summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-04-05 04:18:58 +0200
committerDylan William Hardison <dylan@hardison.net>2018-06-28 22:41:54 +0200
commitcdc26a69674ea7a3413efce2f8d4e3225c6ab76e (patch)
treecdee5c2c8b40652cdea40becdcc96f13c3a97bc9
parente680057dd24ea4290096f4420bdd5c354acea024 (diff)
downloadbugzilla-cdc26a69674ea7a3413efce2f8d4e3225c6ab76e.tar.gz
bugzilla-cdc26a69674ea7a3413efce2f8d4e3225c6ab76e.tar.xz
render bugzilla templates using mojo
-rw-r--r--Bugzilla/CGI/Mojo.pm17
-rwxr-xr-xnew.psgi22
-rw-r--r--template/en/default/global/header.html.tmpl4
3 files changed, 42 insertions, 1 deletions
diff --git a/Bugzilla/CGI/Mojo.pm b/Bugzilla/CGI/Mojo.pm
index e3adf1133..2d4f40d3e 100644
--- a/Bugzilla/CGI/Mojo.pm
+++ b/Bugzilla/CGI/Mojo.pm
@@ -14,6 +14,23 @@ has 'controller' => (
handles => [qw(param cookie)],
);
+has 'content_security_policy' => (
+ is => 'lazy',
+);
+
+sub _build_content_security_policy {
+ my ($self) = @_;
+ my $csp = $self->controller->stash->{content_security_policy} // { Bugzilla::CGI::DEFAULT_CSP() };
+ return Bugzilla::CGI::ContentSecurityPolicy->new( $csp );
+}
+
+sub csp_nonce {
+ my ($self) = @_;
+
+ my $csp = $self->content_security_policy;
+ return $csp->has_nonce ? $csp->nonce : '';
+}
+
sub script_name {
my ($self) = @_;
diff --git a/new.psgi b/new.psgi
index 7685a7392..9eb56b370 100755
--- a/new.psgi
+++ b/new.psgi
@@ -19,6 +19,25 @@ use Try::Tiny;
plugin 'PODRenderer';
+app->renderer->add_handler(
+ 'bugzilla' => sub {
+ my ( $renderer, $c, $output, $options ) = @_;
+ my %params;
+
+ # Helpers
+ foreach my $method ( grep {m/^\w+\z/} keys %{ $renderer->helpers } ) {
+ my $sub = $renderer->helpers->{$method};
+ $params{$method} = sub { $c->$sub(@_) };
+ }
+
+ # Stash values
+ $params{$_} = $c->stash->{$_} for grep {m/^\w+\z/} keys %{ $c->stash };
+ $params{self} = $params{c} = $c;
+ Bugzilla->template->process( $options->{template}, \%params, $output )
+ or die Bugzilla->template->error;
+ }
+);
+
app->hook(
around_dispatch => sub {
my ($next, $c) = @_;
@@ -36,7 +55,8 @@ app->hook(
get '/' => sub {
my $c = shift;
my $user = Bugzilla->login(LOGIN_OPTIONAL);
- $c->render( template => 'index', user => $user );
+ $c->stash->{use_login_page} = 1;
+ $c->render( template => 'index.html.tmpl', handler => 'bugzilla', user => $user );
};
app->start;
diff --git a/template/en/default/global/header.html.tmpl b/template/en/default/global/header.html.tmpl
index 153137394..b286830fc 100644
--- a/template/en/default/global/header.html.tmpl
+++ b/template/en/default/global/header.html.tmpl
@@ -97,6 +97,10 @@
[% IF Param('utf8') %]
<meta charset="UTF-8">
[% END %]
+ [% USE Bugzilla %]
+ [% IF Bugzilla.usage_mode == constants.USAGE_MODE_MOJO %]
+ <base href="[% urlbase FILTER html %]">
+ [% END %]
[% IF Bugzilla.cgi.should_block_referrer %]
<meta name="referrer" content="origin">