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
124 125 126 127 128 |
# File 'app/models/concerns/tb_core/user_model.rb', line 124 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
153 154 155 156 157 |
# File 'app/models/concerns/tb_core/user_model.rb', line 153 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
131 132 133 134 135 136 |
# File 'app/models/concerns/tb_core/user_model.rb', line 131 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
113 114 115 116 117 |
# File 'app/models/concerns/tb_core/user_model.rb', line 113 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
119 120 121 |
# File 'app/models/concerns/tb_core/user_model.rb', line 119 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
142 143 144 145 146 147 |
# File 'app/models/concerns/tb_core/user_model.rb', line 142 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
160 161 162 163 164 |
# File 'app/models/concerns/tb_core/user_model.rb', line 160 def return [] if role.blank? role. end |