| 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}}
|
|
|