whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: add a create button for podling group
Date Sat, 03 Jun 2017 13:41:38 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  516c60c   add a create button for podling group
516c60c is described below

commit 516c60cac70c4504920377e5235d972aab32bcab
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sat Jun 3 09:41:24 2017 -0400

    add a create button for podling group
---
 lib/whimsy/asf/ldap.rb                | 18 ++++++++++++-
 www/roster/views/actions/ppmc.json.rb |  6 ++++-
 www/roster/views/ppmc/main.js.rb      | 50 ++++++++++++++++++++++++++++++++---
 www/roster/views/ppmc/mentors.js.rb   |  1 -
 www/roster/views/ppmcs.html.rb        |  2 +-
 5 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index bfe2df2..caa249c 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -724,11 +724,27 @@ module ASF
 
     attr_accessor :modifyTimestamp, :createTimestamp
 
-
     def dn
       @dn ||= ASF.search_one(base, "cn=#{name}", 'dn').first.first rescue nil
     end
 
+    # create an LDAP group for this project
+    def create(people)
+      people = Array(people).map(&:dn)
+
+      entry = [
+        ASF::Base.mod_add('objectClass', ['groupOfNames', 'top']),
+        ASF::Base.mod_add('cn', name), 
+        ASF::Base.mod_add('member', people),
+        ASF::Base.mod_add('owner', people)
+      ]
+
+      ASF::LDAP.add("cn=#{name},#{base}", entry)
+
+      self.owners = people
+      self.members = people
+    end
+
     def members=(members)
       @members = WeakRef.new(members)
     end
diff --git a/www/roster/views/actions/ppmc.json.rb b/www/roster/views/actions/ppmc.json.rb
index a05548a..69f79e8 100644
--- a/www/roster/views/actions/ppmc.json.rb
+++ b/www/roster/views/actions/ppmc.json.rb
@@ -5,7 +5,11 @@ if env.password
   # update LDAP
   if @targets.include? 'ppmc' or @targets.include? 'committer'
     ASF::LDAP.bind(env.user, env.password) do
-      if @action == 'add'
+      if @targets.include? 'ldap'
+        if @action == 'add'
+          project.create(people)
+        end
+      elsif @action == 'add'
         project.add_owners(people) if @targets.include? 'ppmc'
         project.add_members(people) if @targets.include? 'committer'
       elsif @action == 'remove'
diff --git a/www/roster/views/ppmc/main.js.rb b/www/roster/views/ppmc/main.js.rb
index 5b97dbc..5467e9f 100644
--- a/www/roster/views/ppmc/main.js.rb
+++ b/www/roster/views/ppmc/main.js.rb
@@ -3,14 +3,18 @@
 #
 
 class PPMC < React
+  def initialize
+    @create_disabled = false
+  end
+
   def render
     auth = @@auth and (@@auth.secretary or @@auth.root or
-      @@ppmc.owners.include? @@auth.id)
+      @ppmc.owners.include? @@auth.id)
 
     # header
     _h1 do
-      _a @@ppmc.display_name, 
-        href: "https://incubator.apache.org/projects/#{@@ppmc.id}.html"
+      _a @ppmc.display_name, 
+        href: "https://incubator.apache.org/projects/#{@ppmc.id}.html"
       _small " established #{@ppmc.established}" if @ppmc.established
     end
 
@@ -27,6 +31,11 @@ class PPMC < React
       end
     end
 
+    if @ppmc.owners.empty? and (@@auth.root or @@auth.secretary)
+      _button.btn.btn_primary 'Create project in LDAP', onClick: self.post,
+        disabled: @create_disabled
+    end
+
     # main content
     _PPMCMentors auth: @@auth.ipmc, ppmc: @ppmc
     _PPMCMembers auth: auth, ppmc: @ppmc
@@ -97,4 +106,39 @@ class PPMC < React
   def update(ppmc)
     @ppmc = ppmc
   end
+
+  # create project in ldap
+  def post()
+    # construct arguments to fetch
+    args = {
+      method: 'post',
+      credentials: 'include',
+      headers: {'Content-Type' => 'application/json'},
+      body: {
+        project: @ppmc.id, 
+        ids: @ppmc.mentors.join(','), 
+        action: 'add', 
+        targets: ['ldap', 'ppmc', 'committer']
+      }.inspect
+    }
+
+    @disabled = true
+    Polyfill.require(%w(Promise fetch)) do
+      @create_disabled = true
+      fetch("actions/ppmc", args).then {|response|
+        content_type = response.headers.get('content-type') || ''
+        if response.status == 200 and content_type.include? 'json'
+          response.json().then do |json|
+            self.update(json)
+          end
+        else
+          alert "#{response.status} #{response.statusText}"
+        end
+        @create_disabled = false
+      }.catch {|error|
+        alert errror
+        @create_disabled = false
+      }
+    end
+  end
 end
diff --git a/www/roster/views/ppmc/mentors.js.rb b/www/roster/views/ppmc/mentors.js.rb
index e18891e..8c4756c 100644
--- a/www/roster/views/ppmc/mentors.js.rb
+++ b/www/roster/views/ppmc/mentors.js.rb
@@ -89,7 +89,6 @@ class PPMCMentors < React
       fetch('committee/incubator.json', credentials: 'include').then {|response|
 	if response.status == 200
 	  response.json().then do |json|
-	    console.log json.committers.keys()
 	    @ipmc = json.roster.keys()
 	  end
 	else
diff --git a/www/roster/views/ppmcs.html.rb b/www/roster/views/ppmcs.html.rb
index 0d69c7d..059f76d 100644
--- a/www/roster/views/ppmcs.html.rb
+++ b/www/roster/views/ppmcs.html.rb
@@ -30,7 +30,7 @@ _html do
           if project_names.include? ppmc.name
             _a ppmc.display_name, href: "ppmc/#{ppmc.name}"
           else
-            _span.label_danger ppmc.display_name
+            _a.label_danger ppmc.display_name, href: "ppmc/#{ppmc.name}"
           end
         end
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message