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 base64 |
| 11 import json |
| 12 import os |
| 13 |
| 14 import jinja2 |
| 15 import webapp2 |
| 16 |
| 17 from google.appengine.api import users |
| 18 from google.appengine.ext import ndb |
| 19 |
| 20 import auth_util |
| 21 import constants |
| 22 import hmac_util |
| 23 import model |
| 24 |
| 25 |
| 26 TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), 'templates') |
| 27 JINJA2_ENVIRONMENT = jinja2.Environment( |
| 28 loader=jinja2.FileSystemLoader(TEMPLATES_PATH), |
| 29 autoescape=True, |
| 30 extensions=['jinja2.ext.autoescape']) |
| 31 |
| 32 |
| 33 class MainPageHandler(webapp2.RequestHandler): |
| 34 |
| 35 def get(self): |
| 36 """Displays the homepage, with a login url.""" |
| 37 template = JINJA2_ENVIRONMENT.get_template('index.html') |
| 38 template_values = {'login_url': users.create_login_url(dest_url='/')} |
| 39 page = template.render(template_values) |
| 40 self.response.write(page) |
| 41 |
| 42 |
| 43 class ChromiumHandler(webapp2.RequestHandler): |
| 44 |
| 45 @auth_util.CheckUserAuth |
| 46 @hmac_util.CheckHmacAuth |
| 47 @auth_util.RequireAuth |
| 48 def get(self): |
| 49 """Displays the list of chromium committers in plain text.""" |
| 50 committer_list = ndb.Key(model.EmailList, constants.LIST).get() |
| 51 emails = committer_list.emails if committer_list else [] |
| 52 self.response.headers['Content-Type'] = 'text/plain' |
| 53 self.response.write('\n'.join(sorted(emails))) |
| 54 |
| 55 |
| 56 class MappingHandler(webapp2.RequestHandler): |
| 57 |
| 58 def get(self): |
| 59 """Displays the mapping of chromium to googler email addresses.""" |
| 60 self.response.headers['Content-Type'] = 'text/plain' |
| 61 self.response.out.write('Not yet implemented. Sorry!') |
| 62 |
| 63 |
| 64 class UpdateHandler(webapp2.RequestHandler): |
| 65 |
| 66 @hmac_util.CheckHmacAuth |
| 67 @auth_util.RequireAuth |
| 68 def post(self): |
| 69 """Updates the list of committers from the POST data recieved.""" |
| 70 emails = base64.b64decode(self.request.get('committers')) |
| 71 email_list = json.loads(emails) |
| 72 committer_list = model.EmailList(id=constants.LIST, emails=email_list) |
| 73 committer_list.put() |
| 74 |
| 75 |
| 76 app = webapp2.WSGIApplication([ |
| 77 ('/', MainPageHandler), |
| 78 ('/chromium', ChromiumHandler), |
| 79 ('/mapping', MappingHandler), |
| 80 ('/update', UpdateHandler), |
| 81 ], debug=True) |
OLD | NEW |