Module: Pageflow::UserMixin

Extended by:
ActiveSupport::Concern
Includes:
Suspendable
Defined in:
lib/pageflow/user_mixin.rb

Overview

ActiveRecord related functionality of the Pageflow users.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

NON_ADMIN_ROLES =
['editor', 'account_manager']
ROLES =
NON_ADMIN_ROLES + ['admin']

Instance Method Summary collapse

Methods included from Suspendable

#active_for_authentication?, #suspend!, #suspended?, #unsuspend!

Instance Method Details

#account_manager?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pageflow/user_mixin.rb', line 32

def 
  role == 'account_manager'
end

#admin?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/pageflow/user_mixin.rb', line 28

def admin?
  role == 'admin'
end

#destroy_with_password(password) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/pageflow/user_mixin.rb', line 50

def destroy_with_password(password)
  if valid_password?(password)
    destroy
    true
  else
    self.errors.add(:current_password, password.blank? ? :blank : :invalid)
    false
  end
end

#full_nameObject



36
37
38
# File 'lib/pageflow/user_mixin.rb', line 36

def full_name
  [first_name, last_name] * " "
end

#update_with_password(attributes) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/pageflow/user_mixin.rb', line 40

def update_with_password(attributes)
  if needs_password?(attributes)
    super(attributes)
  else
    # remove the virtual current_password attribute update_without_password
    # doesn't know how to ignore it
    update_without_password(attributes.except(:current_password))
  end
end