Class: Spud::SpudUserModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spud::SpudUserModel
- Defined in:
- app/models/spud/spud_user_model.rb
Direct Known Subclasses
Class Method Summary collapse
-
.where_name_like(string) ⇒ Object
Returns an ActiveRecord::Relation performing a LIKE query against name columns.
-
.with_permission(tag, include_supers: true) ⇒ Object
Return an array of users who have the requested permission.
Instance Method Summary collapse
-
#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
-
#has_admin_rights? ⇒ Boolean
Returns true if user can view at least one dashboard app.
-
#has_any_permission?(*tags) ⇒ Boolean
Check if a user has at least one out of a given list of permissions.
-
#has_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.
Class Method Details
.where_name_like(string) ⇒ Object
Returns an ActiveRecord::Relation performing a LIKE query against name columns
97 98 99 100 |
# File 'app/models/spud/spud_user_model.rb', line 97 def self.where_name_like(string) like = '%' + string + '%' return self.where('login like ? or concat(`first_name`, " ", `last_name`) like ?', like, like) end |
.with_permission(tag, include_supers: true) ⇒ Object
Return an array of users who have the requested permission
-
tag - Desired permission tag string (required)
-
include_supers - Whether to include super user (default: true)
106 107 108 109 110 111 112 113 |
# File 'app/models/spud/spud_user_model.rb', line 106 def self.(tag, include_supers:true) role_ids = SpudRolePermission.where(:spud_permission_tag => tag).pluck(:spud_role_id).uniq() if include_supers return SpudUser.where('super_admin = 1 OR spud_role_id IN (?)', role_ids) else return SpudUser.where(:spud_role_id => role_ids) end end |
Instance Method Details
#can_view_app?(admin_application) ⇒ Boolean
Returns true if the user can view a spud app based on it’s key
53 54 55 56 57 58 59 60 |
# File 'app/models/spud/spud_user_model.rb', line 53 def can_view_app?(admin_application) if self.super_admin? return true else key = admin_application[:key] return self..find{ |p| p.apps.include?(key) }.present? end end |
#full_name ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/spud/spud_user_model.rb', line 27 def full_name if first_name.blank? && last_name.blank? return self.login end if self.first_name.blank? return self.last_name elsif self.last_name.blank? return self.first_name end return "#{self.first_name} #{self.last_name}" end |
#full_name_with_email ⇒ Object
39 40 41 |
# File 'app/models/spud/spud_user_model.rb', line 39 def full_name_with_email return "#{full_name} (#{email})" end |
#has_admin_rights? ⇒ Boolean
Returns true if user can view at least one dashboard app
44 45 46 47 48 49 50 |
# File 'app/models/spud/spud_user_model.rb', line 44 def has_admin_rights? if self.super_admin? return true else return Spud::Core.admin_applications.find{ |app| self.can_view_app?(app) }.present? end end |
#has_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
79 80 81 82 83 84 85 |
# File 'app/models/spud/spud_user_model.rb', line 79 def (*) if self.super_admin? return true else return self..find{ |p| .include?(p.tag) }.present? end end |
#has_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
66 67 68 69 70 71 72 73 |
# File 'app/models/spud/spud_user_model.rb', line 66 def (*) if self.super_admin? return true else = self..collect(&:tag) return .find{ |tag| !.include?(tag) }.blank? end end |
#permissions ⇒ Object
Return a list of SpudPermission objects for the user’s SpudRole
88 89 90 91 92 93 94 |
# File 'app/models/spud/spud_user_model.rb', line 88 def if !self.role return [] else return self.role. end end |