Class: Cms::PersistentUser
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::PersistentUser
show all
- Extended by:
- DefaultAccessible
- Defined in:
- app/models/cms/persistent_user.rb
Overview
A parent class for users that need to be persisted in the CMS database.
Class Method Summary
collapse
Instance Method Summary
collapse
non_permitted_params, permitted_params
Class Method Details
.able_to_edit_or_publish_content ⇒ ActiveRelation<Cms::User>
Returns all users that can :edit_content or :publish_content permissions.
37
38
39
|
# File 'app/models/cms/persistent_user.rb', line 37
def able_to_edit_or_publish_content
where(["#{Permission.table_name}.name = ? OR #{Permission.table_name}.name = ?", "edit_content", "publish_content"]).includes({ :groups => :permissions }).references(:permissions)
end
|
.current=(user) ⇒ Object
45
46
47
|
# File 'app/models/cms/persistent_user.rb', line 45
def current=(user)
Cms::UsersService.current = user
end
|
.guest(options = {}) ⇒ Object
Return a GuestUser with the given values.
50
51
52
|
# File 'app/models/cms/persistent_user.rb', line 50
def guest(options = {})
Cms::GuestUser.new(options)
end
|
.permitted_params ⇒ Object
30
31
32
|
# File 'app/models/cms/persistent_user.rb', line 30
def permitted_params
super + [{ :group_ids => [] }]
end
|
Instance Method Details
#active_for_authentication? ⇒ Boolean
Determines if this user should be authenticated. Hook for Devise.
93
94
95
96
97
|
# File 'app/models/cms/persistent_user.rb', line 93
def active_for_authentication?
is_active = !expired?
logger.error "Expired User '#{login}' failed to login. Account expired on #{expires_at_formatted}." unless is_active
is_active
end
|
55
56
57
58
59
|
# File 'app/models/cms/persistent_user.rb', line 55
def ()
self.external_data = .to_json
= {}.merge().symbolize_keys
Cms..call self,
end
|
#disable ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/models/cms/persistent_user.rb', line 74
def disable
if self.class.where(["expires_at is null and id != ?", id]).count > 0
self.expires_at = Time.now - 2.minutes
else
false
end
end
|
#disable! ⇒ Object
82
83
84
85
86
87
|
# File 'app/models/cms/persistent_user.rb', line 82
def disable!
unless disable
raise "You must have at least 1 enabled user"
end
save!
end
|
#enable ⇒ Object
110
111
112
|
# File 'app/models/cms/persistent_user.rb', line 110
def enable
self.expires_at = nil
end
|
#enable! ⇒ Object
114
115
116
117
|
# File 'app/models/cms/persistent_user.rb', line 114
def enable!
enable
save!
end
|
#expired? ⇒ Boolean
Determines if this user has expired or has been disabled.
106
107
108
|
# File 'app/models/cms/persistent_user.rb', line 106
def expired?
expires_at && expires_at <= Time.now
end
|
This is to show a formatted date on the input form. I’m unsure that this is the best way to solve this, but it works.
125
126
127
|
# File 'app/models/cms/persistent_user.rb', line 125
def expires_at_formatted
expires_at ? (expires_at.strftime '%m/%d/%Y') : nil
end
|
#full_name ⇒ Object
119
120
121
|
# File 'app/models/cms/persistent_user.rb', line 119
def full_name
[first_name, last_name].reject { |e| e.nil? }.join(" ")
end
|
#group_codes ⇒ Object
61
62
63
|
# File 'app/models/cms/persistent_user.rb', line 61
def group_codes
groups.map &:code
end
|
#group_codes=(group_codes) ⇒ Object
65
66
67
|
# File 'app/models/cms/persistent_user.rb', line 65
def group_codes=(group_codes)
self.groups = Cms::Group.with_code(group_codes)
end
|
#guest? ⇒ Boolean
Determines if this user a Guest or not.
70
71
72
|
# File 'app/models/cms/persistent_user.rb', line 70
def guest?
!!@guest
end
|
#password_changeable? ⇒ Boolean
Determines if this User can have their password changed.
100
101
102
|
# File 'app/models/cms/persistent_user.rb', line 100
def password_changeable?
true
end
|