Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_super_admin_and_adminsObject


55
56
57
# File 'app/models/user.rb', line 55

def self.all_super_admin_and_admins
  self.where(:role => ["super_admin" , "admin"]).all
end

.user_rolesObject


36
37
38
# File 'app/models/user.rb', line 36

def self.user_roles
  @roles ||= (["super_admin" , "admin" , "contributor"] << (Rails.configuration.user_roles) ).flatten
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'app/models/user.rb', line 32

def admin?
  self.role == "admin"
end

#deliver_password_reset_instructions!Object


23
24
25
26
# File 'app/models/user.rb', line 23

def deliver_password_reset_instructions!
  reset_perishable_token!
  Notifier.password_reset_instructions(self.id).deliver
end

#full_nameObject


17
18
19
20
21
# File 'app/models/user.rb', line 17

def full_name
  self.first_name = "" if self.first_name.blank?
  self.last_name = "" if self.last_name.blank?
  self.first_name + " " + self.last_name
end

#have_backend_access?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'app/models/user.rb', line 51

def have_backend_access?
  ["super_admin" , "admin" , "contributor"].include?(self.role)
end

#super_admin?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'app/models/user.rb', line 28

def super_admin?
  self.role == "super_admin"
end

#user_valid_roles(user) ⇒ Object


40
41
42
43
44
45
46
47
48
49
# File 'app/models/user.rb', line 40

def user_valid_roles(user)
  if user.id == self.id
    []
  else
    roles = (["super_admin" , "admin" , "contributor"] << (Rails.configuration.user_roles) ).flatten
    roles.delete("super_admin") unless self.super_admin?
    roles.delete("contributor") if !self.super_admin? && !self.admin?
    roles
  end
end