Module: AbAdmin::Models::User

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
lib/ab_admin/models/user.rb

Instance Method Summary collapse

Instance Method Details

#activate!Object


34
35
36
37
# File 'lib/ab_admin/models/user.rb', line 34

def activate!
  confirm unless confirmed?
  unlock_access! if access_locked?
end

#active?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/ab_admin/models/user.rb', line 39

def active?
  active_for_authentication?
end

#admin?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/ab_admin/models/user.rb', line 66

def admin?
  has_role?(:admin)
end

#admin_access?Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/ab_admin/models/user.rb', line 50

def admin_access?
  moderator?
end

#default?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/ab_admin/models/user.rb', line 54

def default?
  has_role?(:default)
end

#full_nameObject


26
27
28
# File 'lib/ab_admin/models/user.rb', line 26

def full_name
  [first_name.presence, last_name.presence].compact.join(' ')
end

#generate_password!Object


43
44
45
46
47
48
# File 'lib/ab_admin/models/user.rb', line 43

def generate_password!
  raw_password = AbAdmin.test_env? ? '654321' : AbAdmin.friendly_token
  self.password = self.password_confirmation = raw_password
  self.save(validate: false)
  raw_password
end

#has_role?(role_name) ⇒ Boolean

Returns:

  • (Boolean)

70
71
72
# File 'lib/ab_admin/models/user.rb', line 70

def has_role?(role_name)
  user_role_type.code == role_name
end

#moderator?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'lib/ab_admin/models/user.rb', line 62

def moderator?
  has_role?(:admin) || has_role?(:moderator)
end

#nameObject


22
23
24
# File 'lib/ab_admin/models/user.rb', line 22

def name
  full_name.strip.presence || email
end

#redactor?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/ab_admin/models/user.rb', line 58

def redactor?
  has_role?(:redactor)
end

#set_default_roleObject


74
75
76
# File 'lib/ab_admin/models/user.rb', line 74

def set_default_role
  self.user_role_id ||= ::UserRoleType.default.id
end

#suspend!Object


30
31
32
# File 'lib/ab_admin/models/user.rb', line 30

def suspend!
  update_attribute(:locked_at, Time.now.utc)
end