Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2570)

Unified Diff: dashboard/dashboard/create_health_report.py

Issue 2622303003: Allows a user to create_health_reports. (Closed)
Patch Set: updated a test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dashboard/dashboard/create_health_report_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/dashboard/create_health_report.py
diff --git a/dashboard/dashboard/create_health_report.py b/dashboard/dashboard/create_health_report.py
new file mode 100644
index 0000000000000000000000000000000000000000..4a1b175b61aef7650c671a88c7126be3519d5cdf
--- /dev/null
+++ b/dashboard/dashboard/create_health_report.py
@@ -0,0 +1,78 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Provides the web interface for adding and editing sheriff rotations."""
+
+import json
+
+from google.appengine.api import users
+
+from dashboard.common import request_handler
+from dashboard.common import utils
+from dashboard.common import xsrf
+from dashboard.models import table_config
+
+
+class CreateHealthReportHandler(request_handler.RequestHandler):
+
+ def get(self):
+ """Renders the UI with the form fields."""
+ self.RenderStaticHtml('create_health_report.html')
+
+ def post(self):
+ """POSTS the data to the datastore."""
+
+ user = users.get_current_user()
+ if not user:
+ self.response.out.write(json.dumps({'error': 'User not logged in.'}))
+ return
+ if not utils.IsInternalUser():
+ self.response.out.write(json.dumps(
+ {'error':
+ 'Unauthorized access, please use chromium account to login.'}))
+ return
+
+ get_token = self.request.get('getToken')
+ if get_token == 'true':
+ values = {}
+ self.GetDynamicVariables(values)
+ self.response.out.write(json.dumps({
+ 'xsrf_token': values['xsrf_token'],
+ }))
+ else:
+ self._CreateTableConfig()
+
+
+ def _CreateTableConfig(self):
+ """Creates a table config. Writes a valid name or an error message."""
+ self._ValidateToken()
+ name = self.request.get('tableName')
+ master_bot = self.request.get('tableBots').splitlines()
+ tests = self.request.get('tableTests').splitlines()
+ table_layout = self.request.get('tableLayout')
+ user = users.get_current_user()
+ if not name or not master_bot or not tests or not table_layout or not user:
+ self.response.out.write(json.dumps({
+ 'error': 'Please fill out the form entirely.'
+ }))
+ return
+
+ created_table, msg = table_config.CreateTableConfig(
+ name=name, bots=master_bot, tests=tests, layout=table_layout,
+ username=user.email())
+
+ if created_table:
+ self.response.out.write(json.dumps({
+ 'name': name,
+ }))
+ else:
+ self.response.out.write(json.dumps({
+ 'error': msg,
+ }))
+
+ def _ValidateToken(self):
+ user = users.get_current_user()
+ token = str(self.request.get('xsrf_token'))
+ if not user or not xsrf._ValidateToken(token, user):
+ self.abort(403)
« no previous file with comments | « no previous file | dashboard/dashboard/create_health_report_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698