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 882
def self.[] name
  group = super
  group.members.empty? ? nil : group
end
add(name, people) click to toggle source

add a new group to LDAP

# File lib/whimsy/asf/ldap.rb, line 927
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 847
def self.list(filter='cn=*')
  ASF.search_one(base, filter, 'cn').flatten.map {|cn| find(cn)}
end
preload() click to toggle source

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

# File lib/whimsy/asf/ldap.rb, line 863
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 943
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 917
def add(people)
  @members = nil
  people = (Array(people) - members).map(&:id)
  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 902
def dn
  @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first
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 852
def include?(person)
  filter = "(&(cn=#{name})(memberUid=#{person.name}))"
  if ASF.search_one(base, filter, 'cn').empty?
    return false
  else
    return true
  end
end
members() click to toggle source

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

# File lib/whimsy/asf/ldap.rb, line 893
def members
  members = weakref(:members) do
    ASF.search_one(base, "cn=#{name}", 'memberUid').flatten
  end

  members.map {|uid| Person.find(uid)}
end
members=(members) click to toggle source

setter for members, should only be used by preload

# File lib/whimsy/asf/ldap.rb, line 888
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 907
def remove(people)
  @members = nil
  people = (Array(people) & members).map(&:id)
  return if people.empty?
  ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete('memberUid', people)])
ensure
  @members = nil
end
usesproject?() click to toggle source

does this group use ou=project?

# File lib/whimsy/asf/auth.rb, line 83
def usesproject?
  @usesproject ||= ASF::Authorization.new('asf').projects.include?(name)
end