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

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 any_permission?(*tags)
  return true if super_admin?

  permissions.find { |p| tags.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]
  permissions.find { |p| p.apps.include?(key) }.present?
end

#full_nameObject



70
71
72
73
74
# File 'app/models/concerns/tb_core/user_model.rb', line 70

def full_name
  return  if first_name.blank? && last_name.blank?

  [first_name, last_name].reject(&:blank?).join(' ')
end

#full_name_with_emailObject



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 permission?(*tags)
  return true if super_admin?

  my_tags = permissions.collect(&:tag)
  tags.find { |tag| !my_tags.include?(tag) }.blank?
end

#permissionsObject

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 permissions
  return [] if role.blank?

  role.permissions
end