class ASF::Committer

Manage committers: list, add, and remove people not only from the list of people, but from the list of committers.

Public Class Methods

create(attrs) click to toggle source

create a new person and add as a new committer to LDAP. Attrs must include uid, cn, and mail

# File lib/whimsy/asf/ldap.rb, line 616
def self.create(attrs)
  # add person to LDAP
  person = ASF::Person.add(attrs)

  # add person to committers lists
  register(person)

  # return new person
  person
end
deregister(person) click to toggle source

deregister an existing person as a committer updates both committer LDAP groups

# File lib/whimsy/asf/ldap.rb, line 701
def self.deregister(person)
  if person.instance_of? String
    id = person # save for use in error message
    person = ASF::Person[person] or raise ArgumentError.new("Cannot find person: '#{id}'")
  end

  # remove person from 'legacy' committers list
  ASF::Group['committers'].remove(person)

  # remove person from 'new' committers list
  ASF::LDAP.modify("cn=committers,#{@base}",
    [ASF::Base.mod_delete('member', [person.dn])])
end
destroy(person) click to toggle source

completely remove a committer from LDAP ** DO NOT USE ** In almost all cases, use deregister instead

# File lib/whimsy/asf/ldap.rb, line 668
def self.destroy(person)
  # if person is a string, find the person object
  person = ASF::Person.find(person) if person.instance_of? String

  # remove person from 'legacy' committers list, ignoring exceptions
  ASF::Group['committers'].remove(person) rescue nil

  # remove person from 'new' committers list, ignoring exceptions
  ASF::LDAP.modify("cn=committers,#{@base}",
    [ASF::Base.mod_delete('member', [person.dn])]) rescue nil

  # remove person from LDAP (should almost never be done)
  ASF::Person.remove(person.id)
end
list() click to toggle source

get a list of committers

# File lib/whimsy/asf/ldap.rb, line 603
def self.list
  ASF.search_one(base, 'cn=committers', 'member').flatten.
    map {|uid| Person.find uid[/uid=(.*?),/, 1]}
end
listids() click to toggle source

get a list of committers (ids only)

# File lib/whimsy/asf/ldap.rb, line 609
def self.listids
  ASF.search_one(base, 'cn=committers', 'member').flatten.
    map {|uid| uid[/uid=(.*?),/, 1]}
end
register(person) click to toggle source

register an existing person as a committer updates both committer LDAP groups

# File lib/whimsy/asf/ldap.rb, line 685
def self.register(person)
  if person.instance_of? String
    id = person # save for use in error message
    person = ASF::Person[person] or raise ArgumentError.new("Cannot find person: '#{id}'")
  end

  # add person to 'new' committers list
  ASF::LDAP.modify("cn=committers,#{@base}",
    [ASF::Base.mod_add('member', [person.dn])])

  # add person to 'legacy' committers list
  ASF::Group['committers'].add(person)
end

Public Instance Methods

rename(newid, attrs={}) click to toggle source

rename a person/committer

# File lib/whimsy/asf/ldap.rb, line 628
def rename(newid, attrs={})
  # ensure person exists in LDAP
  raise ArgumentError(self.id) unless self.dn

  # create a new person/committer (this should create new uid/gid numbers, if not overridden)
  new_person = ASF::Committer.create(self.attrs.merge(attrs).merge(uid: newid))

  # determine what groups the individual is a member of
  uid_groups = ASF.search_subtree('dc=apache,dc=org',
    "memberUid=#{self.id}", 'dn').flatten
  dn_groups = ASF.search_subtree('dc=apache,dc=org',
    "member=#{self.dn}", 'dn').flatten

  # add new user to all groups
  uid_groups.each do |dn|
    ASF::LDAP.modify(dn, [ASF::Base.mod_add('memberUid', new_person.id)])
  end
  dn_groups.each do |dn|
    ASF::LDAP.modify(dn, [ASF::Base.mod_add('member', new_person.dn)])
  end

  # remove original user from all groups
  uid_groups.each do |dn|
    ASF::LDAP.modify(dn, [ASF::Base.mod_delete('memberUid', self.id)])
  end
  dn_groups.each do |dn|
    ASF::LDAP.modify(dn, [ASF::Base.mod_delete('member', self.dn)])
  end

  # remove original user
  # TODO: the old entry should probably be disabled instead, to avoid reuse of uid/gid
  ASF::Person.remove(person.id)

  # return new user
  new_person
end