whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit fd70d21: remove, add, and auth
Date Mon, 15 Feb 2016 02:12:33 GMT
Commit fd70d21b7171adc5d8fcd907c77f535406bb8655:
    remove, add, and auth


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
lib/whimsy/asf/ldap.rb                                       | ++++++++++++++ 
lib/whimsy/asf/rack.rb                                       | +++++ ---
www/roster/Rakefile                                          | +++++++++++++ 
www/roster/views/actions/committee.json.rb                   | +++++ ----
------------------------------------------------------------
58 changes: 51 additions, 7 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index c54fda1..83f23ba 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -425,6 +425,22 @@ def members
 
       members.map {|uid| Person.find(uid)}
     end
+
+    def dn
+      @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first
+    end
+
+    def remove(people)
+      people = Array(people).map(&:id)
+      mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, 'memberUid', people)
+      ASF.ldap.modify(self.dn, [mod])
+    end
+
+    def add(people)
+      people = Array(people).map(&:dn)
+      mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, 'memberUid', people)
+      ASF.ldap.modify(self.dn, [mod])
+    end
   end
 
   class Committee < Base
@@ -462,6 +478,18 @@ def members
     def dn
       @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first
     end
+
+    def remove(people)
+      people = Array(people).map(&:dn)
+      mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, 'member', people)
+      ASF.ldap.modify(self.dn, [mod])
+    end
+
+    def add(people)
+      people = Array(people).map(&:dn)
+      mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, 'member', people)
+      ASF.ldap.modify(self.dn, [mod])
+    end
   end
 
   class Service < Base
diff --git a/lib/whimsy/asf/rack.rb b/lib/whimsy/asf/rack.rb
index ea7e094..cfa52c4 100644
--- a/lib/whimsy/asf/rack.rb
+++ b/lib/whimsy/asf/rack.rb
@@ -21,12 +21,14 @@ module Auth
     def self.decode(env)
       class << env; attr_accessor :user, :password; end
 
-      if env['HTTP_AUTHORIZATION'].to_s.empty?
+      auth = env['HTTP_AUTHORIZATION'] || ENV['HTTP_AUTHORIZATION']
+
+      if auth.to_s.empty?
         env.user = env['REMOTE_USER'] || ENV['USER'] || Etc.getpwuid.name
       else
         require 'base64'
-        env.user, env.password = Base64.decode64(env['HTTP_AUTHORIZATION'][
-          /^Basic ([A-Za-z0-9+\/=]+)$/,1].to_s).split(':',2)
+        env.user, env.password = Base64.
+          decode64(auth[/^Basic ([A-Za-z0-9+\/=]+)$/,1].to_s).split(':',2)
       end
 
       env['REMOTE_USER'] ||= env.user
diff --git a/www/roster/Rakefile b/www/roster/Rakefile
index f77b646..553955d 100644
--- a/www/roster/Rakefile
+++ b/www/roster/Rakefile
@@ -10,6 +10,19 @@ file 'Gemfile.lock' => 'Gemfile' do
   touch 'Gemfile.lock'
 end
 
+# setup authentication
+task :auth do
+  require 'etc'
+  require 'io/console'
+  require 'base64'
+
+  user = ENV['USER'] || ETC.getlogin
+  STDOUT.write "Enter password for #{user}: "
+  password = STDIN.noecho(&:gets).chomp
+  ENV['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user}:#{password}")}"
+  STDOUT.puts
+end
+
 desc 'install dependencies'
 task :bundle => 'Gemfile.lock' do
   require 'bundler'
diff --git a/www/roster/views/actions/committee.json.rb b/www/roster/views/actions/committee.json.rb
index c567257..d45ef96 100644
--- a/www/roster/views/actions/committee.json.rb
+++ b/www/roster/views/actions/committee.json.rb
@@ -1,14 +1,15 @@
 if env.password
   ASF::LDAP.bind(env.user, env.password) do
+    person = ASF::Person.find(@person)
     pmc = ASF::Committee.find(@pmc) if @targets.include? 'pmc'
     group = ASF::Group.find(@pmc) if @targets.include? 'commit'
 
     if @action == 'add'
-      pmc.add(@person) if pmc
-      group.add(@person) if group
+      pmc.add(person) if pmc
+      group.add(person) if group
     elsif @action == 'remove'
-      pmc.remove(@person) if pmc
-      group.remove(@person) if group
+      pmc.remove(person) if pmc
+      group.remove(person) if group
     end
   end
 end

Mime
View raw message