Class: Cms::TemporaryUser

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

Overview

This represents a ‘temporary’ user who is never stored in the database, but lives only as a limited duration (generally tied to a session) This can be used to represent an externally verified user who should be granted access to areas of the site.

Typical Usage:

user = Cms::TemporaryUser.new(:login=>“[email protected]”) user << Group.find_by_code(“Special Group”) user.able_to_view?(“/some/path”)

Direct Known Subclasses

CasUser

Instance Method Summary collapse

Instance Method Details

#cms_access?Boolean

Determines if this user has access to the CMS UI.

Note: This overrides User.cms_access? which is implicitly dependant on groups being a proxy/has_many Array, rather than just an array of groups.

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'app/models/cms/temporary_user.rb', line 28

def cms_access?
  groups.each do |g|
    return true if g.cms_access?
  end
  false
end

#save(perform_validations = true) ⇒ Object

Shouldn’t save these users to the db.



15
16
17
# File 'app/models/cms/temporary_user.rb', line 15

def save(perform_validations=true)
  false
end

#save!(perform_validation = true) ⇒ Object

Shouldn’t save these users to the db.

Raises:

  • (NotImplementedError)


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

def save!(perform_validation=true)
  raise NotImplementedError
end

#viewable_sectionsObject

Returns all sections that this user has rights to view.

Overrides core behavior of User to avoid including user as part of the query (since temp users doen’t exist in the database).



39
40
41
# File 'app/models/cms/temporary_user.rb', line 39

def viewable_sections
  Section.find(:all, :joins=>:groups, :conditions=>["groups.id IN (?)", groups])
end