Class: Reactor::Cm::Group
- Inherits:
-
Object
- Object
- Reactor::Cm::Group
- Extended by:
- WhereQuery
- Includes:
- Permissions, XmlAttributes
- Defined in:
- lib/reactor/cm/group.rb
Overview
The Group class can be used to work with user groups defined or known to the content manager. It allows you to create, edit and delete groups, handle users and permissions and get the group meta data. The Group class does not respect the user management defined under “config/userManagement.xml”, but is the basis for class like @EditorialGroup or @LiveGroup that respect the user management.
Direct Known Subclasses
Class Method Summary collapse
-
.all(match = nil) ⇒ Object
Returns all known group names as an array of strings.
-
.create(attributes = {}) ⇒ Object
See @create.
-
.exists?(name) ⇒ Boolean
Method returns true if a group with the given
nameexists, false otherwise. -
.get(name) ⇒ Object
See @get.
Instance Method Summary collapse
-
#add_users!(users) ⇒ Object
Add the given
usersto the current set of group users. -
#delete! ⇒ Object
Deletes the current group instance.
-
#remove_users!(users) ⇒ Object
Remove the given
usersfrom the current set of group users. -
#rename!(name) ⇒ Object
As it is not possible to actually rename an existing group, this method creates a new group with the same attributes but a different name as the current instance and deletes the old group.
-
#save! ⇒ Object
Saves all settable instance attributes to the Content Manager.
-
#set_users!(users) ⇒ Object
Set the group users to the given
users. -
#user?(name) ⇒ Boolean
Returns true, if an user with the given
nameexists, false otherwise.
Methods included from WhereQuery
Methods included from Permissions
#global_permission?, #grant_global_permissions!, included, #revoke_global_permissions!, #set_global_permissions!
Class Method Details
.all(match = nil) ⇒ Object
Returns all known group names as an array of strings.
39 40 41 |
# File 'lib/reactor/cm/group.rb', line 39 def all(match = nil) self.where("groupText", match) end |
.create(attributes = {}) ⇒ Object
See @create.
51 52 53 54 55 |
# File 'lib/reactor/cm/group.rb', line 51 def create(attributes = {}) object = new(attributes) object.send(:create) object end |
.exists?(name) ⇒ Boolean
Method returns true if a group with the given name exists, false otherwise.
28 29 30 31 32 33 34 35 36 |
# File 'lib/reactor/cm/group.rb', line 28 def exists?(name) object = new(:name => name) begin object.send(:get).present? rescue XmlRequestError false end end |
.get(name) ⇒ Object
See @get.
44 45 46 47 48 |
# File 'lib/reactor/cm/group.rb', line 44 def get(name) object = new(:name => name) object.send(:get) object end |
Instance Method Details
#add_users!(users) ⇒ Object
Add the given users to the current set of group users.
75 76 77 78 79 80 |
# File 'lib/reactor/cm/group.rb', line 75 def add_users!(users) users = users.kind_of?(Array) ? users : [users] users = self.users | users set_users(users) end |
#delete! ⇒ Object
Deletes the current group instance.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/reactor/cm/group.rb', line 121 def delete! request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, self.class.primary_key, self.name) xml.delete_tag!(base_name) end response = request.execute! response.ok? end |
#remove_users!(users) ⇒ Object
Remove the given users from the current set of group users.
83 84 85 86 87 88 |
# File 'lib/reactor/cm/group.rb', line 83 def remove_users!(users) users = users.kind_of?(Array) ? users : [users] users = self.users - users set_users(users) end |
#rename!(name) ⇒ Object
As it is not possible to actually rename an existing group, this method creates a new group with the same attributes but a different name as the current instance and deletes the old group. The method returns the new group object.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/reactor/cm/group.rb', line 135 def rename!(name) new_attributes = self.class.attributes.inject({}) do |hash, mapping| key, _ = mapping hash[key] = self.send(key) hash end if self.delete! new_attributes[:name] = name self.class.create(new_attributes) else false end end |
#save! ⇒ Object
Saves all settable instance attributes to the Content Manager.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/reactor/cm/group.rb', line 103 def save! request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, self.class.primary_key, self.name) xml.set_tag!(base_name) do self.class.attributes(:set).each do |name, xml_attribute| value = self.send(name) xml.value_tag!(xml_attribute.name, value) end end end response = request.execute! response.ok? end |
#set_users!(users) ⇒ Object
Set the group users to the given users.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/reactor/cm/group.rb', line 91 def set_users!(users) request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, self.class.primary_key, self.name) xml.set_key_tag!(base_name, self.class.xml_attribute(:users).name, users) end request.execute! self.users = users end |
#user?(name) ⇒ Boolean
Returns true, if an user with the given name exists, false otherwise.
70 71 72 |
# File 'lib/reactor/cm/group.rb', line 70 def user?(name) users.include?(name) end |