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

Side by Side Diff: appengine/monorail/tracker/issueoriginal.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 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
« no previous file with comments | « appengine/monorail/tracker/issueoptions.py ('k') | appengine/monorail/tracker/issuepeek.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """Servlet to show the original email that caused an issue comment.
7
8 The text of the body the email is shown in an HTML page with <pre>.
9 All the text is automatically escaped by EZT to make it safe to
10 include in an HTML page.
11 """
12
13 import logging
14 from third_party import ezt
15
16 from framework import filecontent
17 from framework import permissions
18 from framework import servlet
19 from services import issue_svc
20
21
22 class IssueOriginal(servlet.Servlet):
23 """IssueOriginal shows an inbound email that caused an issue comment."""
24
25 _PAGE_TEMPLATE = 'tracker/issue-original-page.ezt'
26
27 def AssertBasePermission(self, mr):
28 """Make sure that the logged in user has permission to view this page."""
29 super(IssueOriginal, self).AssertBasePermission(mr)
30 issue, comment = self._GetIssueAndComment(mr)
31
32 # TODO(jrobbins): take granted perms into account here.
33 if issue and not permissions.CanViewIssue(
34 mr.auth.effective_ids, mr.perms, mr.project, issue,
35 allow_viewing_deleted=True):
36 raise permissions.PermissionException(
37 'User is not allowed to view this issue')
38
39 can_view_inbound_message = self.CheckPerm(
40 mr, permissions.VIEW_INBOUND_MESSAGES, art=issue)
41 can_delete = permissions.CanDelete(
42 mr.auth.user_id, mr.auth.effective_ids, mr.perms,
43 comment.deleted_by, comment.user_id,
44 mr.project, permissions.GetRestrictions(issue))
45 if not can_view_inbound_message and not can_delete:
46 raise permissions.PermissionException(
47 'Only project members may view original email text')
48
49 def GatherPageData(self, mr):
50 """Build up a dictionary of data values to use when rendering the page.
51
52 Args:
53 mr: commonly used info parsed from the request.
54
55 Returns:
56 Dict of values used by EZT for rendering the page.
57 """
58 issue, comment = self._GetIssueAndComment(mr)
59 message_body_unicode, is_binary, _is_long = (
60 filecontent.DecodeFileContents(comment.inbound_message))
61
62 # Take out the iso8859-1 non-breaking-space characters that gmail
63 # inserts between consecutive spaces when quoting text in a reply.
64 # You can see this in gmail by sending a plain text reply to a
65 # message that had multiple spaces on some line, then use the
66 # "Show original" menu item to view your reply, you will see "=A0".
67 #message_body_unicode = message_body_unicode.replace(u'\xa0', u' ')
68
69 page_data = {
70 'local_id': issue.local_id,
71 'seq': comment.sequence,
72 'is_binary': ezt.boolean(is_binary),
73 'message_body': message_body_unicode,
74 }
75
76 return page_data
77
78 def _GetIssueAndComment(self, mr):
79 """Wait on retriving the specified issue and issue comment."""
80 if mr.local_id is None or mr.seq is None:
81 self.abort(404, 'issue or comment not specified')
82
83 try:
84 issue = self.services.issue.GetIssueByLocalID(
85 mr.cnxn, mr.project_id, mr.local_id)
86 except issue_svc.NoSuchIssueException:
87 self.abort(404, 'issue not found')
88
89 comments = self.services.issue.GetCommentsForIssue(
90 mr.cnxn, issue.issue_id)
91
92 try:
93 comment = comments[mr.seq]
94 except IndexError:
95 self.abort(404, 'comment not found')
96
97 return issue, comment
OLDNEW
« no previous file with comments | « appengine/monorail/tracker/issueoptions.py ('k') | appengine/monorail/tracker/issuepeek.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698