whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Centralise logic and simplify
Date Fri, 25 Nov 2016 11:59:16 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  ff5ffe6   Centralise logic and simplify
ff5ffe6 is described below

commit ff5ffe6789bfa94fe65d3a4cb3421db6265292e3
Author: Sebb <sebb@apache.org>
AuthorDate: Fri Nov 25 11:58:53 2016 +0000

    Centralise logic and simplify
    
    List name filtering belongs in ASF::Mail
    Re-use podlings.xml parsing from ASF::Podling
---
 lib/whimsy/asf/mail.rb       | 34 +++++++++++++++++++++---
 www/committers/subscribe.cgi | 62 ++++++++++++++++----------------------------
 2 files changed, 54 insertions(+), 42 deletions(-)

diff --git a/lib/whimsy/asf/mail.rb b/lib/whimsy/asf/mail.rb
index cf8f156..45c733b 100644
--- a/lib/whimsy/asf/mail.rb
+++ b/lib/whimsy/asf/mail.rb
@@ -38,19 +38,47 @@ module ASF
       list
     end
 
-    def self.lists(public_private= false)
+    # Parse the .archives file to get the list names
+    def self._load_lists
       apmail_bin = ASF::SVN['infra/infrastructure/apmail/trunk/bin']
       file = File.join(apmail_bin, '.archives')
       if not @lists or File.mtime(file) != @list_mtime
-        @list_mtime = File.mtime(file)
-        @lists = Hash[File.read(file).scan(
+        lists = Hash[File.read(file).scan(
           /^\s+"(\w[-\w]+)", "\/home\/apmail\/(public|private)-arch\//
         )]
+        # Drop the infra test lists
+        lists.delete_if {|list| list =~ /-infra-[a-z]$/ }
+        @lists = lists
+        @list_mtime = File.mtime(file)
       end
+    end
 
+    def self.lists(public_private= false)
+      Mail._load_lists
       public_private ? @lists : @lists.keys
     end
 
+    # which lists are available for subscription via Whimsy?
+    def self.cansub(member, pmc_chair)
+      Mail._load_lists
+      if member
+          lists = @lists.keys
+          # These are not subscribable via Whimsy
+          lists.delete_if {|list| list =~ /^(ea|secretary|president|treasurer|chairman|committers|pmc-chairs)$/
}
+          lists.delete_if {|list| list =~ /(^|-)security$|^security(-|$)/ }
+          lists
+      else
+          whitelist = ['infra-users', 'jobs', 'site-dev', 'committers-cvs', 'site-cvs', 'concom',
'party']
+          # Can always subscribe to public lists and the whitelist
+          lists = @lists.keys.select{|key| @lists[key] == 'public' or whitelist.include?
key}
+          # Chairs need the board
+          if pmc_chair
+            lists += ['board']
+          end
+          lists
+      end
+    end
+
     # common configuration for sending mail
     def self.configure
       # fetch overrides
diff --git a/www/committers/subscribe.cgi b/www/committers/subscribe.cgi
index a9c48ff..11fbd98 100755
--- a/www/committers/subscribe.cgi
+++ b/www/committers/subscribe.cgi
@@ -12,48 +12,27 @@ FORMAT_NUMBER = 3 # json format number
 user = ASF::Person.new($USER)
 # authz handled by httpd
 
-# TODO dedup, copied from mlreq
-class Podlings
-  def self.list
-    return @list if @list
-    # extract the names of podlings (and aliases) from podlings.xml
-    require 'nokogiri'
-    incubator_content = ASF::SVN['asf/incubator/public/trunk/content']
-      current = Nokogiri::XML(File.read("#{incubator_content}/podlings.xml")).
-      search('podling[status=current]')
-    podlings = current.map {|podling| podling['resource']}
-    podlings += current.map {|podling| podling['resourceAliases']}.compact.
-      map {|names| names.split(/[, ]+/)}.flatten
-    @list = podlings
+# get the possible names of the current and retired podlings
+current=[]
+retired=[]
+ASF::Podling.list.each {|p|
+  names = p['resourceAliases'] # array, may be empty
+  names.push p['resource'] # single string, always present
+  status = p['status']
+  if status == 'current'
+    current.concat(names)
+  elsif status == 'retired'
+    retired.concat(names)
   end
-end
-
-lists = ASF::Mail.lists
-lists.delete_if {|list| list =~ /^(ea|secretary|president|treasurer|chairman|committers$)/
}
-lists.delete_if {|list| list =~ /(^|-)security$|^security(-|$)/ }
+}
 
 pmcs = ASF::Committee.list.map(&:mail_list)
-seen = Hash.new
-lists.each do |list|
-  seen[list] = 0
-  seen[list] = 1 if pmcs.include? list.split('-').first
-  seen[list] = 2 if Podlings.list.include? list.split('-').first
-  seen[list] = 2 if (list.split('-').first == 'incubator') \
-                    && (Podlings.list.include? list.split('-')[1])
-end
 
-unless user.asf_member?
-  # non-members only see specifically whitelisted foundation lists as well
-  # as all non-private committee lists
-  whitelist = ['infrastructure', 'jobs', 'site-dev', 'committers-cvs',
-     'site-cvs', 'concom', 'party']
-  lists.delete_if {|list| seen[list] < 1 and not whitelist.include? list}
-  lists.delete_if {|list| list =~ /-private$/}
-  lists += ['board'] if ASF.pmc_chairs.include? user
-end
+lists = ASF::Mail.cansub(user.asf_member?, ASF.pmc_chairs.include?(user))
 
 lists.sort!
 
+
 addrs = (["#{$USER}@apache.org"] + user.mail + user.alt_email)
 
 _html do
@@ -117,11 +96,16 @@ _html do
         _select name: 'list' do
           seen = Hash.new
           lists.each do |list|
+            ln = list.split('-').first
+            ln = 'empire-db' if ln == 'empire'
             seen[list] = 0
-            seen[list] = 1 if pmcs.include? list.split('-').first
-            seen[list] = 2 if Podlings.list.include? list.split('-').first
-            seen[list] = 2 if (list.split('-').first == 'incubator') \
-                              && (Podlings.list.include? list.split('-')[1])
+            seen[list] = 1 if pmcs.include? ln
+            seen[list] = 2 if current.include? ln
+            seen[list] = 2 if (ln == 'incubator') \
+                              && (current.include? list.split('-')[1])
+            seen[list] = 3 if retired.include? ln
+            seen[list] = 3 if (ln == 'incubator') \
+                      && (retired.include? list.split('-')[1])
           end
           _option '--- Foundation lists ---', disabled: 'disabled'
           lists.find_all { |list| seen[list] == 0 }.each do |list|

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

Mime
View raw message