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?, current, current=, #disable, #disable!, #enable, #enable!, #expired?, #expires_at_formatted, #full_name, #full_name_with_login, guest, #guest?, #modifiable_sections, #permissions, #viewable_sections

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)


22
23
24
# File 'app/models/guest_user.rb', line 22

def able_to_edit?(section)
  false
end

#able_to_view?(page) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/guest_user.rb', line 18

def able_to_view?(page)
  group && !!(group.sections.include?(page.section))
end

#groupObject



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

def group
  @group ||= Group.guest
end

#groupsObject



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

def groups
  [group]
end

#save(perform_validation = true) ⇒ Object



41
42
43
# File 'app/models/guest_user.rb', line 41

def save(perform_validation=true)
  false
end

#update_attribute(name, value) ⇒ Object

You shouldn’t be able to save a guest user



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

def update_attribute(name, value)
  false
end

#update_attributes(attrs = {}) ⇒ Object



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

def update_attributes(attrs={})
  false
end