Module: Cms::UsersService::CmsUserCompatibilityModule
- Defined in:
- lib/cms/users_service/cms_user_compatibility_module.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
add expected columns to objects.
Instance Method Summary collapse
-
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of codes of Permissions true if the user has any of the permissions.
-
#able_to_edit?(object) ⇒ Boolean
Expects node to be a Section, Page or Link Returns true if the specified node, or any of its ancestor sections, is editable by any of the user’s ‘CMS User’ groups.
- #able_to_edit_or_publish_content? ⇒ Boolean
- #able_to_modify?(object) ⇒ Boolean
- #able_to_publish?(object) ⇒ Boolean
-
#able_to_view?(object) ⇒ Boolean
Determine if this user has permission to view the specific object.
- #cms_access? ⇒ Boolean
- #cms_user_compatible? ⇒ Boolean
- #disable_able? ⇒ Boolean
- #enable_able? ⇒ Boolean
- #expired? ⇒ Boolean
- #full_name_or_login ⇒ Object
-
#full_name_with_login ⇒ Object
COLUMN based.
-
#groups_with_cms_access ⇒ Object
Permissions.
- #guest? ⇒ Boolean
- #modifiable_sections ⇒ Object
- #password_changeable? ⇒ Boolean
- #permissions ⇒ Object
- #viewable_sections ⇒ Object
Class Method Details
.extended(base) ⇒ Object
add expected columns to objects
26 27 28 29 30 31 32 33 34 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 26 def self.extended(base) unless base.respond_to? :login base.send :alias_method, :login, Cms.user_key_field.to_sym end unless base.respond_to? :full_name base.send :alias_method, :full_name, Cms.user_name_field.to_sym end end |
Instance Method Details
#able_to?(*required_permissions) ⇒ Boolean
Expects a list of codes of Permissions true if the user has any of the permissions
74 75 76 77 78 79 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 74 def able_to?(*) perms = .map(&:to_sym) .any? do |p| perms.include?(p.name.to_sym) end end |
#able_to_edit?(object) ⇒ Boolean
Expects node to be a Section, Page or Link Returns true if the specified node, or any of its ancestor sections, is editable by any of the user’s ‘CMS User’ groups.
120 121 122 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 120 def able_to_edit?(object) able_to?(:edit_content) && able_to_modify?(object) end |
#able_to_edit_or_publish_content? ⇒ Boolean
128 129 130 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 128 def able_to_edit_or_publish_content? able_to?(:edit_content, :publish_content) end |
#able_to_modify?(object) ⇒ Boolean
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 102 def able_to_modify?(object) case object when Cms::Section modifiable_sections.include?(object) when Cms::Page, Cms::Link modifiable_sections.include?(object.section) else if object.class.respond_to?(:connectable?) && object.class.connectable? object.connected_pages.all? { |page| able_to_modify?(page) } else true end end end |
#able_to_publish?(object) ⇒ Boolean
124 125 126 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 124 def able_to_publish?(object) able_to?(:publish_content) && able_to_modify?(object) 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.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 91 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.parent end viewable_sections.include?(section) || cms_access? end |
#cms_access? ⇒ Boolean
132 133 134 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 132 def cms_access? groups.cms_access.present? end |
#cms_user_compatible? ⇒ Boolean
5 6 7 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 5 def cms_user_compatible? true end |
#disable_able? ⇒ Boolean
13 14 15 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 13 def disable_able? false end |
#enable_able? ⇒ Boolean
9 10 11 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 9 def enable_able? false end |
#expired? ⇒ Boolean
21 22 23 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 21 def expired? false end |
#full_name_or_login ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 46 def full_name_or_login if full_name.strip.present? full_name else login end end |
#full_name_with_login ⇒ Object
COLUMN based
42 43 44 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 42 def full_name_with_login "#{full_name} (#{login})" end |
#groups_with_cms_access ⇒ Object
Permissions
56 57 58 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 56 def groups_with_cms_access groups.cms_access end |
#guest? ⇒ Boolean
36 37 38 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 36 def guest? false end |
#modifiable_sections ⇒ Object
68 69 70 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 68 def modifiable_sections @modifiable_sections ||= load_modifiable_sections end |
#password_changeable? ⇒ Boolean
17 18 19 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 17 def password_changeable? false end |
#permissions ⇒ Object
60 61 62 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 60 def @permissions ||= end |
#viewable_sections ⇒ Object
64 65 66 |
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 64 def viewable_sections @viewable_sections ||= load_viewable_sections end |