Module: Cms::UsersService::CmsUserCompatibilityModule

Defined in:
lib/cms/users_service/cms_user_compatibility_module.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 74

def able_to?(*required_permissions)
  perms = required_permissions.map(&:to_sym)
  permissions.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.

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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.

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


13
14
15
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 13

def disable_able?
  false
end

#enable_able?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 9

def enable_able?
  false
end

#expired?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 21

def expired?
  false
end

#full_name_or_loginObject



46
47
48
49
50
51
52
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 46

def 
  if full_name.strip.present?
    full_name
  else
    
  end
end

#full_name_with_loginObject

COLUMN based



42
43
44
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 42

def 
  "#{full_name} (#{})"
end

#groups_with_cms_accessObject

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 36

def guest?
  false
end

#modifiable_sectionsObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 17

def password_changeable?
  false
end

#permissionsObject



60
61
62
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 60

def permissions
  @permissions ||= load_permissions
end

#viewable_sectionsObject



64
65
66
# File 'lib/cms/users_service/cms_user_compatibility_module.rb', line 64

def viewable_sections
  @viewable_sections ||= load_viewable_sections
end