Module: Cms::Acts::CmsUser::MacroMethods::InstanceMethods
- Defined in:
- lib/cms/acts/cms_user.rb
Instance Method Summary collapse
-
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of names of Permissions true if the user has any of the permissions.
- #able_to_edit?(section) ⇒ Boolean
-
#able_to_view?(object) ⇒ Boolean
Determine if this user has permission to view the specific object.
-
#cms_access? ⇒ Boolean
Guests never get access to the CMS.
-
#guest? ⇒ Boolean
The following came from Cms::User.
- #permissions ⇒ Object
-
#viewable_sections ⇒ Object
Return a list of the sections associated with this user that can be viewed.
Instance Method Details
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of names of Permissions true if the user has any of the permissions
87 88 89 90 91 92 |
# File 'lib/cms/acts/cms_user.rb', line 87 def able_to?(*) perms = .map(&:to_sym) .any? do |p| perms.include?(p.name.to_sym) end end |
#able_to_edit?(section) ⇒ Boolean
110 111 112 |
# File 'lib/cms/acts/cms_user.rb', line 110 def able_to_edit?(section) false end |
#able_to_view?(object) ⇒ Boolean
Determine if this user has permission to view the specific object. Permissions
are always tied to a specific section. This method can take different input parameters
and will attempt to determine the relevant section to check.
Expects object to be of type:
1. Section - Will check the user's groups to see if any of those groups can view this section.
2. Path - Will look up the section based on the path, then check it. (Note that section paths are not currently unique, so this will check the first one it finds).
3. Other - Assumes it has a section attribute and will call that and check the return value.
Returns: true if the user can view this object, false otherwise. Raises: ActiveRecord::RecordNotFound if a path to a not existent section is passed in.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cms/acts/cms_user.rb', line 71 def able_to_view?(object) section = object if object.is_a?(String) section = Cms::Section.find_by_path(object) raise ActiveRecord::RecordNotFound.new("Could not find section with path = '#{object}'") unless section elsif !object.is_a?(Cms::Section) section = object.section end viewable_sections.include?(section) || cms_access? end |
#cms_access? ⇒ Boolean
Guests never get access to the CMS.
96 97 98 |
# File 'lib/cms/acts/cms_user.rb', line 96 def cms_access? false end |
#guest? ⇒ Boolean
The following came from Cms::User
57 58 59 |
# File 'lib/cms/acts/cms_user.rb', line 57 def guest? false end |
#permissions ⇒ Object
106 107 108 |
# File 'lib/cms/acts/cms_user.rb', line 106 def @permissions ||= Cms::Permission.find(:all, :include => :groups, :conditions => ["#{Cms::Group.table_name}.id in (?)", cms_groups.collect(&:id)]) end |
#viewable_sections ⇒ Object
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.
102 103 104 |
# File 'lib/cms/acts/cms_user.rb', line 102 def viewable_sections @viewable_sections ||= Cms::Section.find(:all, :include => :groups, :conditions => ["#{Cms::Group.table_name}.id in (?)", cms_groups.collect(&:id)]) end |