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 e31e7ae: update public & legal name w/dryrun
Date Sat, 02 Apr 2016 15:44:59 GMT
Commit e31e7ae0e173d2b00e4fa9354e9e4b32a73fbab0:
    update public & legal name w/dryrun


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

------------------------------------------------------------
lib/whimsy/asf/svn.rb                                        | ++++++++++ -----
www/roster/models.rb                                         | + 
www/roster/models/committer.rb                               | + 
www/roster/models/svn.rb                                     | +++++++++ 
www/roster/views/actions/pubname.json.rb                     | ++++++++++++ 
------------------------------------------------------------
98 changes: 93 additions, 5 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index cfaf2b4..bbf66d0 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -93,7 +93,7 @@ def self.get(path, user=nil, password=nil)
     end
 
     # update a file in SVN, working entirely in a temporary directory
-    def self.update(path, msg, env, _)
+    def self.update(path, msg, env, _, options={})
       dir = File.dirname(path)
       basename = File.basename(path)
 
@@ -140,10 +140,15 @@ def self.update(path, msg, env, _)
             tmpfile]
         end
 
-        # commit the changes
-        rc = _.system ['svn', 'commit', '--message', msg.untaint,
-          ['--username', env.user, '--password', env.password],
-          tmpfile]
+        if options[:dryrun]
+          # show what would have been committed
+          rc = _.system ['svn', 'diff', tmpfile]
+        else
+          # commit the changes
+          rc = _.system ['svn', 'commit', '--message', msg.untaint,
+            ['--username', env.user, '--password', env.password],
+            tmpfile]
+        end
 
         # fail if there are pending changes
         unless rc == 0 and `svn st`.empty?
diff --git a/www/roster/models.rb b/www/roster/models.rb
index 29636bc..3717e44 100644
--- a/www/roster/models.rb
+++ b/www/roster/models.rb
@@ -5,3 +5,4 @@
 require_relative 'models/group'
 
 require_relative 'models/ldap'
+require_relative 'models/svn'
diff --git a/www/roster/models/committer.rb b/www/roster/models/committer.rb
index f8b1619..67f1b05 100644
--- a/www/roster/models/committer.rb
+++ b/www/roster/models/committer.rb
@@ -96,6 +96,7 @@ def self.serialize(id, env)
             person.icla.name,
             member[:info].split("\n").first.strip
           ].uniq.each do |name|
+            next unless name
             memapp = name.downcase.gsub(/\s/, '-').untaint
             if apps and File.exist? File.join(apps, memapp + '.pdf')
               response[:forms][:member] = memapp + '.pdf'
diff --git a/www/roster/models/svn.rb b/www/roster/models/svn.rb
new file mode 100644
index 0000000..51e21e5
--- /dev/null
+++ b/www/roster/models/svn.rb
@@ -0,0 +1,33 @@
+#
+# Implement an _svn command for json actions.
+#
+# Once tested, this code could migrate into whimsy/asf, and be available
+# for all Rack application (e.g., secmail, board/agenda, roster)
+#
+
+# provide methods to encapsulate updates update LDAP
+module ASF
+  class SVN
+    class JsonBuilder
+      def initialize(env, builder, dryrun)
+        @env = env
+        @builder = builder
+        @dryrun = dryrun
+      end
+
+      def update(name, options, &block)
+        ASF::SVN.update(name, options[:message], @env, @builder, 
+          dryrun: @dryrun, &block)
+      end
+    end
+  end
+end
+
+# provide _svn command which forwards requests to the ASF::SVN::JsonBuilder
+module Wunderbar
+  class JsonBuilder
+    def _svn
+      ASF::SVN::JsonBuilder.new(env, self, params['dryrun'])
+    end
+  end
+end
diff --git a/www/roster/views/actions/pubname.json.rb b/www/roster/views/actions/pubname.json.rb
new file mode 100644
index 0000000..7ef586e
--- /dev/null
+++ b/www/roster/views/actions/pubname.json.rb
@@ -0,0 +1,48 @@
+#
+# Update LDAP SpamAssassin score attribute for a committer
+#
+person = ASF::Person.find(@userid)
+
+# update LDAP
+if person.public_name != @publicname
+  _ldap.update do
+    _previous person.public_name
+
+    if @publicname and not @dryrun
+      person.modify 'cn', @publicname
+    end
+  end
+end
+
+# determine commit message
+if person.icla.legal_name != @legalname
+  if person.icla.name != @publicname
+    message = "Update legal and public name for #{@userid}"
+  else
+    message = "Update legal name for #{@userid}"
+  end
+elsif person.icla.name != @publicname
+  message = "Update public name for #{@userid}"
+else
+  message = nil
+end
+
+# update iclas.txt
+if message
+  icla_txt = ASF::SVN['private/foundation/officers/iclas.txt']
+  _svn.update icla_txt, message: message do |dir, text|
+    # replace legal and public names in icla record
+    userid = Regexp.escape(@userid)
+    text[/^#{userid}:(.*?):/, 1] = @legalname
+    text[/^#{userid}:.*?:(.*?):/, 1] = @publicname
+  
+    text
+  end
+end
+
+# update cache
+person.icla.legal_name = @legalname
+person.icla.name = @publicname
+
+# return updated committer info
+_committer Committer.serialize(@userid, env)

Mime
View raw message