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
26 27 28 |
# File 'app/models/user.rb', line 26 def self.current Thread.current[:cms_user] end |
.current=(user) ⇒ Object
29 30 31 |
# File 'app/models/user.rb', line 29 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
97 98 99 100 101 102 |
# File 'app/models/user.rb', line 97 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.
131 132 133 |
# File 'app/models/user.rb', line 131 def able_to_edit?(object) able_to?(:edit_content) && able_to_modify?(object) end |
#able_to_edit_or_publish_content? ⇒ Boolean
139 140 141 |
# File 'app/models/user.rb', line 139 def able_to_edit_or_publish_content? able_to?(:edit_content, :publish_content) end |
#able_to_modify?(object) ⇒ Boolean
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/user.rb', line 113 def able_to_modify?(object) case object when Section modifiable_sections.include?(object) when Page, Link modifiable_sections.include?(object.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
135 136 137 |
# File 'app/models/user.rb', line 135 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.
108 109 110 111 |
# File 'app/models/user.rb', line 108 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
41 42 43 44 45 46 47 |
# File 'app/models/user.rb', line 41 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
49 50 51 52 53 54 |
# File 'app/models/user.rb', line 49 def disable! unless disable raise "You must have at least 1 enabled user" end save! end |
#enable ⇒ Object
60 61 62 |
# File 'app/models/user.rb', line 60 def enable self.expires_at = nil end |
#enable! ⇒ Object
64 65 66 67 |
# File 'app/models/user.rb', line 64 def enable! enable save! end |
#expired? ⇒ Boolean
56 57 58 |
# File 'app/models/user.rb', line 56 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.
79 80 81 |
# File 'app/models/user.rb', line 79 def expires_at_formatted expires_at ? (expires_at.strftime '%m/%d/%Y' ): nil end |
#full_name ⇒ Object
69 70 71 |
# File 'app/models/user.rb', line 69 def full_name [first_name, last_name].reject{|e| e.nil?}.join(" ") end |
#full_name_with_login ⇒ Object
73 74 75 |
# File 'app/models/user.rb', line 73 def full_name_with_login "#{full_name} (#{login})" end |
#guest? ⇒ Boolean
37 38 39 |
# File 'app/models/user.rb', line 37 def guest? !!@guest end |
#modifiable_sections ⇒ Object
91 92 93 |
# File 'app/models/user.rb', line 91 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
83 84 85 |
# File 'app/models/user.rb', line 83 def @permissions ||= Permission.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id]) end |
#viewable_sections ⇒ Object
87 88 89 |
# File 'app/models/user.rb', line 87 def viewable_sections @viewable_sections ||= Section.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id]) end |