Sha256: 13e67c46d1a1bfe40e7e3e166c5965052e75ffdee86bc88e128b41dc58179a58

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

#
# 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.
#
module Cms
  class GuestUser < Cms::User

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

    def able_to?(*name)
      group && group.permissions.where('name in (?)', name.map(&:to_s)).count > 0
    end

    # Guests never get access to the CMS.
    # Overridden from user so that able_to_view? will work correctly.
    def cms_access?
      false
    end

    # 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.
    def viewable_sections
      group.sections
    end

    def able_to_edit?(section)
      false
    end

    def group
      @group ||= Cms::Group.guest
    end

    def groups
      [group]
    end

    #You shouldn't be able to save a guest user
    def update_attribute(name, value)
      false
    end

    def update_attributes(attrs={})
      false
    end

    def save(perform_validation=true)
      false
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
browsercms-artirix-4.0.0.rc1.art4 app/models/cms/guest_user.rb