Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Includes:
- Cms::Authentication::Model
- Defined in:
- app/models/user.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of names of Permissions true if the user has any of the permissions.
-
#able_to_edit?(object) ⇒ Boolean
Expects node to be a Section, Page or Link Returns true if the specified node, or any of its ancestor sections, is editable by any of the user’s ‘CMS User’ groups.
- #able_to_edit_or_publish_content? ⇒ Boolean
- #able_to_modify?(object) ⇒ Boolean
- #able_to_publish?(object) ⇒ Boolean
-
#able_to_view?(object) ⇒ Boolean
Expects object to be an object or a section If it’s a section, that will be used If it’s not a section, it will call section on the object returns true if any of the sections of the groups the user is in matches the page’s section.
- #disable ⇒ Object
- #disable! ⇒ Object
- #enable ⇒ Object
- #enable! ⇒ Object
- #expired? ⇒ Boolean
-
#expires_at_formatted ⇒ Object
This is to show a formated date on the input form.
- #full_name ⇒ Object
- #full_name_with_login ⇒ Object
- #guest? ⇒ Boolean
- #modifiable_sections ⇒ Object
- #permissions ⇒ Object
- #viewable_sections ⇒ Object
Methods included from Cms::Authentication::Model
Class Method Details
.current ⇒ Object
27 28 29 |
# File 'app/models/user.rb', line 27 def self.current Thread.current[:cms_user] end |
.current=(user) ⇒ Object
30 31 32 |
# File 'app/models/user.rb', line 30 def self.current=(user) Thread.current[:cms_user] = user end |
Instance Method Details
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of names of Permissions true if the user has any of the permissions
98 99 100 101 102 103 |
# File 'app/models/user.rb', line 98 def able_to?(*) perms = .map(&:to_sym) .any? do |p| perms.include?(p.name.to_sym) end end |
#able_to_edit?(object) ⇒ Boolean
Expects node to be a Section, Page or Link Returns true if the specified node, or any of its ancestor sections, is editable by any of the user’s ‘CMS User’ groups.
132 133 134 |
# File 'app/models/user.rb', line 132 def able_to_edit?(object) able_to?(:edit_content) && able_to_modify?(object) end |
#able_to_edit_or_publish_content? ⇒ Boolean
140 141 142 |
# File 'app/models/user.rb', line 140 def able_to_edit_or_publish_content? able_to?(:edit_content, :publish_content) end |
#able_to_modify?(object) ⇒ Boolean
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/models/user.rb', line 114 def able_to_modify?(object) case object when Section object.with_ancestors.any? { |section| modifiable_sections.include?(section) } when Page, Link object.section.with_ancestors.any? { |section| modifiable_sections.include?(section) } else if object.class.respond_to?(:connectable?) && object.class.connectable? object.connected_pages.all? { |page| able_to_modify?(page) } else true end end end |
#able_to_publish?(object) ⇒ Boolean
136 137 138 |
# File 'app/models/user.rb', line 136 def able_to_publish?(object) able_to?(:publish_content) && able_to_modify?(object) end |
#able_to_view?(object) ⇒ Boolean
Expects object to be an object or a section If it’s a section, that will be used If it’s not a section, it will call section on the object returns true if any of the sections of the groups the user is in matches the page’s section.
109 110 111 112 |
# File 'app/models/user.rb', line 109 def able_to_view?(object) section = object.is_a?(Section) ? object : object.section viewable_sections.include?(section) || groups.cms_access.count > 0 end |
#disable ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/models/user.rb', line 42 def disable if self.class.count(:conditions => ["expires_at is null and id != ?", id]) > 0 self.expires_at = Time.now - 1.minutes else false end end |
#disable! ⇒ Object
50 51 52 53 54 55 |
# File 'app/models/user.rb', line 50 def disable! unless disable raise "You must have at least 1 enabled user" end save! end |
#enable ⇒ Object
61 62 63 |
# File 'app/models/user.rb', line 61 def enable self.expires_at = nil end |
#enable! ⇒ Object
65 66 67 68 |
# File 'app/models/user.rb', line 65 def enable! enable save! end |
#expired? ⇒ Boolean
57 58 59 |
# File 'app/models/user.rb', line 57 def expired? expires_at && expires_at <= Time.now end |
#expires_at_formatted ⇒ Object
This is to show a formated date on the input form. I’m unsure that this is the best way to solve this, but it works.
80 81 82 |
# File 'app/models/user.rb', line 80 def expires_at_formatted expires_at ? (expires_at.strftime '%m/%d/%Y' ): nil end |
#full_name ⇒ Object
70 71 72 |
# File 'app/models/user.rb', line 70 def full_name [first_name, last_name].reject{|e| e.nil?}.join(" ") end |
#full_name_with_login ⇒ Object
74 75 76 |
# File 'app/models/user.rb', line 74 def full_name_with_login "#{full_name} (#{login})" end |
#guest? ⇒ Boolean
38 39 40 |
# File 'app/models/user.rb', line 38 def guest? !!@guest end |
#modifiable_sections ⇒ Object
92 93 94 |
# File 'app/models/user.rb', line 92 def modifiable_sections @modifiable_sections ||= Section.find(:all, :include => {:groups => [:group_type, :users]}, :conditions => ["users.id = ? and group_types.cms_access = ?", id, true]) end |
#permissions ⇒ Object
84 85 86 |
# File 'app/models/user.rb', line 84 def @permissions ||= Permission.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id]) end |
#viewable_sections ⇒ Object
88 89 90 |
# File 'app/models/user.rb', line 88 def viewable_sections @viewable_sections ||= Section.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id]) end |