OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """This file handles serving the list of committers to users.""" |
| 6 |
| 7 __author__ = 'agable@google.com (Aaron Gable)' |
| 8 |
| 9 |
| 10 import webapp2 |
| 11 |
| 12 from google.appengine.api import users |
| 13 from google.appengine.ext import ndb |
| 14 |
| 15 import auth_util |
| 16 import constants |
| 17 import model |
| 18 |
| 19 |
| 20 class ChromiumHandler(webapp2.RequestHandler): |
| 21 |
| 22 @staticmethod |
| 23 def _can_see_list(user, committer_list): |
| 24 """Returns True if the user is allowed to see the list.""" |
| 25 if not user: |
| 26 return False |
| 27 if users.is_current_user_admin(): |
| 28 return True |
| 29 email = user.email() |
| 30 if email in committer_list: |
| 31 return True |
| 32 if (email.endswith('@google.com') and |
| 33 email[:-11] + '@chromium.org' in committer_list): |
| 34 return True |
| 35 return False |
| 36 |
| 37 def get(self): |
| 38 """Displays the list of chromium committers in plain text.""" |
| 39 self.response.headers['Content-Type'] = 'text/plain' |
| 40 |
| 41 committer_list = ndb.Key(model.EmailList, constants.LIST).get() |
| 42 emails = committer_list.emails if committer_list else [] |
| 43 |
| 44 authenticated = False |
| 45 try: |
| 46 auth_util.CheckRequest(self.request) |
| 47 authenticated = True |
| 48 except: |
| 49 user = users.get_current_user() |
| 50 authenticated = self._can_see_list(user, emails) |
| 51 |
| 52 if authenticated: |
| 53 self.response.write('\n'.join(sorted(emails))) |
| 54 else: |
| 55 self.response.status = 403 |
| 56 self.response.write('403: Forbidden') |
| 57 |
| 58 |
| 59 class MappingHandler(webapp2.RequestHandler): |
| 60 |
| 61 def get(self): |
| 62 """Displays the mapping of chromium to googler email addresses.""" |
| 63 self.response.headers['Content-Type'] = 'text/plain' |
| 64 self.response.out.write('Not yet implemented. Sorry!') |
| 65 |
| 66 |
| 67 class UpdateHandler(webapp2.RequestHandler): |
| 68 def post(self): |
| 69 """Updates the list of committers from the POST data recieved.""" |
| 70 auth_util.CheckRequest(self.request) |
| 71 emails = request.get('committers') |
| 72 committer_list = model.EmailList(id=constants.LIST, emails=emails) |
| 73 committer_list.put() |
| 74 |
| 75 |
| 76 app = webapp2.WSGIApplication([ |
| 77 ('/chromium', ChromiumHandler), |
| 78 ('/mapping', MappingHandler), |
| 79 ('/update', UpdateHandler), |
| 80 ], debug=True) |
OLD | NEW |