class Reactor::Cm::Group

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.

Public Class Methods

all(match = nil) click to toggle source

Returns all known group names as an array of strings.

# File lib/reactor/cm/group.rb, line 38
def all(match = nil)
  self.where("groupText", match)
end
create(attributes = {}) click to toggle source

See @create.

# File lib/reactor/cm/group.rb, line 50
def create(attributes = {})
  object = new(attributes)
  object.send(:create)
  object
end
exists?(name) click to toggle source

Method returns true if a group with the given name exists, false otherwise.

# File lib/reactor/cm/group.rb, line 27
def exists?(name)
  object = new(:name => name)

  begin
    object.send(:get).present?
  rescue XmlRequestError
    false
  end
end
get(name) click to toggle source

See @get.

# File lib/reactor/cm/group.rb, line 43
def get(name)
  object = new(:name => name)
  object.send(:get)
  object
end
new(attributes = {}) click to toggle source
# File lib/reactor/cm/group.rb, line 167
def initialize(attributes = {})
  update_attributes(attributes)
end

Protected Class Methods

base_name() click to toggle source
# File lib/reactor/cm/group.rb, line 163
def self.base_name
  'group'
end

Public Instance Methods

add_users!(users) click to toggle source

Add the given users to the current set of group users.

# File lib/reactor/cm/group.rb, line 74
def add_users!(users)
  users = users.kind_of?(Array) ? users : [users]
  users = self.users | users

  set_users(users)
end
delete!() click to toggle source

Deletes the current group instance.

# File lib/reactor/cm/group.rb, line 120
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) click to toggle source

Remove the given users from the current set of group users.

# File lib/reactor/cm/group.rb, line 82
def remove_users!(users)
  users = users.kind_of?(Array) ? users : [users]
  users = self.users - users

  set_users(users)
end
rename!(name) click to toggle source

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.

# File lib/reactor/cm/group.rb, line 134
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!() click to toggle source

Saves all settable instance attributes to the Content Manager.

# File lib/reactor/cm/group.rb, line 102
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) click to toggle source

Set the group users to the given users.

# File lib/reactor/cm/group.rb, line 90
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) click to toggle source

Returns true, if an user with the given name exists, false otherwise.

# File lib/reactor/cm/group.rb, line 69
def user?(name)
  users.include?(name)
end

Protected Instance Methods

base_name() click to toggle source

The group base name can either be “group”, “groupProxy”, or “secondaryGroupProxy”. Only the two proxy group names take the configured user management (config/userManagement.xml) into account. Use EditorialGroup to work on editorial groups and LiveGroup to work on live groups.

# File lib/reactor/cm/group.rb, line 159
def base_name
  self.class.base_name
end
create() click to toggle source

Creates a new group and sets all attributes that are settable on create. Other attributes are ignored and would be overwritten by the final get call.

# File lib/reactor/cm/group.rb, line 191
def create
  request = XmlRequest.prepare do |xml|
    xml.create_tag!(base_name) do |xml|
      self.class.attributes(:create).each do |name, xml_attribute|
        value = self.send(name)

        xml.value_tag!(xml_attribute.name, value) if value.present?
      end
    end
  end

  response = request.execute!

  self.name = self.class.response_handler.get(response, self.class.xml_attribute(:name))

  get
end
get() click to toggle source

Retrieves a single group matching the name set in the current instance.

# File lib/reactor/cm/group.rb, line 172
def get
  request = XmlRequest.prepare do |xml|
    xml.where_key_tag!(base_name, self.class.primary_key, self.name)
    xml.get_key_tag!(base_name, self.class.xml_attribute_names)
  end

  response = request.execute!

  self.class.attributes(:get).each do |name, xml_attribute|
    value = self.class.response_handler.get(response, xml_attribute)

    set_attribute(name, value)
  end

  self
end