Module: Mumuki::Domain::Helpers::User

Extended by:
ActiveSupport::Concern
Includes:
Mumukit::Auth::Roles, Mumukit::Platform::Notifiable
Included in:
User
Defined in:
lib/mumuki/domain/helpers/user.rb

Instance Method Summary collapse

Instance Method Details

#any_granted_organizationsObject

Accessible organizations



74
75
76
# File 'lib/mumuki/domain/helpers/user.rb', line 74

revamp_accessor :any_granted_organizations, :student_granted_organizations do |_, _, result|
  result.map { |org| Mumukit::Platform::Organization.find_by_name!(org) rescue nil }.compact
end

#discusser_of?(organization) ⇒ Boolean

Tells whether this user has forum discusser permissions in the given organization

Returns:

  • (Boolean)


49
50
51
# File 'lib/mumuki/domain/helpers/user.rb', line 49

def discusser_of?(organization)
  has_permission? organization.forum_discussions_minimal_role, organization.slug
end

#has_immersive_main_organization?Boolean

Deprecated: use ‘immersive_organization_at` which properly looks for a single immersive organization taking current organization and path into account

Returns:

  • (Boolean)


89
90
91
# File 'lib/mumuki/domain/helpers/user.rb', line 89

def has_immersive_main_organization?
  main_organization.try(&:immersive?).present?
end

#has_role?Object

Permissions



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mumuki/domain/helpers/user.rb', line 8

delegate :has_role?,
:add_permission!,
:remove_permission!,
:update_permission!,
:has_permission?,
:has_permission_delegation?,
:protect!,
:protect_delegation!,
:protect_permissions_assignment!,
:student_granted_organizations,
:any_granted_organizations,
:any_granted_roles,
to: :permissions

#has_student_granted_organizations?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/mumuki/domain/helpers/user.rb', line 78

def has_student_granted_organizations?
  student_granted_organizations.present?
end

#immersive_organization_at(path_item, current = Organization.current) ⇒ Object



93
94
95
# File 'lib/mumuki/domain/helpers/user.rb', line 93

def immersive_organization_at(path_item, current = Organization.current)
  immersive_organizations_at(path_item, current).single
end

#immersive_organization_with_content_at(path_item, current = Organization.current) ⇒ Object



102
103
104
105
# File 'lib/mumuki/domain/helpers/user.rb', line 102

def immersive_organization_with_content_at(path_item, current = Organization.current)
  orga = immersive_organizations_with_content_at(path_item, current).single
  [orga, path_item&.navigable_content_in(orga)]
end

#immersive_organizations_at(path_item, current = Organization.current) ⇒ Object



97
98
99
100
# File 'lib/mumuki/domain/helpers/user.rb', line 97

def immersive_organizations_at(path_item, current = Organization.current)
  usage_filter = path_item ? lambda { |it| path_item.used_in?(it) } : lambda { |_| true }
  immersive_organizations_for(current).select(&usage_filter)
end

#immersive_organizations_with_content_at(path_item, current = Organization.current) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/mumuki/domain/helpers/user.rb', line 107

def immersive_organizations_with_content_at(path_item, current = Organization.current)
  immersive_without_usage = immersive_organizations_for(current)
  return immersive_without_usage unless path_item.present?

  immersive_with_usage = immersive_without_usage.select { |it| path_item.content_used_in? it }
  immersive_with_usage.empty? ? immersive_without_usage : immersive_with_usage
end

#main_organizationObject



82
83
84
# File 'lib/mumuki/domain/helpers/user.rb', line 82

def main_organization
  student_granted_organizations.first || any_granted_organizations.first
end

#merge_permissions!(new_permissions) ⇒ Object



26
27
28
# File 'lib/mumuki/domain/helpers/user.rb', line 26

def merge_permissions!(new_permissions)
  self.permissions = permissions.merge(new_permissions)
end

#platform_class_nameObject



22
23
24
# File 'lib/mumuki/domain/helpers/user.rb', line 22

def platform_class_name
  :User
end

#profile_completed?Boolean

Profile

Returns:

  • (Boolean)


64
65
66
# File 'lib/mumuki/domain/helpers/user.rb', line 64

def profile_completed?
  self.class.profile_fields.map { |it| self[it] }.all? &:present?
end

#to_paramObject

API Exposure



117
118
119
# File 'lib/mumuki/domain/helpers/user.rb', line 117

def to_param
  uid
end

#to_sObject



68
69
70
# File 'lib/mumuki/domain/helpers/user.rb', line 68

def to_s
  "#{full_name} <#{email}> [#{uid}]"
end