class ASF::Group

Access to LDAP groups; where committer lists for PMCs have traditionally been stored. The intent is to move this data to member attributes on Project lists.

Attributes

createTimestamp[RW]

Date this committee was initially created in LDAP.

modifyTimestamp[RW]

Date this committee was last modified in LDAP.

Public Class Methods

[](name) click to toggle source

return group only if it actually exits

Calls superclass method ASF::Base::[]
# File lib/whimsy/asf/ldap.rb, line 1143
def self.[](name)
  group = super
  group.dn ? group : nil
end
add(name, people) click to toggle source

add a new group to LDAP

# File lib/whimsy/asf/ldap.rb, line 1194
def self.add(name, people)
  nextgid = ASF.search_one(ASF::Group.base, 'cn=*', 'gidNumber').
    flatten.map(&:to_i).max + 1

  entry = [
    mod_add('objectClass', ['posixGroup', 'top']),
    mod_add('cn', name),
    mod_add('userPassword', '{crypt}*'),
    mod_add('gidNumber', nextgid.to_s),
    mod_add('memberUid', people.map(&:id))
  ]

  ASF::LDAP.add("cn=#{name},#{base}", entry)
end
list(filter='cn=*') click to toggle source

obtain a list of groups from LDAP

# File lib/whimsy/asf/ldap.rb, line 1103
def self.list(filter='cn=*')
  ASF.search_one(base, filter, 'cn').flatten.map {|cn| find(cn)}
end
listcns(filter='cn=*') click to toggle source

return a list of groups (cns only), from LDAP.

# File lib/whimsy/asf/ldap.rb, line 1108
def self.listcns(filter='cn=*')
  ASF.search_one(base, filter, 'cn').flatten
end
preload() click to toggle source

fetch dn, member, modifyTimestamp, and createTimestamp for all groups in LDAP.

# File lib/whimsy/asf/ldap.rb, line 1124
def self.preload
  Hash[ASF.search_one(base, 'cn=*', %w(dn memberUid modifyTimestamp createTimestamp)).map do |results|
    cn = results['dn'].first[/^cn=(.*?),/, 1]
    group = ASF::Group.find(cn)
    group.modifyTimestamp = results['modifyTimestamp'].first # it is returned as an array of 1 entry
    group.createTimestamp = results['createTimestamp'].first # it is returned as an array of 1 entry
    members = results['memberUid'] || []
    group.members = members
    [group, members]
  end]
end
remove(name) click to toggle source

remove a group from LDAP

# File lib/whimsy/asf/ldap.rb, line 1210
def self.remove(name)
  ASF::LDAP.delete("cn=#{name},#{base}")
end

Public Instance Methods

add(people) click to toggle source

add people to an existing group in LDAP

# File lib/whimsy/asf/ldap.rb, line 1183
def add(people)
  # addition fails if the id is present
  @members = nil  # force fresh LDAP search
  people = Array(people).map(&:id) - memberids
  return if people.empty?
  ASF::LDAP.modify(self.dn, [ASF::Base.mod_add('memberUid', people)])
ensure
  @members = nil
end
dn() click to toggle source

Designated Name from LDAP

# File lib/whimsy/asf/ldap.rb, line 1167
def dn
  @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first rescue nil
end
include?(person) click to toggle source

determine if a given ASF::Person is a member of this group

# File lib/whimsy/asf/ldap.rb, line 1113
def include?(person)
  filter = "(&(cn=#{name})(memberUid=#{person.name}))"
  if ASF.search_one(base, filter, 'cn').empty?
    return false
  else
    return true
  end
end
memberids() click to toggle source

return a list of ids who are members of this group

# File lib/whimsy/asf/ldap.rb, line 1160
def memberids
  weakref(:members) do # initialises @members if necessary
    ASF.search_one(base, "cn=#{name}", 'memberUid').flatten
  end
end
members() click to toggle source

return a list of ASF::People who are members of this group

# File lib/whimsy/asf/ldap.rb, line 1155
def members
  memberids.map {|uid| Person.find(uid)}
end
members=(members) click to toggle source

setter for members, should only be used by preload N.B. Do not dereference @members directly; use weakref(:members) instead

# File lib/whimsy/asf/ldap.rb, line 1150
def members=(members)
  @members = WeakRef.new(members)
end
remove(people) click to toggle source

remove people from an existing group in LDAP

# File lib/whimsy/asf/ldap.rb, line 1172
def remove(people)
  # Removal fails if the id is not present
  @members = nil  # force fresh LDAP search
  people = Array(people).map(&:id) & memberids
  return if people.empty?
  ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete('memberUid', people)])
ensure
  @members = nil
end