summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Quantum
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Quantum')
-rw-r--r--Bugzilla/Quantum/Plugin/Hostage.pm32
-rw-r--r--Bugzilla/Quantum/Template.pm39
2 files changed, 52 insertions, 19 deletions
diff --git a/Bugzilla/Quantum/Plugin/Hostage.pm b/Bugzilla/Quantum/Plugin/Hostage.pm
index cbde7b5ee..418b09a0c 100644
--- a/Bugzilla/Quantum/Plugin/Hostage.pm
+++ b/Bugzilla/Quantum/Plugin/Hostage.pm
@@ -1,20 +1,19 @@
package Bugzilla::Quantum::Plugin::Hostage;
use 5.10.1;
use Mojo::Base 'Mojolicious::Plugin';
-use Bugzilla::Logging;
sub _attachment_root {
my ($base) = @_;
return undef unless $base;
return $base =~ m{^https?://(?:bug)?\%bugid\%\.([a-zA-Z\.-]+)}
- ? $1
- : undef;
+ ? $1
+ : undef;
}
sub _attachment_host_regex {
my ($base) = @_;
return undef unless $base;
- my $val = $base;
+ my $val = $base;
$val =~ s{^https?://}{}s;
$val =~ s{/$}{}s;
my $regex = quotemeta $val;
@@ -25,11 +24,11 @@ sub _attachment_host_regex {
sub register {
my ( $self, $app, $conf ) = @_;
- $app->hook( before_routes => \&_before_routes );
+ $app->hook(before_routes => \&_before_routes);
}
sub _before_routes {
- my ($c) = @_;
+ my ( $c ) = @_;
state $urlbase = Bugzilla->localconfig->{urlbase};
state $urlbase_uri = URI->new($urlbase);
state $urlbase_host = $urlbase_uri->host;
@@ -44,40 +43,35 @@ sub _before_routes {
return if $stash->{'mojo.static'};
- my $hostname = $url->host;
+ my $hostname = $url->host;
return if $hostname eq $urlbase_host;
my $path = $url->path;
return if $path eq '/__lbheartbeat__';
- if ( $attachment_base && $hostname eq $attachment_root ) {
- DEBUG("redirecting to $urlbase because $hostname is $attachment_root");
+ if ($attachment_base && $hostname eq $attachment_root) {
$c->redirect_to($urlbase);
return;
}
- elsif ( $attachment_base && $hostname =~ $attachment_host_regex ) {
- if ( $path =~ m{^/attachment\.cgi}s ) {
+ elsif ($attachment_base && $hostname =~ $attachment_host_regex) {
+ if ($path =~ m{^/attachment\.cgi}s) {
return;
- }
- else {
+ } else {
my $new_uri = $url->clone;
- $new_uri->scheme( $urlbase_uri->scheme );
+ $new_uri->scheme($urlbase_uri->scheme);
$new_uri->host($urlbase_host);
- DEBUG("redirecting to $new_uri because $hostname matches attachment regex");
$c->redirect_to($new_uri);
return;
}
}
- elsif ( my ($id) = $hostname =~ $urlbase_host_regex ) {
+ elsif (my ($id) = $hostname =~ $urlbase_host_regex) {
my $new_uri = $urlbase_uri->clone;
$new_uri->path('/show_bug.cgi');
- $new_uri->query_form( id => $id );
- DEBUG("redirecting to $new_uri because $hostname includes bug id");
+ $new_uri->query_form(id => $id);
$c->redirect_to($new_uri);
return;
}
else {
- DEBUG("redirecting to $urlbase because $hostname doesn't make sense");
$c->redirect_to($urlbase);
return;
}
diff --git a/Bugzilla/Quantum/Template.pm b/Bugzilla/Quantum/Template.pm
new file mode 100644
index 000000000..2442f1134
--- /dev/null
+++ b/Bugzilla/Quantum/Template.pm
@@ -0,0 +1,39 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Quantum::Template;
+use 5.10.1;
+use Moo;
+
+has 'controller' => (
+ is => 'ro',
+ required => 1,
+);
+
+has 'template' => (
+ is => 'ro',
+ required => 1,
+ handles => ['error', 'get_format'],
+);
+
+sub process {
+ my ($self, $file, $vars, $output) = @_;
+
+ if (@_ < 4) {
+ $self->controller->stash->{vars} = $vars;
+ $self->controller->render(template => $file, handler => 'bugzilla');
+ return 1;
+ }
+ elsif (@_ == 4) {
+ return $self->template->process($file, $vars, $output);
+ }
+ else {
+ die __PACKAGE__ . '->process() called with too many arguments';
+ }
+}
+
+1; \ No newline at end of file