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

Side by Side 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: Address comments. Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(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')
stgao 2016/07/09 01:20:52 should we change the param name in the request too
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}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698