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: enable realtime updates of reporter drafts
Date Mon, 12 Aug 2019 00:13:41 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 d634919  enable realtime updates of reporter drafts
d634919 is described below

commit d634919a22abe6083a39c33f953fea5dc4a87d69
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sun Aug 11 20:13:23 2019 -0400

    enable realtime updates of reporter drafts
---
 www/board/agenda/config.ru                      |  3 +++
 www/board/agenda/models/reporter.rb             | 34 ++++++++++++++++++-------
 www/board/agenda/views/actions/reporter.json.rb | 19 ++++++++++----
 www/board/agenda/views/models/reporter.js.rb    |  2 +-
 4 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/www/board/agenda/config.ru b/www/board/agenda/config.ru
index 63572aa..56cd74f 100644
--- a/www/board/agenda/config.ru
+++ b/www/board/agenda/config.ru
@@ -22,9 +22,12 @@ use ASF::Auth::MembersAndOfficers do |env|
   #   non-officers.
   # - post is limited to ASF members, officers, and members of the PMC whose
   #   report is being posted.
+  # - reporter can be used with both HTTP GET and POST.  GET is filtered
+  #   like historical-commits, and POST is limited like post.
   # - calendar is available to all committers
   next true if env['PATH_INFO'] == '/json/historical-comments'
   next true if env['PATH_INFO'] == '/json/post'
+  next true if env['PATH_INFO'] == '/json/reporter'
   next true if env['PATH_INFO'] == '/latest.json'
   next true if env['PATH_INFO'] == '/calendar.json'
 
diff --git a/www/board/agenda/models/reporter.rb b/www/board/agenda/models/reporter.rb
index 23b6621..6ef647e 100644
--- a/www/board/agenda/models/reporter.rb
+++ b/www/board/agenda/models/reporter.rb
@@ -9,7 +9,7 @@
 class Reporter
   @@partial = true
 
-  def self.drafts(env)
+  def self.drafts(env, update=nil)
     changed = false
 
     agenda_file = File.basename(
@@ -22,13 +22,20 @@ class Reporter
 
     cache = File.join(ASF::Config.get(:cache), 'reporter-drafts.json')
 
-    # if cache is older than a minute, fetch new data
-    if not File.exist? cache or File.mtime(cache) < Time.now - 60 or @@partial
-      # read and prune previous status.  May be used to "fill in the blanks"
-      # should a partial set of reports be received
-      report_status = (JSON.parse(File.read(cache)) rescue {}).
-        select {|project, status| status['agenda'] == agenda_file}.to_h
+    # read and prune previous status.  May be used to "fill in the blanks"
+    # should a partial set of reports be received
+    report_status = (JSON.parse(File.read(cache)) rescue {}).
+      select {|project, status| status['agenda'] == agenda_file}.to_h
+
+    # file updates as they are received
+    if update
 
+      report_status.merge! update
+      File.write cache, report_status.to_json
+      changed = true
+
+    # if cache is older than a minute, fetch new data
+    elsif not File.exist? cache or File.mtime(cache) < Time.now-60 or @@partial
       # source of truth
       uri = URI.parse('https://reporter.apache.org/api/drafts/forgotten')
 
@@ -50,7 +57,7 @@ class Reporter
     end
 
     # extract projects with drafts for this agenda
-    drafts = JSON.parse(File.read(cache)).select do |project, status| 
+    drafts = report_status.select do |project, status| 
       next false unless status['agenda'] == agenda_file
       last_draft = status['last_draft']
       last_draft and not last_draft.empty?
@@ -70,7 +77,16 @@ class Reporter
     }
 
     if changed
-      Events.post 'reporter', report_status
+      Events.post type: 'reporter', status: results
+    end
+
+    # filter drafts based on user visibility
+    user = env.respond_to?(:user) && ASF::Person.find(env.user)
+    unless !user or user.asf_member? or ASF.pmc_chairs.include? user
+      projects = user.committees.map(&:name)
+      results[:drafts].keep_if do |attach, draft| 
+        projects.include? draft[:project]
+      end
     end
 
     results
diff --git a/www/board/agenda/views/actions/reporter.json.rb b/www/board/agenda/views/actions/reporter.json.rb
index 7d4eaff..e7f7c63 100644
--- a/www/board/agenda/views/actions/reporter.json.rb
+++ b/www/board/agenda/views/actions/reporter.json.rb
@@ -1,6 +1,15 @@
-# find the latest agenda
-agenda_file = Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last.untaint
-agenda = Agenda.parse File.basename(agenda_file), :quick
-
-agenda
+# ASF members and PMC chairs can post anything, everybody else can only post
+# to updates for the PMCs that they belong to.
+user = env.respond_to?(:user) && ASF::Person.find(env.user)
+unless !user or user.asf_member? or ASF.pmc_chairs.include? user
+  projects = user.committees.map(&:name)
+  @report_status.each do |project, status|
+    unless projects.include? project
+      status 403 # Forbidden
+      return "Not authorized to post #{project}"
+    end
+  end
+end
 
+# apply the updates
+Reporter.drafts env, @report_status
diff --git a/www/board/agenda/views/models/reporter.js.rb b/www/board/agenda/views/models/reporter.js.rb
index bdc76c9..057b149 100644
--- a/www/board/agenda/views/models/reporter.js.rb
+++ b/www/board/agenda/views/models/reporter.js.rb
@@ -28,5 +28,5 @@ class Reporter
 end
 
 Events.subscribe :reporter do |message|
-  Reporter.load(message)
+  Reporter.load(message.status)
 end


Mime
View raw message