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 27
27:   def self.current
28:     Thread.current[:cms_user]
29:   end

[Source]

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

[Source]

    # File app/models/user.rb, line 34
34:   def self.guest(options = {})
35:     GuestUser.new(options)
36:   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 98
 98:   def able_to?(*required_permissions)
 99:     perms = required_permissions.map(&:to_sym)
100:     permissions.any? do |p| 
101:       perms.include?(p.name.to_sym) 
102:     end
103:   end

Expects section to be a Section Returns true if any of the sections of the groups that have group_type = ‘CMS User’ that the user is in match the section.

[Source]

     # File app/models/user.rb, line 117
117:   def able_to_edit?(section)    
118:     !!(editable_sections.include?(section) && able_to?(:edit_content))
119:   end

[Source]

     # File app/models/user.rb, line 121
121:   def able_to_edit_or_publish_content?
122:     able_to?(:edit_content, :publish_content)
123:   end

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.

[Source]

     # File app/models/user.rb, line 109
109:   def able_to_view?(object)
110:     section = object.is_a?(Section) ? object : object.section
111:     !!(viewable_sections.include?(section) || groups.cms_access.count > 0)
112:   end

[Source]

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

[Source]

    # File app/models/user.rb, line 50
50:   def disable!
51:     unless disable
52:       raise "You must have at least 1 enabled user"
53:     end
54:     save!
55:   end

[Source]

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

[Source]

    # File app/models/user.rb, line 61
61:   def enable
62:     self.expires_at = nil
63:   end

[Source]

    # File app/models/user.rb, line 65
65:   def enable!
66:     enable
67:     save!
68:   end

[Source]

    # File app/models/user.rb, line 57
57:   def expired?
58:     expires_at && expires_at <= Time.now
59:   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 80
80:   def expires_at_formatted
81:     expires_at ? (expires_at.strftime '%m/%d/%Y' ): nil
82:   end

[Source]

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

[Source]

    # File app/models/user.rb, line 74
74:   def full_name_with_login
75:     "#{full_name} (#{login})"
76:   end

[Source]

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

[Source]

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

[Source]

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

[Validate]