Class: Cortex::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Cortex::User
- Includes:
- HasFirstnameLastname, HasGravatar
- Defined in:
- app/models/cortex/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_tenant ⇒ Object
- #anonymous? ⇒ Boolean
- #gravatar ⇒ Object
- #has_permission?(resource, permission) ⇒ Boolean
- #referenced? ⇒ Boolean
- #tenants_with_children ⇒ Object
Class Method Details
.anonymous ⇒ Object
72 73 74 |
# File 'app/models/cortex/user.rb', line 72 def anonymous User.new end |
.authenticate(username, password) ⇒ Object
67 68 69 70 |
# File 'app/models/cortex/user.rb', line 67 def authenticate(username, password) user = User.find_by_email(username) user && user.valid_password?(password) ? user : nil end |
Instance Method Details
#active_tenant ⇒ Object
21 22 23 |
# File 'app/models/cortex/user.rb', line 21 def active_tenant super || tenants.order(:name).first end |
#anonymous? ⇒ Boolean
31 32 33 |
# File 'app/models/cortex/user.rb', line 31 def anonymous? self.id == nil end |
#gravatar ⇒ Object
48 49 50 |
# File 'app/models/cortex/user.rb', line 48 def gravatar "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest email}" end |
#has_permission?(resource, permission) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/cortex/user.rb', line 35 def (resource, ) return true if self.is_superadmin? resource_class = resource.class allowed_perms = (resource_class, ) if resource_class == Cortex::ContentType allowed_perms.select { |perm| perm.resource_id == resource.id }.any? else allowed_perms.any? end end |
#referenced? ⇒ Boolean
25 26 27 28 29 |
# File 'app/models/cortex/user.rb', line 25 def referenced? [ContentItem].find do |resource| true if resource.where(user: self).count > 0 end end |
#tenants_with_children ⇒ Object
52 53 54 |
# File 'app/models/cortex/user.rb', line 52 def tenants_with_children tenants.flat_map(&:self_and_descendants) end |