Class: Reactor::Cm::Group
- Inherits:
-
Object
- Object
- Reactor::Cm::Group
- Includes:
- 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 = '') ⇒ 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
name
exists, false otherwise. -
.get(name) ⇒ Object
See @get.
Instance Method Summary collapse
-
#add_users!(users) ⇒ Object
Add the given
users
to the current set of group users. -
#delete! ⇒ Object
Deletes the current group instance.
-
#global_permission?(name) ⇒ Boolean
Returns true, if a global permission with the given
name
exists, false otherwise. -
#grant_global_permissions!(permissions) ⇒ Object
Add the given
permissions
to the current set of group permissions. -
#remove_users!(users) ⇒ Object
Remove the given
users
from 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.
-
#revoke_global_permissions!(permissions) ⇒ Object
Take away the given
permissions
from the current set of group permissions. -
#save! ⇒ Object
Saves all settable instance attributes to the Content Manager.
-
#set_global_permissions!(permissions) ⇒ Object
Set the group permissions to the given
permissions
. -
#set_users!(users) ⇒ Object
Set the group users to the given
users
. -
#user?(name) ⇒ Boolean
Returns true, if an user with the given
name
exists, false otherwise.
Class Method Details
.all(match = '') ⇒ Object
Returns all known group names as an array of strings.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reactor/cm/group.rb', line 35 def all(match = '') object = new base_name = object.send(:base_name) request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'groupText', match) xml.get_key_tag!(base_name, 'name') end begin response = request.execute! groups = ResponseHandler::String.new.get(response, '//group/name/text()') groups.is_a?(Array) ? groups : [groups] rescue XmlRequestError [] end end |
.create(attributes = {}) ⇒ Object
See @create.
64 65 66 67 68 |
# File 'lib/reactor/cm/group.rb', line 64 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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/reactor/cm/group.rb', line 24 def exists?(name) object = new(:name => name) begin object.send(:get).present? rescue XmlRequestError false end end |
.get(name) ⇒ Object
See @get.
57 58 59 60 61 |
# File 'lib/reactor/cm/group.rb', line 57 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.
120 121 122 123 124 125 |
# File 'lib/reactor/cm/group.rb', line 120 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.
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/reactor/cm/group.rb', line 166 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 |
#global_permission?(name) ⇒ Boolean
Returns true, if a global permission with the given name
exists, false otherwise.
82 83 84 |
# File 'lib/reactor/cm/group.rb', line 82 def (name) self..include?(name.to_s) end |
#grant_global_permissions!(permissions) ⇒ Object
Add the given permissions
to the current set of group permissions.
87 88 89 90 91 92 |
# File 'lib/reactor/cm/group.rb', line 87 def () = .kind_of?(Array) ? : [] = self. | () end |
#remove_users!(users) ⇒ Object
Remove the given users
from the current set of group users.
128 129 130 131 132 133 |
# File 'lib/reactor/cm/group.rb', line 128 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.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/reactor/cm/group.rb', line 180 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 |
#revoke_global_permissions!(permissions) ⇒ Object
Take away the given permissions
from the current set of group permissions.
95 96 97 98 99 100 |
# File 'lib/reactor/cm/group.rb', line 95 def () = .kind_of?(Array) ? : [] = self. - () end |
#save! ⇒ Object
Saves all settable instance attributes to the Content Manager.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/reactor/cm/group.rb', line 148 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_global_permissions!(permissions) ⇒ Object
Set the group permissions to the given permissions
.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/reactor/cm/group.rb', line 103 def () 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(:global_permissions).name, ) end request.execute! self. = end |
#set_users!(users) ⇒ Object
Set the group users to the given users
.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/reactor/cm/group.rb', line 136 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.
115 116 117 |
# File 'lib/reactor/cm/group.rb', line 115 def user?(name) users.include?(name) end |