Class: GuestUser

Inherits:
User
  • Object
show all
Defined in:
app/models/guest_user.rb

Overview

Guests are a special user that represents a non-logged in user. The main reason to create an explicit instance of this type of user is so that the permissions a Guest user can have can be set via the Admin interface.

Every request that a non-logged in user makes will use this User’s permissions to determine what they can/can’t do.

Instance Method Summary collapse

Methods inherited from User

#able_to_edit_or_publish_content?, #able_to_modify?, #able_to_publish?, #able_to_view?, current, current=, #disable, #disable!, #enable, #enable!, #expired?, #expires_at_formatted, #full_name, #full_name_or_login, #full_name_with_login, guest, #guest?, #modifiable_sections, #permissions

Methods included from Cms::Authentication::Model

included

Constructor Details

#initialize(attributes = {}) ⇒ GuestUser

Returns a new instance of GuestUser.



9
10
11
12
# File 'app/models/guest_user.rb', line 9

def initialize(attributes={})
  super({:login => Group::GUEST_CODE, :first_name => "Anonymous", :last_name => "User"}.merge(attributes))
  @guest = true
end

Instance Method Details

#able_to?(*name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/guest_user.rb', line 14

def able_to?(*name)
  group && group.permissions.count(:conditions => ["name in (?)", name.map(&:to_s)]) > 0
end

#able_to_edit?(section) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/guest_user.rb', line 30

def able_to_edit?(section)
  false
end

#cms_access?Boolean

Guests never get access to the CMS. Overridden from user so that able_to_view? will work correctly.

Returns:

  • (Boolean)


20
21
22
# File 'app/models/guest_user.rb', line 20

def cms_access?
  false
end

#groupObject



34
35
36
# File 'app/models/guest_user.rb', line 34

def group
  @group ||= Group.guest
end

#groupsObject



38
39
40
# File 'app/models/guest_user.rb', line 38

def groups
  [group]
end

#save(perform_validation = true) ⇒ Object



49
50
51
# File 'app/models/guest_user.rb', line 49

def save(perform_validation=true)
  false
end

#update_attribute(name, value) ⇒ Object

You shouldn’t be able to save a guest user



43
44
45
# File 'app/models/guest_user.rb', line 43

def update_attribute(name, value)
  false
end

#update_attributes(attrs = {}) ⇒ Object



46
47
48
# File 'app/models/guest_user.rb', line 46

def update_attributes(attrs={})
  false
end

#viewable_sectionsObject

Return a list of the sections associated with this user that can be viewed. Overridden from user so that able_to_view? will work correctly.



26
27
28
# File 'app/models/guest_user.rb', line 26

def viewable_sections
  group.sections
end