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



58
59
60
61
62
63
64
65
66
# File 'lib/pageflow/user_mixin.rb', line 58

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

#formal_nameObject



40
41
42
# File 'lib/pageflow/user_mixin.rb', line 40

def formal_name
  [last_name, first_name] * ", "
end

#full_nameObject



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

def full_name
  [first_name, last_name] * " "
end

#localeObject



44
45
46
# File 'lib/pageflow/user_mixin.rb', line 44

def locale
  super.presence || I18n.default_locale
end

#update_with_password(attributes) ⇒ Object



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

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