From ae3a728378f218477f8bf5d46952fb1ba1ab58b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20OUDOT?= Date: Wed, 10 Apr 2019 15:42:58 +0200 Subject: [PATCH] Manage template inclusion when file is not in configured portal theme (#1653) --- .../lib/Lemonldap/NG/Common/PSGI.pm | 3 ++- .../lib/Lemonldap/NG/Portal/Lib/SMTP.pm | 8 +++++--- .../lib/Lemonldap/NG/Portal/Main/Init.pm | 2 ++ .../lib/Lemonldap/NG/Portal/Main/Run.pm | 18 ++++++++---------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm index 934b98979..4cf7ab29f 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm @@ -17,7 +17,7 @@ has languages => ( is => 'rw', isa => 'Str', default => 'en' ); has logLevel => ( is => 'rw', isa => 'Str', default => 'info' ); has portal => ( is => 'rw', isa => 'Str' ); has staticPrefix => ( is => 'rw', isa => 'Str' ); -has templateDir => ( is => 'rw', isa => 'Str' ); +has templateDir => ( is => 'rw', isa => 'Str|ArrayRef' ); has links => ( is => 'rw', isa => 'ArrayRef' ); has menuLinks => ( is => 'rw', isa => 'ArrayRef' ); has logger => ( is => 'rw' ); @@ -250,6 +250,7 @@ sub sendHtml { $htpl = HTML::Template->new( filehandle => IO::File->new($template), path => $self->templateDir, + search_path_on_include => 1, die_on_bad_params => 0, die_on_missing_include => 1, cache => 0, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm index e8c8c9ead..a7f5b2446 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm @@ -15,7 +15,7 @@ use Email::Sender::Transport::SMTP qw(); use MIME::Base64; use Encode; -our $VERSION = '2.0.2'; +our $VERSION = '2.0.3'; our $transport; @@ -184,8 +184,10 @@ sub send_mail { foreach ( keys %cid ) { $message->attach( Type => "image/" . ( $cid{$_} =~ m/\.(\w+)/ )[0], - Id => $_, - Path => $self->p->{templateDir} . "/" . $cid{$_}, + Id => $_, + Path => $self->conf->{templateDir} . "/" + . $self->conf->{portalSkin} . "/" + . $cid{$_}, ); } } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm index f529fc5f5..63a8bc3cc 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm @@ -194,6 +194,8 @@ sub reloadConf { $self->error("Template dir $self->{templateDir} doesn't exist"); return $self->fail; } + $self->templateDir( + [ $self->{templateDir}, $self->conf->{templateDir} . '/bootstrap' ] ); $self->{staticPrefix} = $self->conf->{staticPrefix} || '/static'; $self->{languages} = $self->conf->{languages} || '/'; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 959fabfb6..6d875d622 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -743,6 +743,7 @@ sub sendHtml { my ( $self, $req, $template, %args ) = @_; my $templateDir = $self->conf->{templateDir} . '/' . $self->getSkin($req); + $self->templateDir( [ $templateDir, @{ $self->templateDir } ] ); # Check template $args{templateDir} = $templateDir; @@ -1004,17 +1005,14 @@ sub _sumUpSession { sub loadTemplate { my ( $self, $name, %prm ) = @_; $name .= '.tpl'; - my $file = - $self->conf->{templateDir} . '/' - . $self->conf->{portalSkin} . '/' - . $name; - $file = $self->conf->{templateDir} . '/common/' . $name - unless ( -e $file ); - unless ( -e $file ) { - die "Unable to find $name in $self->conf->{templateDir}"; - } my $tpl = HTML::Template->new( - filename => $file, + filename => $name, + path => [ + $self->conf->{templateDir} . '/' . $self->conf->{portalSkin}, + $self->conf->{templateDir} . '/bootstrap/', + $self->conf->{templateDir} . '/common/' + ], + search_path_on_include => 1, die_on_bad_params => 0, die_on_missing_include => 1, cache => 1,