Chromium Code Reviews| 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..f462bbfdf0de3b0c99d4f307aa19a2564a70ba10 |
| --- /dev/null |
| +++ b/appengine/findit/handlers/crash/triage_fracas_analysis.py |
| @@ -0,0 +1,69 @@ |
| +# 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_data): |
| + analysis = key.get() |
| + success = analysis.Update(update_data) |
| + |
| + result_property = None |
| + status = None |
| + for key, value in update_data.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': triage_status.TRIAGE_STATUS_TO_DESCRIPTION[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 HandlePost(self): |
| + """Sets the manual triage result for fracas analysis.""" |
| + key = ndb.Key(urlsafe=self.request.get('key')) |
| + update_data = self.request.params.get('update') |
|
stgao
2016/07/09 01:20:52
should we change the param name in the request too
|
| + if not update_data: |
| + return {'data': {'success': False}} |
| + |
| + update_data = json.loads(update_data) |
| + # 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_data) |
| + |
| + return {'data': {'success': success}} |