| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """This module is to handle manual triage of fracas crash analysis result.""" |
| 6 |
| 7 import calendar |
| 8 from datetime import datetime |
| 9 import json |
| 10 |
| 11 from google.appengine.api import users |
| 12 from google.appengine.ext import ndb |
| 13 |
| 14 from common.base_handler import BaseHandler |
| 15 from common.base_handler import Permission |
| 16 from model import triage_status |
| 17 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 18 |
| 19 |
| 20 @ndb.transactional |
| 21 def _UpdateAnalysis(key, user_name, update_data): |
| 22 analysis = key.get() |
| 23 success = analysis.Update(update_data) |
| 24 |
| 25 result_property = None |
| 26 status = None |
| 27 for key, value in update_data.iteritems(): |
| 28 if 'triage_status' in key: |
| 29 result_property = key.replace('_triage_status', '') |
| 30 status = value |
| 31 break |
| 32 |
| 33 if not result_property: |
| 34 analysis.put() |
| 35 return success |
| 36 |
| 37 triage_record = { |
| 38 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()), |
| 39 'user_name': user_name, |
| 40 'result_property': result_property, |
| 41 'triage_status': triage_status.TRIAGE_STATUS_TO_DESCRIPTION[status], |
| 42 } |
| 43 |
| 44 if not analysis.triage_history: |
| 45 analysis.triage_history = [] |
| 46 |
| 47 analysis.triage_history.append(triage_record) |
| 48 |
| 49 analysis.put() |
| 50 return success |
| 51 |
| 52 |
| 53 class TriageFracasAnalysis(BaseHandler): |
| 54 PERMISSION_LEVEL = Permission.CORP_USER |
| 55 |
| 56 def HandlePost(self): |
| 57 """Sets the manual triage result for fracas analysis.""" |
| 58 key = ndb.Key(urlsafe=self.request.get('key')) |
| 59 update_data = self.request.params.get('update-data') |
| 60 if not update_data: |
| 61 return {'data': {'success': False}} |
| 62 |
| 63 update_data = json.loads(update_data) |
| 64 # As the permission level is CORP_USER, we could assume the current user |
| 65 # already logged in. |
| 66 user_name = users.get_current_user().email().split('@')[0] |
| 67 success = _UpdateAnalysis(key, user_name, update_data) |
| 68 |
| 69 return {'data': {'success': success}} |
| OLD | NEW |