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.
-
#cms_user_compatible? ⇒ Boolean
checks for usage.
- #disable_able? ⇒ Boolean
- #enable_able? ⇒ Boolean
-
#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
100 101 102 103 104 105 |
# File 'lib/cms/acts/cms_user.rb', line 100 def able_to?(*) perms = .map(&:to_sym) .any? do |p| perms.include?(p.name.to_sym) end end |
#able_to_edit?(section) ⇒ Boolean
123 124 125 |
# File 'lib/cms/acts/cms_user.rb', line 123 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.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cms/acts/cms_user.rb', line 84 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.
109 110 111 |
# File 'lib/cms/acts/cms_user.rb', line 109 def cms_access? false end |
#cms_user_compatible? ⇒ Boolean
checks for usage
62 63 64 |
# File 'lib/cms/acts/cms_user.rb', line 62 def cms_user_compatible? true end |
#disable_able? ⇒ Boolean
70 71 72 |
# File 'lib/cms/acts/cms_user.rb', line 70 def disable_able? false end |
#enable_able? ⇒ Boolean
66 67 68 |
# File 'lib/cms/acts/cms_user.rb', line 66 def enable_able? 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
119 120 121 |
# File 'lib/cms/acts/cms_user.rb', line 119 def @permissions ||= Cms::Permission.includes(:groups).where(["#{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.
115 116 117 |
# File 'lib/cms/acts/cms_user.rb', line 115 def viewable_sections @viewable_sections ||= Cms::Section.includes(:groups).where(["#{Cms::Group.table_name}.id in (?)", cms_groups.collect(&:id)]) end |