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

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

Issue 2074273002: [Findit] Add feedback button for manual triage. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@show-result
Patch Set: 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
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..89e5af15d52fe03375eb38d3dffc3e9ea06edecf
--- /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):
stgao 2016/06/30 01:28:02 Var name `update` is not clear.
Sharu Jiang 2016/07/01 22:05:48 Changed to update_data.
+ analysis = key.get()
+ success = analysis.Update(update)
+
+ result_property = None
+ status = None
+ for key, value in update.iteritems():
+ if 'triage_status' in key:
stgao 2016/06/30 01:28:02 Will there be multiple 'triage_status'?
Sharu Jiang 2016/07/01 22:05:48 We only click one button at a time, so it will onl
+ 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': triage_status.TRIAGE_STATUS_TO_DESCRIPTION[status],
stgao 2016/06/30 01:28:02 I guess we won't change the description for a stat
Sharu Jiang 2016/07/01 22:05:48 Acknowledged.
+ }
+
+ 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
stgao 2016/06/30 01:28:02 This could be removed if the JS is a post.
Sharu Jiang 2016/07/01 22:05:48 Done.
+ 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}}

Powered by Google App Engine
This is Rietveld 408576698