class ASF::Project

Ultimately, this will include both PMCs and PPMCs, and enable separate updating of owners and members. For now this is only used for PPMCs and owners and members are kept in sync.

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 project only if it actually exits

Calls superclass method ASF::Base.[]
# File lib/whimsy/asf/ldap.rb, line 960
def self.[] name
  project = super
  project.members.empty? ? nil : project
end
list(filter='cn=*') click to toggle source

obtain a list of projects from LDAP

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

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

# File lib/whimsy/asf/ldap.rb, line 967
def self.preload
  Hash[ASF.search_one(base, "cn=*", %w(dn member owner modifyTimestamp createTimestamp)).map do |results|
    cn = results['dn'].first[/^cn=(.*?),/, 1]
    project = self.find(cn)
    project.modifyTimestamp = results['modifyTimestamp'].first # it is returned as an array of 1 entry
    project.createTimestamp = results['createTimestamp'].first # it is returned as an array of 1 entry
    members = results['member'] || []
    owners = results['owner'] || []
    project.members = members
    project.owners = owners
    [project, [members, owners]] # TODO is this correct? it seems to work...
  end]
end

Public Instance Methods

add(people) click to toggle source

add people to a project as members and owners in LDAP

# File lib/whimsy/asf/ldap.rb, line 1069
def add(people)
  add_owners(people)
  add_members(people)
end
add_members(people) click to toggle source

add people as members of a project in LDAP

# File lib/whimsy/asf/ldap.rb, line 1086
def add_members(people)
  @members = nil
  additions = (Array(people) - members).map(&:dn)
  unless additions.empty?
    ASF::LDAP.modify(self.dn, [ASF::Base.mod_add('member', additions)])
  end
ensure
  @members = nil
end
add_owners(people) click to toggle source

add people as owners of a project in LDAP

# File lib/whimsy/asf/ldap.rb, line 1075
def add_owners(people)
  @owners = nil
  additions = (Array(people) - owners).map(&:dn)
  unless additions.empty?
    ASF::LDAP.modify(self.dn, [ASF::Base.mod_add('owner', additions)])
  end
ensure
  @owners = nil
end
create(owners, committers=nil) click to toggle source

create an LDAP group for this project

# File lib/whimsy/asf/ldap.rb, line 993
def create(owners, committers=nil)
  committers = Array(committers || owners).map(&:dn)
  owners = Array(owners).map(&:dn)

  entry = [
    ASF::Base.mod_add('objectClass', ['groupOfNames', 'top']),
    ASF::Base.mod_add('cn', name), 
    ASF::Base.mod_add('owner', owners),
    ASF::Base.mod_add('member', committers),
  ]

  ASF::LDAP.add("cn=#{name},#{base}", entry)

  self.owners = owners
  self.members = committers
end
dn() click to toggle source

Designated Name from LDAP

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

list of committers on this project. Stored in LDAP as a member attribute.

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

  members.map {|uid| Person.find uid[/uid=(.*?),/,1]}
end
members=(members) click to toggle source

setter for members, should only be called by preload.

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

list of owners on this project. Stored in LDAP as a owners attribute.

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

  owners.map {|uid| Person.find uid[/uid=(.*?),/,1]}
end
owners=(owners) click to toggle source

setter for owners, should only be called by preload.

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

remove people from a project as owners and members in LDAP

# File lib/whimsy/asf/ldap.rb, line 1041
def remove(people)
  remove_owners(people)
  remove_members(people)
end
remove_members(people) click to toggle source

remove people as members of a project in LDAP

# File lib/whimsy/asf/ldap.rb, line 1058
def remove_members(people)
  @members = nil
  removals = (Array(people) & members).map(&:dn)
  unless removals.empty?
    ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete('member', removals)])
  end
ensure
  @members = nil
end
remove_owners(people) click to toggle source

remove people as owners of a project in LDAP

# File lib/whimsy/asf/ldap.rb, line 1047
def remove_owners(people)
  @owners = nil
  removals = (Array(people) & owners).map(&:dn)
  unless removals.empty?
    ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete('owner', removals)])
  end
ensure
  @owners = nil
end