Class: Zimbra::ACL

Inherits:
Object
  • Object
show all
Defined in:
lib/zimbra/acl.rb

Defined Under Namespace

Classes: TargetObjectNotFound

Constant Summary collapse

TARGET_CLASSES =
[Zimbra::Domain, Zimbra::DistributionList, Zimbra::Cos, Zimbra::]
TARGET_MAPPINGS =
TARGET_CLASSES.inject({}) do |hsh, klass|
  hsh[klass.acl_name] = klass
  hsh[klass] = klass.acl_name
  hsh
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ACL



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zimbra/acl.rb', line 40

def initialize(options = {})
  if options[:grantee]
    self.grantee_id = options[:grantee].id
    self.grantee_class = options[:grantee].class
    self.grantee_name = options[:grantee].grantee_name unless options[:grantee].grantee_name.nil?
  else
    self.grantee_id = options[:grantee_id]
    self.grantee_class = options[:grantee_class]
    self.grantee_name = options[:grantee_name] unless options[:grantee_name].nil?
  end
  self.name = options[:name]
end

Instance Attribute Details

#grantee_classObject

Returns the value of attribute grantee_class.



38
39
40
# File 'lib/zimbra/acl.rb', line 38

def grantee_class
  @grantee_class
end

#grantee_idObject

Returns the value of attribute grantee_id.



38
39
40
# File 'lib/zimbra/acl.rb', line 38

def grantee_id
  @grantee_id
end

#grantee_nameObject

Returns the value of attribute grantee_name.



38
39
40
# File 'lib/zimbra/acl.rb', line 38

def grantee_name
  @grantee_name
end

#nameObject

Returns the value of attribute name.



38
39
40
# File 'lib/zimbra/acl.rb', line 38

def name
  @name
end

Class Method Details

.delete_all(xmldoc) ⇒ Object



13
14
15
# File 'lib/zimbra/acl.rb', line 13

def delete_all(xmldoc)
  A.inject(xmldoc, 'zimbraACE', '', 'c' => '1')
end

.from_s(value) ⇒ Object



30
31
32
33
34
35
# File 'lib/zimbra/acl.rb', line 30

def from_s(value)
  grantee_id, grantee_name, name = value.split(' ')
  grantee_class = TARGET_MAPPINGS[grantee_name]
  return "Target object not found for acl #{value}" if target_class.nil?
  new(grantee_id: grantee_id, grantee_class: grantee_class, name: name)
end

.from_zimbra(node) ⇒ Object



26
27
28
# File 'lib/zimbra/acl.rb', line 26

def from_zimbra(node)
  from_s(node.to_s)
end

.read(node) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/zimbra/acl.rb', line 17

def read(node)
  list = A.read(node, 'zimbraACE')
  return nil if list.nil?
  list = [list] unless list.respond_to?(:map)
  acls = list.map do |ace|
    from_s(ace)
  end
end

Instance Method Details

#apply(xmldoc) ⇒ Object



59
60
61
# File 'lib/zimbra/acl.rb', line 59

def apply(xmldoc)
  A.inject(xmldoc, 'zimbraACE', to_zimbra_acl_value, 'c' => '1')
end

#to_zimbra_acl_valueObject



53
54
55
56
57
# File 'lib/zimbra/acl.rb', line 53

def to_zimbra_acl_value
  id = grantee_id
  type = grantee_class.acl_name
  "#{id} #{type} #{name}"
end