summaryrefslogtreecommitdiffstats
path: root/extensions/Splinter
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/Splinter')
-rw-r--r--extensions/Splinter/Extension.pm217
-rw-r--r--extensions/Splinter/lib/Config.pm14
-rw-r--r--extensions/Splinter/lib/Util.pm208
3 files changed, 226 insertions, 213 deletions
diff --git a/extensions/Splinter/Extension.pm b/extensions/Splinter/Extension.pm
index eb2006f47..f5a2f41cb 100644
--- a/extensions/Splinter/Extension.pm
+++ b/extensions/Splinter/Extension.pm
@@ -28,135 +28,140 @@ use Bugzilla::Extension::Splinter::Util;
our $VERSION = '0.1';
BEGIN {
- *Bugzilla::splinter_review_base = \&get_review_base;
- *Bugzilla::splinter_review_url = \&_get_review_url;
+ *Bugzilla::splinter_review_base = \&get_review_base;
+ *Bugzilla::splinter_review_url = \&_get_review_url;
}
sub _get_review_url {
- my ($class, $bug_id, $attach_id) = @_;
- return get_review_url(Bugzilla::Bug->check({ id => $bug_id, cache => 1 }), $attach_id);
+ my ($class, $bug_id, $attach_id) = @_;
+ return get_review_url(Bugzilla::Bug->check({id => $bug_id, cache => 1}),
+ $attach_id);
}
sub page_before_template {
- my ($self, $args) = @_;
- my ($vars, $page) = @$args{qw(vars page_id)};
-
- if ($page eq 'splinter.html') {
- my $user = Bugzilla->user;
-
- # We can either provide just a bug id to see a list
- # of prior reviews by the user, or just an attachment
- # id to go directly to a review page for the attachment.
- # If both are give they will be checked later to make
- # sure they are connected.
-
- my $input = Bugzilla->input_params;
- if ($input->{'bug'}) {
- $vars->{'bug_id'} = $input->{'bug'};
- $vars->{'attach_id'} = $input->{'attachment'};
- $vars->{'bug'} = Bugzilla::Bug->check({ id => $input->{'bug'}, cache => 1 });
- }
-
- if ($input->{'attachment'}) {
- my $attachment = Bugzilla::Attachment->check({ id => $input->{'attachment'} });
-
- # Check to see if the user can see the bug this attachment is connected to.
- Bugzilla::Bug->check($attachment->bug_id);
- if ($attachment->isprivate
- && $user->id != $attachment->attacher->id
- && !$user->is_insider)
- {
- ThrowUserError('auth_failure', {action => 'access',
- object => 'attachment'});
- }
-
- # If the user provided both a bug id and an attachment id, they must
- # be connected to each other
- if ($input->{'bug'} && $input->{'bug'} != $attachment->bug_id) {
- ThrowUserError('bug_attach_id_mismatch');
- }
-
- # The patch is going to be displayed in a HTML page and if the utf8
- # param is enabled, we have to encode attachment data as utf8.
- if (Bugzilla->params->{'utf8'}) {
- $attachment->data; # load data
- utf8::decode($attachment->{data});
- }
-
- $vars->{'attach_id'} = $attachment->id;
- if ($user->id && $attachment->contenttype eq "text/x-github-pull-request" && $attachment->can_review) {
- $vars->{'attach_data'} = $attachment->fetch_github_pr_diff;
- }
- else {
- $vars->{'attach_data'} = $attachment->data;
- }
- $vars->{'attach_is_crlf'} = $vars->{'attach_data'} =~ /\012\015/ ? 1 : 0;
- }
-
- my $field_object = new Bugzilla::Field({ name => 'attachments.status' });
- my $statuses;
- if ($field_object) {
- $statuses = [map { $_->name } @{ $field_object->legal_values }];
- } else {
- $statuses = [];
- }
- $vars->{'attachment_statuses'} = $statuses;
+ my ($self, $args) = @_;
+ my ($vars, $page) = @$args{qw(vars page_id)};
+
+ if ($page eq 'splinter.html') {
+ my $user = Bugzilla->user;
+
+ # We can either provide just a bug id to see a list
+ # of prior reviews by the user, or just an attachment
+ # id to go directly to a review page for the attachment.
+ # If both are give they will be checked later to make
+ # sure they are connected.
+
+ my $input = Bugzilla->input_params;
+ if ($input->{'bug'}) {
+ $vars->{'bug_id'} = $input->{'bug'};
+ $vars->{'attach_id'} = $input->{'attachment'};
+ $vars->{'bug'} = Bugzilla::Bug->check({id => $input->{'bug'}, cache => 1});
}
+
+ if ($input->{'attachment'}) {
+ my $attachment = Bugzilla::Attachment->check({id => $input->{'attachment'}});
+
+ # Check to see if the user can see the bug this attachment is connected to.
+ Bugzilla::Bug->check($attachment->bug_id);
+ if ( $attachment->isprivate
+ && $user->id != $attachment->attacher->id
+ && !$user->is_insider)
+ {
+ ThrowUserError('auth_failure', {action => 'access', object => 'attachment'});
+ }
+
+ # If the user provided both a bug id and an attachment id, they must
+ # be connected to each other
+ if ($input->{'bug'} && $input->{'bug'} != $attachment->bug_id) {
+ ThrowUserError('bug_attach_id_mismatch');
+ }
+
+ # The patch is going to be displayed in a HTML page and if the utf8
+ # param is enabled, we have to encode attachment data as utf8.
+ if (Bugzilla->params->{'utf8'}) {
+ $attachment->data; # load data
+ utf8::decode($attachment->{data});
+ }
+
+ $vars->{'attach_id'} = $attachment->id;
+ if ( $user->id
+ && $attachment->contenttype eq "text/x-github-pull-request"
+ && $attachment->can_review)
+ {
+ $vars->{'attach_data'} = $attachment->fetch_github_pr_diff;
+ }
+ else {
+ $vars->{'attach_data'} = $attachment->data;
+ }
+ $vars->{'attach_is_crlf'} = $vars->{'attach_data'} =~ /\012\015/ ? 1 : 0;
+ }
+
+ my $field_object = new Bugzilla::Field({name => 'attachments.status'});
+ my $statuses;
+ if ($field_object) {
+ $statuses = [map { $_->name } @{$field_object->legal_values}];
+ }
+ else {
+ $statuses = [];
+ }
+ $vars->{'attachment_statuses'} = $statuses;
+ }
}
sub bug_format_comment {
- my ($self, $args) = @_;
-
- my $bug = $args->{'bug'};
- my $regexes = $args->{'regexes'};
- my $text = $args->{'text'};
-
- # Add [review] link to the end of "Created attachment" comments
- #
- # We need to work around the way that the hook works, which is intended
- # to avoid overlapping matches, since we *want* an overlapping match
- # here (the normal handling of "Created attachment"), so we add in
- # dummy text and then replace in the regular expression we return from
- # the hook.
- $$text =~ s~((?:^Created\ |\b)attachment\s*\#?\s*(\d+)(\s\[details\])?)
+ my ($self, $args) = @_;
+
+ my $bug = $args->{'bug'};
+ my $regexes = $args->{'regexes'};
+ my $text = $args->{'text'};
+
+ # Add [review] link to the end of "Created attachment" comments
+ #
+ # We need to work around the way that the hook works, which is intended
+ # to avoid overlapping matches, since we *want* an overlapping match
+ # here (the normal handling of "Created attachment"), so we add in
+ # dummy text and then replace in the regular expression we return from
+ # the hook.
+ $$text =~ s~((?:^Created\ |\b)attachment\s*\#?\s*(\d+)(\s\[details\])?)
~(push(@$regexes, { match => qr/__REVIEW__$2/,
replace => get_review_link("$2", "[review]") })) &&
(attachment_id_is_patch($2) ? "$1 __REVIEW__$2" : $1)
~egmx;
- # And linkify "Review of attachment", this is less of a workaround since
- # there is no issue with overlap; note that there is an assumption that
- # there is only one match in the text we are linkifying, since they all
- # get the same link.
- my $REVIEW_RE = qr/Review\s+of\s+attachment\s+(\d+)\s*:/;
-
- if ($$text =~ $REVIEW_RE) {
- my $attach_id = $1;
- my $review_link = get_review_link($attach_id, "Review");
- my $attach_link = Bugzilla::Template::get_attachment_link($attach_id, "attachment $attach_id");
-
- push(@$regexes, { match => $REVIEW_RE,
- replace => "$review_link of $attach_link:"});
- }
+ # And linkify "Review of attachment", this is less of a workaround since
+ # there is no issue with overlap; note that there is an assumption that
+ # there is only one match in the text we are linkifying, since they all
+ # get the same link.
+ my $REVIEW_RE = qr/Review\s+of\s+attachment\s+(\d+)\s*:/;
+
+ if ($$text =~ $REVIEW_RE) {
+ my $attach_id = $1;
+ my $review_link = get_review_link($attach_id, "Review");
+ my $attach_link = Bugzilla::Template::get_attachment_link($attach_id,
+ "attachment $attach_id");
+
+ push(@$regexes,
+ {match => $REVIEW_RE, replace => "$review_link of $attach_link:"});
+ }
}
sub config_add_panels {
- my ($self, $args) = @_;
+ my ($self, $args) = @_;
- my $modules = $args->{panel_modules};
- $modules->{Splinter} = "Bugzilla::Extension::Splinter::Config";
+ my $modules = $args->{panel_modules};
+ $modules->{Splinter} = "Bugzilla::Extension::Splinter::Config";
}
sub mailer_before_send {
- my ($self, $args) = @_;
-
- # Post-process bug mail to add review links to bug mail.
- # It would be nice to be able to hook in earlier in the
- # process when the email body is being formatted in the
- # style of the bug-format_comment link for HTML but this
- # is the only hook available as of Bugzilla-3.4.
- add_review_links_to_email($args->{'email'});
+ my ($self, $args) = @_;
+
+ # Post-process bug mail to add review links to bug mail.
+ # It would be nice to be able to hook in earlier in the
+ # process when the email body is being formatted in the
+ # style of the bug-format_comment link for HTML but this
+ # is the only hook available as of Bugzilla-3.4.
+ add_review_links_to_email($args->{'email'});
}
__PACKAGE__->NAME;
diff --git a/extensions/Splinter/lib/Config.pm b/extensions/Splinter/lib/Config.pm
index fb3c16074..d3675c111 100644
--- a/extensions/Splinter/lib/Config.pm
+++ b/extensions/Splinter/lib/Config.pm
@@ -31,17 +31,13 @@ use Bugzilla::Config::Common;
our $sortkey = 1350;
sub get_param_list {
- my ($class) = @_;
+ my ($class) = @_;
- my @param_list = (
- {
- name => 'splinter_base',
- type => 't',
- default => 'page.cgi?id=splinter.html',
- },
- );
+ my @param_list = (
+ {name => 'splinter_base', type => 't', default => 'page.cgi?id=splinter.html',},
+ );
- return @param_list;
+ return @param_list;
}
1;
diff --git a/extensions/Splinter/lib/Util.pm b/extensions/Splinter/lib/Util.pm
index c85bb9b3b..0b7b2ff12 100644
--- a/extensions/Splinter/lib/Util.pm
+++ b/extensions/Splinter/lib/Util.pm
@@ -32,12 +32,12 @@ use Email::MIME::ContentType qw(parse_content_type);
use base qw(Exporter);
@Bugzilla::Extension::Splinter::Util::EXPORT = qw(
- attachment_is_visible
- attachment_id_is_patch
- get_review_base
- get_review_url
- get_review_link
- add_review_links_to_email
+ attachment_is_visible
+ attachment_id_is_patch
+ get_review_base
+ get_review_url
+ get_review_link
+ add_review_links_to_email
);
# Validates an attachment ID.
@@ -51,81 +51,95 @@ use base qw(Exporter);
# Returns an attachment object.
# Based on code from attachment.cgi
sub attachment_id_is_valid {
- my ($attach_id, $dont_validate_access) = @_;
+ my ($attach_id, $dont_validate_access) = @_;
- # Validate the specified attachment id.
- detaint_natural($attach_id) || return 0;
+ # Validate the specified attachment id.
+ detaint_natural($attach_id) || return 0;
- # Make sure the attachment exists in the database.
- my $attachment = new Bugzilla::Attachment({ id => $attach_id, cache => 1 })
- || return 0;
+ # Make sure the attachment exists in the database.
+ my $attachment
+ = new Bugzilla::Attachment({id => $attach_id, cache => 1}) || return 0;
- return $attachment
- if ($dont_validate_access || attachment_is_visible($attachment));
+ return $attachment
+ if ($dont_validate_access || attachment_is_visible($attachment));
}
# Checks if the current user can see an attachment
# Based on code from attachment.cgi
sub attachment_is_visible {
- my $attachment = shift;
+ my $attachment = shift;
- $attachment->isa('Bugzilla::Attachment') || return 0;
+ $attachment->isa('Bugzilla::Attachment') || return 0;
- return (Bugzilla->user->can_see_bug($attachment->bug->id)
- && (!$attachment->isprivate
- || Bugzilla->user->id == $attachment->attacher->id
- || Bugzilla->user->is_insider));
+ return (
+ Bugzilla->user->can_see_bug($attachment->bug->id)
+ && (!$attachment->isprivate
+ || Bugzilla->user->id == $attachment->attacher->id
+ || Bugzilla->user->is_insider)
+ );
}
sub attachment_id_is_patch {
- my $attach_id = shift;
- my $attachment = attachment_id_is_valid($attach_id);
- return ($attachment
- && ($attachment->ispatch
- || ($attachment->contenttype eq "text/x-github-pull-request" && $attachment->external_redirect)));
+ my $attach_id = shift;
+ my $attachment = attachment_id_is_valid($attach_id);
+ return (
+ $attachment
+ && (
+ $attachment->ispatch
+ || ( $attachment->contenttype eq "text/x-github-pull-request"
+ && $attachment->external_redirect)
+ )
+ );
}
sub get_review_base {
- my $base = Bugzilla->params->{'splinter_base'};
- $base =~ s!/$!!;
- my $urlbase = Bugzilla->localconfig->{urlbase};
- $urlbase =~ s!/$!! if $base =~ "^/";
- $base = $urlbase . $base;
- return $base;
+ my $base = Bugzilla->params->{'splinter_base'};
+ $base =~ s!/$!!;
+ my $urlbase = Bugzilla->localconfig->{urlbase};
+ $urlbase =~ s!/$!! if $base =~ "^/";
+ $base = $urlbase . $base;
+ return $base;
}
sub get_review_url {
- my ($bug, $attach_id) = @_;
- my $base = get_review_base();
- my $bug_id = $bug->id;
- return $base . ($base =~ /\?/ ? '&' : '?') . "bug=$bug_id&attachment=$attach_id";
+ my ($bug, $attach_id) = @_;
+ my $base = get_review_base();
+ my $bug_id = $bug->id;
+ return
+ $base
+ . ($base =~ /\?/ ? '&' : '?')
+ . "bug=$bug_id&attachment=$attach_id";
}
sub get_review_link {
- my ($attach_id, $link_text) = @_;
-
- my $attachment = attachment_id_is_valid($attach_id);
-
- if (attachment_id_is_patch($attach_id)) {
- return "<a href='" . html_quote(get_review_url($attachment->bug, $attach_id)) .
- "'>$link_text</a>";
- }
- else {
- return $link_text;
- }
+ my ($attach_id, $link_text) = @_;
+
+ my $attachment = attachment_id_is_valid($attach_id);
+
+ if (attachment_id_is_patch($attach_id)) {
+ return
+ "<a href='"
+ . html_quote(get_review_url($attachment->bug, $attach_id))
+ . "'>$link_text</a>";
+ }
+ else {
+ return $link_text;
+ }
}
sub munge_create_attachment {
- my ($bug, $intro_text, $attach_id, $view_link) = @_;
-
- if (attachment_id_is_patch($attach_id)) {
- return ("$intro_text" .
- " View: $view_link\015\012" .
- " Review: " . get_review_url($bug, $attach_id, 1) . "\015\012");
- }
- else {
- return ("$intro_text --> ($view_link)");
- }
+ my ($bug, $intro_text, $attach_id, $view_link) = @_;
+
+ if (attachment_id_is_patch($attach_id)) {
+ return ("$intro_text"
+ . " View: $view_link\015\012"
+ . " Review: "
+ . get_review_url($bug, $attach_id, 1)
+ . "\015\012");
+ }
+ else {
+ return ("$intro_text --> ($view_link)");
+ }
}
# This adds review links into a bug mail before we send it out.
@@ -133,64 +147,62 @@ sub munge_create_attachment {
# RFC-2822 style \r\n, we need handle line ends carefully.
# (\015 and \012 are used because Perl \n is platform-dependent)
sub add_review_links_to_email {
- my $email = shift;
- return if $email->parts > 1;
- return unless $email->content_type =~ m#^text/#;
+ my $email = shift;
+ return if $email->parts > 1;
+ return unless $email->content_type =~ m#^text/#;
- _fix_encoding($email);
- my $body = $email->body_str;
+ _fix_encoding($email);
+ my $body = $email->body_str;
- my $new_body = 0;
- my $bug;
+ my $new_body = 0;
+ my $bug;
- if ($email->header('Subject') =~ /^\[Bug\s+(\d+)\]/
- && Bugzilla->user->can_see_bug($1))
- {
- $bug = Bugzilla::Bug->new({ id => $1, cache => 1 });
- }
+ if ($email->header('Subject') =~ /^\[Bug\s+(\d+)\]/
+ && Bugzilla->user->can_see_bug($1))
+ {
+ $bug = Bugzilla::Bug->new({id => $1, cache => 1});
+ }
- return unless defined $bug;
+ return unless defined $bug;
- if ($body =~ /Review\s+of\s+attachment\s+\d+\s*:/) {
- $body =~ s~(Review\s+of\s+attachment\s+(\d+)\s*:)
+ if ($body =~ /Review\s+of\s+attachment\s+\d+\s*:/) {
+ $body =~ s~(Review\s+of\s+attachment\s+(\d+)\s*:)
~"$1\015\012 --> (" . get_review_url($bug, $2, 1) . ")"
~egx;
- $new_body = 1;
- }
+ $new_body = 1;
+ }
- if ($body =~ /Created attachment \d+\015\012 --> /) {
- $body =~ s~(Created\ attachment\ (\d+)\015\012)
+ if ($body =~ /Created attachment \d+\015\012 --> /) {
+ $body =~ s~(Created\ attachment\ (\d+)\015\012)
\ -->\ \(([^\015\012]*)\)[^\015\012]*
~munge_create_attachment($bug, $1, $2, $3)
~egx;
- $new_body = 1;
- }
+ $new_body = 1;
+ }
- $email->body_str_set($body) if $new_body;
+ $email->body_str_set($body) if $new_body;
}
sub _fix_encoding {
- my $part = shift;
-
- # don't touch the top-level part of multi-part mail
- return if $part->parts > 1;
-
- # nothing to do if the part already has a charset
- my $ct = parse_content_type($part->content_type);
- my $charset = $ct->{attributes}{charset}
- ? $ct->{attributes}{charset}
- : '';
- return unless !$charset || $charset eq 'us-ascii';
-
- if (Bugzilla->params->{utf8}) {
- $part->charset_set('UTF-8');
- my $raw = $part->body_raw;
- if (utf8::is_utf8($raw)) {
- utf8::encode($raw);
- $part->body_set($raw);
- }
+ my $part = shift;
+
+ # don't touch the top-level part of multi-part mail
+ return if $part->parts > 1;
+
+ # nothing to do if the part already has a charset
+ my $ct = parse_content_type($part->content_type);
+ my $charset = $ct->{attributes}{charset} ? $ct->{attributes}{charset} : '';
+ return unless !$charset || $charset eq 'us-ascii';
+
+ if (Bugzilla->params->{utf8}) {
+ $part->charset_set('UTF-8');
+ my $raw = $part->body_raw;
+ if (utf8::is_utf8($raw)) {
+ utf8::encode($raw);
+ $part->body_set($raw);
}
- $part->encoding_set('quoted-printable');
+ }
+ $part->encoding_set('quoted-printable');
}
1;