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 1110
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 1100
def self.list(filter='cn=*')
  ASF.search_one(base, filter, 'cn').flatten.map {|cn| Project.find(cn)}
end
listids(filter='cn=*') click to toggle source

obtain a list of projectids from LDAP

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

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

# File lib/whimsy/asf/ldap.rb, line 1117
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'] || []
    # TODO members and owners are duplicated in the project object and the returned hash
    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 1237
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 1254
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 1243
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 1144
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 1139
def dn
  @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first rescue nil
end
memberids() click to toggle source

list of member ids in the project

# File lib/whimsy/asf/ldap.rb, line 1182
def memberids
  members = weakref(:members) do
    ASF.search_one(base, "cn=#{name}", 'member').flatten
  end    
  members.map {|uid| uid[/uid=(.*?),/,1]}
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 1173
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 1162
def members=(members)
  @members = WeakRef.new(members)
end
ownerids() click to toggle source

list of owner ids in the project

# File lib/whimsy/asf/ldap.rb, line 1200
def ownerids
  owners = weakref(:owners) do
    ASF.search_one(base, "cn=#{name}", 'owner').flatten
  end
  owners.map {|uid| uid[/uid=(.*?),/,1]}
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 1191
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 1167
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 1209
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 1226
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 1215
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