From d6bc2a79456a319fe073a470d1643721bf7adf5e Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Sat, 3 Mar 2018 20:18:33 -0500 Subject: support extensions better --- app.psgi | 40 +++++++++++----------------------------- extensions/BMO/Extension.pm | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app.psgi b/app.psgi index 1da6d4351..101a85a83 100644 --- a/app.psgi +++ b/app.psgi @@ -47,40 +47,24 @@ use Plack::App::URLMap; use Plack::App::WrapCGI; use Plack::Response; -use constant STATIC => qw( - data/webdot - docs - extensions/[^/]+/web - graphs - images - js - skins -); - -# Pre-load all extensions -Bugzilla::Extension->load_all(); +# Pre-load all extensions and find their static dirs. +my @extensions = map { $_->NAME } @{ Bugzilla::Extension->load_all() }; +my @static_dirs = qw( data/webdot docs graphs images js skins static ); +foreach my $name (@extensions) { + my $dir = File::Spec->catfile('extensions', $name, 'web'); + push @static_dirs, $dir if -d $dir; +} + Bugzilla->preload_features(); # Force instantiation of template so Bugzilla::Template::PreloadProvider can do its magic. Bugzilla->template; -my $ses_index = builder { - my $auth_user = Bugzilla->localconfig->{ses_username}; - my $auth_pass = Bugzilla->localconfig->{ses_password}; - enable "Auth::Basic", authenticator => sub { - my ($username, $password, $env) = @_; - return ( $auth_user - && $auth_pass - && $username - && $password - && $username eq $auth_user - && $password eq $auth_pass ); - }; - compile_cgi("ses/index.cgi"); -}; +use Bugzilla::Sentry; + my $bugzilla_app = builder { - my $static_paths = join( '|', STATIC ); + my $static_paths = join '|', map quotemeta, sort {length $b <=> length $a || $a cmp $b } @static_dirs; enable 'Log4perl', category => 'Plack'; @@ -97,8 +81,6 @@ my $bugzilla_app = builder { $mount{$name} = compile_cgi($script); } - $mount{'ses/index.cgi'} = $ses_index; - Bugzilla::Hook::process('psgi_builder', { mount => \%mount }); foreach my $name ( keys %mount ) { diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 2d5d2b182..08a7beb90 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -46,6 +46,7 @@ use Bugzilla::User; use Bugzilla::UserAgent qw(detect_platform detect_op_sys); use Bugzilla::User::Setting; use Bugzilla::Util; +use Bugzilla::PSGI qw(compile_cgi); use Date::Parse; use DateTime; @@ -1666,6 +1667,28 @@ sub webservice { $dispatch->{BMO} = "Bugzilla::Extension::BMO::WebService"; } +sub psgi_builder { + my ($self, $args) = @_; + my $mount = $args->{mount}; + + my $ses_index = Plack::Builder::builder { + my $auth_user = Bugzilla->localconfig->{ses_username}; + my $auth_pass = Bugzilla->localconfig->{ses_password}; + Plack::Builder::enable "Auth::Basic", authenticator => sub { + my ($username, $password, $env) = @_; + return ( $auth_user + && $auth_pass + && $username + && $password + && $username eq $auth_user + && $password eq $auth_pass ); + }; + compile_cgi("ses/index.cgi"); + }; + + $mount->{'ses/index.cgi'} = $ses_index; +} + our $search_content_matches; BEGIN { $search_content_matches = \&Bugzilla::Search::_content_matches; -- cgit v1.2.3-24-g4f1b