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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


153
154
155
156
157
# File 'app/models/concerns/tb_core/user_model.rb', line 153

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

Returns:

  • (Boolean)


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

#full_nameObject



113
114
115
116
117
# File 'app/models/concerns/tb_core/user_model.rb', line 113

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

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

#full_name_with_emailObject



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

Returns:

  • (Boolean)


142
143
144
145
146
147
# File 'app/models/concerns/tb_core/user_model.rb', line 142

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



160
161
162
163
164
# File 'app/models/concerns/tb_core/user_model.rb', line 160

def permissions
  return [] if role.blank?

  role.permissions
end