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

Unified Diff: appengine/findit/handlers/crash/triage_fracas_analysis.py

Issue 2067373002: [Findit] Add fracas analysis result feedback page for manual triage. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@only-dashboard
Patch Set: Merge branch 'only-dashboard' into dashboard Created 4 years, 6 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 | « appengine/findit/handlers/crash/test/triage_fracas_analysis_test.py ('k') | appengine/findit/main.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/handlers/crash/triage_fracas_analysis.py
diff --git a/appengine/findit/handlers/crash/triage_fracas_analysis.py b/appengine/findit/handlers/crash/triage_fracas_analysis.py
new file mode 100644
index 0000000000000000000000000000000000000000..ff17dd6e573e1fae0d8abda258d1c2215c661f01
--- /dev/null
+++ b/appengine/findit/handlers/crash/triage_fracas_analysis.py
@@ -0,0 +1,72 @@
+# Copyright 2016 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.
+
+"""This module is to handle manual triage of fracas crash analysis result."""
+
+import calendar
+from datetime import datetime
+import json
+
+from google.appengine.api import users
+from google.appengine.ext import ndb
+
+from common.base_handler import BaseHandler
+from common.base_handler import Permission
+from model import triage_status
+from model.crash.fracas_crash_analysis import FracasCrashAnalysis
+
+
+@ndb.transactional
+def _UpdateAnalysis(key, user_name, update):
+ analysis = key.get()
+ success = analysis.Update(update)
+
+ result_property = None
+ status = None
+ for key, value in update.iteritems():
+ if 'triage_status' in key:
+ result_property = key.replace('_triage_status', '')
+ status = value
+ break
+
+ if not result_property:
+ analysis.put()
+ return success
+
+ triage_record = {
+ 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()),
+ 'user_name': user_name,
+ 'result_property': result_property,
+ 'triage_status': status,
+ }
+
+ if not analysis.triage_history:
+ analysis.triage_history = []
+
+ analysis.triage_history.append(triage_record)
+
+ analysis.put()
+ return success
+
+
+class TriageFracasAnalysis(BaseHandler):
+ PERMISSION_LEVEL = Permission.CORP_USER
+
+ def HandleGet(self): # pragma: no cover
+ return self.HandlePost()
+
+ def HandlePost(self):
+ """Sets the manual triage result for fracas analysis."""
+ key = ndb.Key(urlsafe=self.request.get('key'))
+ update = self.request.get('update')
+ if not update:
+ return {'data': {'success': False}}
+
+ update = json.loads(update)
+ # As the permission level is CORP_USER, we could assume the current user
+ # already logged in.
+ user_name = users.get_current_user().email().split('@')[0]
+ success = _UpdateAnalysis(key, user_name, update)
+
+ return {'data': {'success': success}}
« no previous file with comments | « appengine/findit/handlers/crash/test/triage_fracas_analysis_test.py ('k') | appengine/findit/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698