Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Disallow posting to confidential bugs.
Browse files Browse the repository at this point in the history
Remove [RB] prefix from attachment summary. Use x-review-board-request
MIME type to identify RB attachments. Include review request description
as comment when posting attachment.
  • Loading branch information
Mark Côté committed May 6, 2014
1 parent 8bddc4c commit 5573294
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
14 changes: 7 additions & 7 deletions rbbz/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from rbbz.transports import bugzilla_transport


ATTACHMENT_SUMMARY_PREFIX = '[RB] '

@simple_decorator
def xmlrpc_to_bugzilla_errors(func):
def _transform_errors(*args, **kwargs):
Expand Down Expand Up @@ -112,12 +110,14 @@ def is_bug_confidential(self, bug_id):
return bool(groups)

@xmlrpc_to_bugzilla_errors
def post_rb_url(self, summary, bug_id, url, reviewer):
def post_rb_url(self, bug_id, review_id, summary, description, url,
reviewer):
params = {
'ids': [bug_id],
'data': url,
'file_name': summary,
'summary': '%s%s' % (ATTACHMENT_SUMMARY_PREFIX, summary),
'file_name': 'reviewboard-%d.url' % review_id,
'summary': summary,
'comment': description,
'content_type': 'text/plain',
'flags': [{'name': 'review',
'status': '?',
Expand All @@ -130,14 +130,14 @@ def get_rb_attachments(self, bug_id):
rb_attachments = []
params = {
'ids': [bug_id],
'include_fields': ['id', 'data', 'summary', 'is_obsolete',
'include_fields': ['id', 'data', 'content_type', 'is_obsolete',
'flags']
}
attachments = self.proxy.Bug.attachments(params)

for a in attachments['bugs'][str(bug_id)]:
if (a['is_obsolete']
or not a['summary'].startswith(ATTACHMENT_SUMMARY_PREFIX)
or a['content_type'] != 'text/x-review-board-request'
or not a['flags']):
continue

Expand Down
6 changes: 6 additions & 0 deletions rbbz/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def __init__(self):
'given in the "People" field.')


class ConfidentialBugError(PublishError):
def __init__(self):
PublishError.__init__(self, 'This bug is confidential; please attach '
'the patch directly to the bug.')


#
# Bugzilla errors.
#
Expand Down
15 changes: 11 additions & 4 deletions rbbz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from reviewboard.site.urlresolvers import local_site_reverse

from rbbz.bugzilla import Bugzilla
from rbbz.errors import (BugzillaError, InvalidBugsError, InvalidBugIdError,
InvalidReviewersError)
from rbbz.errors import (BugzillaError, ConfidentialBugError, InvalidBugsError,
InvalidBugIdError, InvalidReviewersError)

def review_request_url(review_request, site=None, siteconfig=None):
if not site:
Expand Down Expand Up @@ -50,15 +50,22 @@ def publish_review_request(user, review_request_draft, **kwargs):
except (TypeError, ValueError):
raise InvalidBugIdError(bugs[0])

b = Bugzilla(user.bzlogin, user.bzcookie)

if b.is_bug_confidential(bug_id):
raise ConfidentialBugError

reviewers = review_request_draft.target_people
num_reviewers = reviewers.count()

if num_reviewers == 0 or num_reviewers > 1:
raise InvalidReviewersError

reviewer = reviewers.first()
b = Bugzilla(user.bzlogin, user.bzcookie)
b.post_rb_url(review_request_draft.summary, bug_id,
b.post_rb_url(bug_id,
review_request_draft.get_review_request().id,
review_request_draft.summary,
review_request_draft.description,
review_request_url(review_request_draft.get_review_request()),
reviewer.get_username())

Expand Down

0 comments on commit 5573294

Please sign in to comment.