Class User
In: app/models/user.rb
Parent: ActiveRecord::Base

Methods

Included Modules

Cms::Authentication::Model

Public Class methods

[Source]

    # File app/models/user.rb, line 26
26:   def self.current
27:     Thread.current[:cms_user]
28:   end

[Source]

    # File app/models/user.rb, line 29
29:   def self.current=(user)
30:     Thread.current[:cms_user] = user
31:   end

[Source]

    # File app/models/user.rb, line 33
33:   def self.guest(options = {})
34:     GuestUser.new(options)
35:   end

Public Instance methods

Expects a list of names of Permissions true if the user has any of the permissions

[Source]

     # File app/models/user.rb, line 111
111:   def able_to?(*required_permissions)
112:     perms = required_permissions.map(&:to_sym)
113:     permissions.any? do |p| 
114:       perms.include?(p.name.to_sym) 
115:     end
116:   end

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.

[Source]

     # File app/models/user.rb, line 157
157:   def able_to_edit?(object)    
158:     able_to?(:edit_content) && able_to_modify?(object)
159:   end

[Source]

     # File app/models/user.rb, line 165
165:   def able_to_edit_or_publish_content?
166:     able_to?(:edit_content, :publish_content)
167:   end

[Source]

     # File app/models/user.rb, line 139
139:   def able_to_modify?(object)
140:     case object
141:       when Section
142:         modifiable_sections.include?(object)
143:       when Page, Link
144:         modifiable_sections.include?(object.section)
145:       else
146:         if object.class.respond_to?(:connectable?) && object.class.connectable?
147:           object.connected_pages.all? { |page| able_to_modify?(page) }
148:         else
149:           true
150:         end
151:     end
152:   end

[Source]

     # File app/models/user.rb, line 161
161:   def able_to_publish?(object)
162:     able_to?(:publish_content) && able_to_modify?(object)
163:   end

Determine if this user has permission to view the specific object. Permissions

  are always tied to a specific section. This method can take different input parameters
  and will attempt to determine the relevant section to check.

Expects object to be of type:

  1. Section - Will check the user's groups to see if any of those groups can view this section.
  2. Path - Will look up the section based on the path, then check it.  (Note that section paths are not currently unique, so this will check the first one it finds).
  3. Other - Assumes it has a section attribute and will call that and check the return value.

Returns: true if the user can view this object, false otherwise. Raises: ActiveRecord::RecordNotFound if a path to a not existent section is passed in.

[Source]

     # File app/models/user.rb, line 128
128:   def able_to_view?(object)
129:     section = object
130:     if object.is_a?(String)
131:        section = Section.find_by_path(object)
132:        raise ActiveRecord::RecordNotFound.new("Could not find section with path = '#{object}'") unless section
133:     elsif !object.is_a?(Section)
134:       section = object.section
135:     end
136:     viewable_sections.include?(section) || cms_access?
137:   end

Determines if this user should have access to the CMS administration tools. Can be overridden by specific users (like GuestUser) which may not need to check the database for that information.

[Source]

    # File app/models/user.rb, line 43
43:   def cms_access?
44:     groups.cms_access.count > 0 
45:   end

[Source]

    # File app/models/user.rb, line 47
47:   def disable
48:     if self.class.count(:conditions => ["expires_at is null and id != ?", id]) > 0
49:       self.expires_at = Time.now - 1.minutes
50:     else
51:       false
52:     end
53:   end

[Source]

    # File app/models/user.rb, line 55
55:   def disable!
56:     unless disable
57:       raise "You must have at least 1 enabled user"
58:     end
59:     save!
60:   end

[Source]

    # File app/models/user.rb, line 66
66:   def enable
67:     self.expires_at = nil
68:   end

[Source]

    # File app/models/user.rb, line 70
70:   def enable!
71:     enable
72:     save!
73:   end

[Source]

    # File app/models/user.rb, line 62
62:   def expired?
63:     expires_at && expires_at <= Time.now
64:   end

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.

[Source]

    # File app/models/user.rb, line 93
93:   def expires_at_formatted
94:     expires_at ? (expires_at.strftime '%m/%d/%Y' ): nil
95:   end

[Source]

    # File app/models/user.rb, line 75
75:   def full_name
76:     [first_name, last_name].reject{|e| e.nil?}.join(" ")
77:   end

[Source]

    # File app/models/user.rb, line 83
83:   def full_name_or_login
84:     if full_name.strip.blank?
85:       login
86:     else
87:       full_name
88:     end
89:   end

[Source]

    # File app/models/user.rb, line 79
79:   def full_name_with_login
80:     "#{full_name} (#{login})"
81:   end

[Source]

    # File app/models/user.rb, line 37
37:   def guest?
38:     !!@guest
39:   end

[Source]

     # File app/models/user.rb, line 105
105:   def modifiable_sections
106:     @modifiable_sections ||= Section.find(:all, :include => {:groups => [:group_type, :users]}, :conditions => ["users.id = ? and group_types.cms_access = ?", id, true])
107:   end

[Source]

    # File app/models/user.rb, line 97
97:   def permissions
98:     @permissions ||= Permission.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id])
99:   end

[Source]

     # File app/models/user.rb, line 101
101:   def viewable_sections
102:     @viewable_sections ||= Section.find(:all, :include => {:groups => :users}, :conditions => ["users.id = ?", id])
103:   end

[Validate]