diff options
author | Byron Jones <bjones@mozilla.com> | 2013-12-05 18:57:01 +0100 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2013-12-05 18:57:01 +0100 |
commit | 1e95357d5127c40acc4bf6e7ed10739f30c6ca95 (patch) | |
tree | 4957247cdaf95a7923b6eaf2db3c0b0433add915 | |
parent | 8ba55d70d8d4e652037939bb9be52e22ce44992d (diff) | |
download | bugzilla-1e95357d5127c40acc4bf6e7ed10739f30c6ca95.tar.gz bugzilla-1e95357d5127c40acc4bf6e7ed10739f30c6ca95.tar.xz |
Bug 922226: redirect when attachments contain reviewboard URLs
-rw-r--r-- | extensions/BMO/Extension.pm | 20 | ||||
-rw-r--r-- | extensions/BMO/lib/Data.pm | 6 | ||||
-rw-r--r-- | template/en/default/attachment/edit.html.tmpl | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 58813cfc6..2235ebfea 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -595,8 +595,8 @@ sub attachment_process_data { my ($self, $args) = @_; my $attributes = $args->{attributes}; - # quick checks - must be a text/plain non-patch - return if $attributes->{ispatch} || $attributes->{mimetype} ne 'text/plain'; + # must be a text attachment + return unless $attributes->{mimetype} eq 'text/plain'; # check the attachment size, and get attachment content if it isn't too large my $data = $attributes->{data}; @@ -614,12 +614,18 @@ sub attachment_process_data { } # trim and check for the pull request url + return unless defined $url; $url = trim($url); return if $url =~ /\s/; - return unless $url =~ m#^https://github\.com/[^/]+/[^/]+/pull/\d+\/?$#i; - # must be a valid pull-request - $attributes->{mimetype} = GITHUB_PR_CONTENT_TYPE; + if ($url =~ m#^https://github\.com/[^/]+/[^/]+/pull/\d+/?$#i) { + $attributes->{mimetype} = GITHUB_PR_CONTENT_TYPE; + $attributes->{ispatch} = 0; + } + elsif ($url =~ m#^https://reviewboard(?:-dev)?\.allizom\.org/r/\d+/?#i) { + $attributes->{mimetype} = RB_REQUEST_CONTENT_TYPE; + $attributes->{ispatch} = 0; + } } # redirect automatically to github urls @@ -632,7 +638,9 @@ sub attachment_view { return if defined $cgi->param('content_type'); # must be our github content-type - return unless $attachment->contenttype eq GITHUB_PR_CONTENT_TYPE; + return unless + $attachment->contenttype eq GITHUB_PR_CONTENT_TYPE + or $attachment->contenttype eq RB_REQUEST_CONTENT_TYPE; # redirect print $cgi->redirect(trim($attachment->data)); diff --git a/extensions/BMO/lib/Data.pm b/extensions/BMO/lib/Data.pm index cf62b9acf..c4da9c29c 100644 --- a/extensions/BMO/lib/Data.pm +++ b/extensions/BMO/lib/Data.pm @@ -42,9 +42,11 @@ our @EXPORT = qw( $cf_visible_in_products %product_sec_groups %create_bug_formats @default_named_queries - GITHUB_PR_CONTENT_TYPE ); + GITHUB_PR_CONTENT_TYPE + RB_REQUEST_CONTENT_TYPE ); -use constant GITHUB_PR_CONTENT_TYPE => 'text/x-github-pull-request'; +use constant GITHUB_PR_CONTENT_TYPE => 'text/x-github-pull-request'; +use constant RB_REQUEST_CONTENT_TYPE => 'text/x-review-board-request'; # Which custom fields are visible in which products and components. # diff --git a/template/en/default/attachment/edit.html.tmpl b/template/en/default/attachment/edit.html.tmpl index cbc66e95a..85dabbcb7 100644 --- a/template/en/default/attachment/edit.html.tmpl +++ b/template/en/default/attachment/edit.html.tmpl @@ -209,7 +209,7 @@ %] [% ELSE %] <iframe id="viewFrame" src="attachment.cgi?id=[% attachment.id %] - [%- "&content_type=text/plain" IF attachment.contenttype == 'text/x-github-pull-request' %]"> + [%- "&content_type=text/plain" IF attachment.contenttype.match('^text/x-') %]"> <b>You cannot view the attachment while viewing its details because your browser does not support IFRAMEs. <a href="attachment.cgi?id=[% attachment.id %]">View the attachment on a separate page</a>.</b> </iframe> |