Module: TbCore::UserModel
- Extended by:
- ActiveSupport::Concern
- Included in:
- Spud::SpudUserModel, SpudUser
- Defined in:
- app/models/concerns/tb_core/user_model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#admin_rights? ⇒ Boolean
Returns true if user can view at least one dashboard app.
-
#any_permission?(*tags) ⇒ Boolean
Check if a user has at least one out of a given list of permissions.
-
#can_view_app?(admin_application) ⇒ Boolean
Returns true if the user can view a spud app based on it’s key.
- #full_name ⇒ Object
- #full_name_with_email ⇒ Object
-
#permission?(*tags) ⇒ Boolean
Check if a user has a given list of permissions.
-
#permissions ⇒ Object
Return a list of SpudPermission objects for the user’s SpudRole.
Instance Method Details
#admin_rights? ⇒ Boolean
Returns true if user can view at least one dashboard app
81 82 83 84 85 |
# File 'app/models/concerns/tb_core/user_model.rb', line 81 def admin_rights? return true if super_admin TbCore.admin_applications.find { |app| can_view_app?(app) }.present? end |
#any_permission?(*tags) ⇒ Boolean
Check if a user has at least one out of a given list of permissions
-
if one tag is supplied, return true if the tag matches
-
if multiple tags are supplied, return true if ANY tag matches
110 111 112 113 114 |
# File 'app/models/concerns/tb_core/user_model.rb', line 110 def (*) return true if super_admin? .find { |p| .include?(p.tag) }.present? end |
#can_view_app?(admin_application) ⇒ Boolean
Returns true if the user can view a spud app based on it’s key
88 89 90 91 92 93 |
# File 'app/models/concerns/tb_core/user_model.rb', line 88 def can_view_app?(admin_application) return true if super_admin? key = admin_application[:key] .find { |p| p.apps.include?(key) }.present? end |
#full_name ⇒ Object
70 71 72 73 74 |
# File 'app/models/concerns/tb_core/user_model.rb', line 70 def full_name return login if first_name.blank? && last_name.blank? [first_name, last_name].reject(&:blank?).join(' ') end |
#full_name_with_email ⇒ Object
76 77 78 |
# File 'app/models/concerns/tb_core/user_model.rb', line 76 def full_name_with_email "#{full_name} (#{email})" end |
#permission?(*tags) ⇒ Boolean
Check if a user has a given list of permissions
-
if one tag is supplied, return true if the tag matches
-
if multiple tags are supplied, return true if ALL tags match
99 100 101 102 103 104 |
# File 'app/models/concerns/tb_core/user_model.rb', line 99 def (*) return true if super_admin? = .collect(&:tag) .find { |tag| !.include?(tag) }.blank? end |
#permissions ⇒ Object
Return a list of SpudPermission objects for the user’s SpudRole
117 118 119 120 121 |
# File 'app/models/concerns/tb_core/user_model.rb', line 117 def return [] if role.blank? role. end |