blib/lib/Lemonldap/NG/Portal/Main/Menu.pm

filter: Statementstmt 80.8% 182 / 225 Branchbran 66.3% 65 / 98 Conditioncond 36.5% 30 / 82 MC/DCmcdc 13.9% 6 / 43 Subroutinesub 80.9% 17 / 21 Podpod 0.0% 0 / 4 totaltotal 63.4% 300 / 473 CC 94 SCAR 29.6
CC
94
Cov
68%
_buildApplicationHash
36.9
_filterHash
32.5
_sort_menu_helper
30.0
CRAP 19.2
« blib/lib/Lemonldap/NG/Portal/Lib/REST.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/TrustedBrowser.pm »
1 ##@file
2 # menu for lemonldap::ng portal
3 package Lemonldap::NG::Portal::Main::Menu;
4  
5 454 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 454 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 454 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 454 ▶use Lemonldap::NG::Portal::Main::Constants 'URIRE';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 454 our $VERSION = '2.23.0';
11  
12 454 extends 'Lemonldap::NG::Portal::Main::Plugin';
13  
14 # PROPERTIES
15  
16 has menuModules => (
17 is => 'rw',
18 lazy => 1,
19 8 ▶ builder => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
20 8 my $conf = $_[0]->{conf};
21 8 my (@res);
22 8 my @modules = $_[0]->_get_display_order( $conf->{portalDisplayOrder} );
23 8 foreach (@modules) {
24 40 ▶ my $cond = $conf->{"portalDisplay$_"} // 1;
Condition50%1/2
$$conf{"portalDisplay$_"} // 1
l!l
400
MC/DC0%0/1
$$conf{"portalDisplay$_"} // 1
$$conf{"portalDisplay$_"}
Truth table50%1/2
A
A= $$conf{"portalDisplay$_"}
Aresult
11
00
25 40 $_[0]->p->logger->debug("Evaluate condition $cond for module $_");
26 40 my $tmp =
27 $_[0]
28 ->p->HANDLER->buildSub( $_[0]->p->HANDLER->substitute($cond) );
29 40 ▶ push @res, [ $_, $tmp ] if $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp 40 0 40
30 }
31 8 return \@res;
32 }
33 454 );
34  
35 671 ▶has specific => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
36 671 ▶has sfManagerRule => ( is => 'rw', default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
37 has imgPath => (
38 is => 'rw',
39 lazy => 1,
40 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 return $_[0]->conf->{impgPath}
42 0 ▶ || $_[0]->conf->{staticPrefix} . '/logos';
Condition0%0/2
$_[0]->conf->{'impgPath'} || $_[0]->conf->{'staticPrefix'} . '/logos'
l!l
00
MC/DC0%0/1
$_[0]->conf->{'impgPath'} || $_[0]->conf->{'staticPrefix'} . '/logos'
$_[0]->conf->{'impgPath'}
Truth table0%0/2
A
A= $_[0]->conf->{'impgPath'}
Aresult
11
00
43 }
44 454 );
45  
46 # INITIALIZATION
47  
48 671 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
49 671 my ($self) = @_;
50  
51 $self->sfManagerRule(
52 671 $self->p->buildRule( $self->conf->{sfManagerRule}, 'sfManagerRule' ) );
53 671 ▶ $self->sfManagerRule(1) unless $self->sfManagerRule;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sfManagerRule 0 671 671
54  
55 # Allow custom plugins to register new menu tabs
56 671 $self->addEntryPoint(
57 does => "Lemonldap::NG::Portal::MenuTab",
58 service => "menu",
59 method => "_register_tab",
60 );
61  
62 671 return 1;
63 }
64  
65 # RUNNING METHODS
66  
67 # Prepare menu template elements
68 # Returns hash (=list) containing :
69 # - DISPLAY_MODULES
70 # - AUTH_ERROR
71 # - AUTH_ERROR_TYPE
72 12 ▶sub params {
Subroutine params: called CC=14 SCAR=28.4
Pod undocumented
73 12 my ( $self, $req ) = @_;
74 12 ▶ $self->conf->{imgPath} ||= $self->{staticPrefix};
Condition33%1/3
$self->conf->{"imgPath"} ||= $self->{"staticPrefix"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->conf->{"imgPath"} ||= $self->{"staticPrefix"}
$self->conf->{"imgPath"} $self->{"staticPrefix"}
Truth table33%1/3
A ||= B
A= $self->conf->{"imgPath"}B= $self->{"staticPrefix"}
ABresult
1X1
011
000
75 12 my %res;
76 12 my @defaultTabs = (qw/appslist password logout loginHistory oidcConsents/);
77 12 ▶ my @customTabs = split /[,\s]+/, $self->conf->{customMenuTabs} || '';
Condition50%1/2
$self->conf->{'customMenuTabs'} || ''
l!l
012
MC/DC0%0/1
$self->conf->{'customMenuTabs'} || ''
$self->conf->{'customMenuTabs'}
Truth table50%1/2
A
A= $self->conf->{'customMenuTabs'}
Aresult
11
00
78  
79 # Modules to display
80 12 $res{DISPLAY_MODULES} = $self->displayModules($req);
81  
82 # Display noApp message
83 12 $res{NO_APP_ALLOWED} = $req->data->{noApp};
84  
85 $res{AUTH_ERROR_TYPE} =
86 12 $req->error_type( $res{AUTH_ERROR} = $req->menuError );
87 12 $res{AUTH_ERROR_ROLE} = $req->error_role;
88 12 ▶ $res{ 'AUTH_ERROR_' . $res{AUTH_ERROR} } = 1 if $res{AUTH_ERROR};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"AUTH_ERROR"} 0 12 12
89  
90 # Display menu 2fRegisters link only if at least a 2F device is registered and rule
91 $res{sfaManager} =
92 12 ▶ $self->p->_sfEngine->display2fRegisters( $req, $req->userData )
Condition33%1/3
$self->p->_sfEngine->display2fRegisters($req, $req->userData) && $self->sfManagerRule->($req, $req->userData)
!ll&&!rl&&r
1200
MC/DC0%0/2
$self->p->_sfEngine->display2fRegisters($req, $req->userData) && $self->sfManagerRule->($req, $req->userData)
$self->p->_sfEngine->display2fRegisters($req, $req->userData) $self->sfManagerRule->($req, $req->userData)
Truth table33%1/3
A && B
A= $self->p->_sfEngine->display2fRegisters($req, $req->userData)B= $self->sfManagerRule->($req, $req->userData)
ABresult
0X0
100
111
93 && $self->sfManagerRule->( $req, $req->userData );
94 12 ▶ $self->logger->debug('Display 2fRegisters link') if $res{sfaManager};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"sfaManager"} 0 12 12
95  
96 # Display refresh my rights unless disabled
97 12 $res{RefreshMyRights} = $self->conf->{portalDisplayRefreshMyRights};
98 $self->logger->debug('Display RefreshMyRights link')
99 12 ▶ if $res{RefreshMyRights};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"RefreshMyRights"} 12 0 12
100  
101 # Display menu links only if required
102 12 foreach (qw(ContextSwitching DecryptValue Notifications)) {
103 my $plugin =
104 36 $self->p->loadedModules->{"Lemonldap::NG::Portal::Plugins::$_"};
105 36 ▶ $res{$_} =
Branch: 1 branch
BranchTrueFalseTotal
$plugin ? : 0 36 36
106 $plugin
107 ? $plugin->displayLink( $req, $req->userData )
108 : '';
109 36 my $msg = "Display $_ link";
110 $msg .= " -> $res{ContextSwitching}"
111 36 ▶ if ( $_ eq 'ContextSwitching' && $res{$_} );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "ContextSwitching" and $res{$_} 0 36 36
Condition66%2/3
$_ eq "ContextSwitching" and $res{$_}
!ll&&!rl&&r
24120
MC/DC0%0/2
$_ eq "ContextSwitching" and $res{$_}
$_ eq "ContextSwitching" $res{$_}
Truth table66%2/3
A and B
A= $_ eq "ContextSwitching"B= $res{$_}
ABresult
0X0
100
111
112 36 ▶ $self->logger->debug($msg) if $res{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $res{$_} 0 36 36
113 36 undef $plugin;
114 }
115  
116 # Decide whether to display the dropdown or regular text
117 12 $res{DropdownMenu} = 0;
118 12 foreach (
119 qw(RefreshMyRights sfaManager Notifications DecryptValue ContextSwitching)
120 )
121 {
122 12 ▶ if ( $res{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res{$_}) 12 0 12
123 12 $res{DropdownMenu} = 1;
124 12 last;
125 }
126 }
127  
128 12 return %res;
129 }
130  
131 ## @method arrayref displayModules()
132 # List modules that can be displayed in Menu
133 # @return modules list
134 12 ▶sub displayModules {
Subroutine displayModules: called CC=9 SCAR=23.5
Pod undocumented
135 12 my ( $self, $req ) = @_;
136 12 my $displayModules = [];
137  
138 # Foreach module, eval condition
139 # Store module in result if condition is valid
140 12 foreach my $module ( @{ $self->menuModules } ) {
141 60 $self->logger->debug("Check if $module->[0] has to be displayed");
142 60 ▶ if ( $module->[1]->( $req, $req->userData ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->[1]->($req, $req->userData)) 45 15 60
143 45 my $moduleHash = { $module->[0] => 1 };
144 45 ▶ if ( $module->[0] eq 'Appslist' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($module->[0] eq 'Appslist') { } 12 33 45
elsif ($module->[0] eq 'LoginHistory') { } 12 21 33
elsif ($module->[0] eq 'OidcConsents') { } 0 21 21
elsif ($module->[0] eq 'ChangePassword') { } 9 12 21
145 12 $moduleHash->{'APPSLIST_LOOP'} = $self->appslist($req);
146 $req->data->{noApp} = 1
147 12 ▶ unless scalar @{ $moduleHash->{'APPSLIST_LOOP'} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$moduleHash->{"APPSLIST_LOOP"};} 0 12 12
148 }
149 elsif ( $module->[0] eq 'LoginHistory' ) {
150 $moduleHash->{'SUCCESS_LOGIN'} =
151 $self->p->mkSessionArray( $req,
152 $req->userData->{_loginHistory}->{successLogin},
153 12 "", 0, 0 );
154 $moduleHash->{'FAILED_LOGIN'} =
155 $self->p->mkSessionArray( $req,
156 $req->userData->{_loginHistory}->{failedLogin},
157 12 "", 0, 1 );
158 }
159 elsif ( $module->[0] eq 'OidcConsents' ) {
160 0 $moduleHash->{'OIDC_CONSENTS'} =
161 $self->p->mkOidcConsent( $req, $req->userData );
162 }
163 elsif ( $module->[0] eq 'ChangePassword' ) {
164 9 $moduleHash->{'PPOLICY_RULES'} = $self->p->getPpolicyRules;
165 }
166  
167 # If the current entry is a plugin
168 45 ▶ if ( $module->[2] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->[2]) 0 45 45
169 0 my $plugin_hash = $module->[2]->display($req);
170 0 $moduleHash->{_PLUGIN} = 1;
171 0 $moduleHash->{_PLUGIN_LOGO} = $plugin_hash->{logo};
172 0 $moduleHash->{_PLUGIN_NAME} = $plugin_hash->{name};
173 0 $moduleHash->{_PLUGIN_ID} = $plugin_hash->{name};
174 0 $moduleHash->{_PLUGIN_HTML} = $plugin_hash->{html};
175 }
176 45 push @$displayModules, $moduleHash;
177 }
178 }
179  
180 12 return $displayModules;
181 }
182  
183 ## @method arrayref appslist()
184 # Returns categories and applications list as HTML::Template loop
185 # @return categories and applications list
186 12 ▶sub appslist {
Subroutine appslist: called CC=3 SCAR=11.1
Pod undocumented
187 12 my ( $self, $req ) = @_;
188 12 my $appslist = [];
189  
190 12 ▶ return $appslist unless defined $self->conf->{applicationList};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->conf->{"applicationList"} 0 12 12
191  
192 # Reset level
193 12 my $catlevel = 0;
194  
195 12 my $applicationList = clone( $self->conf->{applicationList} );
196 12 my $filteredList = $self->_filter( $req, $applicationList );
197 12 push @$appslist,
198 $self->_buildCategoryHash( $req, "", $filteredList, $catlevel );
199  
200 # We must return an ARRAY ref
201 return ( ref $appslist->[0]->{categories} eq "ARRAY" )
202 ? $appslist->[0]->{categories}
203 12 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $appslist->[0]{'categories'} eq 'ARRAY' ? : 12 0 12
204 }
205  
206 ## @method private hashref _buildCategoryHash(string catname,hashref cathash, int catlevel)
207 # Build hash for a category
208 # @param catname Category name
209 # @param cathash Hash of category elements
210 # @param catlevel Category level
211 # @return Category Hash
212 24 ▶sub _buildCategoryHash {
Subroutine _buildCategoryHash: called CC=17 SCAR=29.3
213 24 my ( $self, $req, $catid, $cathash, $catlevel ) = @_;
214 24 ▶ my $catname = $cathash->{catname} || $catid;
Condition66%2/3
$cathash->{'catname'} || $catid
l!l&&r!l&&!r
12012
MC/DC50%1/2
$cathash->{'catname'} || $catid
$cathash->{'catname'} $catid
Truth table66%2/3
A || B
A= $cathash->{'catname'}B= $catid
ABresult
1X1
011
000
215 24 my $applications;
216 my $categories;
217  
218 # Extract applications from hash
219 24 my $apphash;
220 24 foreach my $catkey ( sort keys %$cathash ) {
221 76 ▶ next if $catkey =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $catkey =~ /(type|options|catname|order)/ 48 28 76
222 28 ▶ if ( $cathash->{$catkey}->{type} eq "application" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cathash->{$catkey}{"type"} eq "application") 16 12 28
223 16 $apphash->{$catkey} = $cathash->{$catkey};
224 }
225 }
226  
227 # Display applications first
228 24 ▶ if ( scalar keys %$apphash > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$apphash > 0) 12 12 24
229 12 foreach my $appkey (
230 sort {
231 ( $apphash->{$a}->{order} || 0 )
232 4 ▶ <=> ( $apphash->{$b}->{order} || 0 )
Condition42%3/7
($apphash->{$a}{'order'} || 0) <=> ($apphash->{$b}{'order'} || 0) || $a cmp $b
l!l&&r!l&&!r
040
$apphash->{$a}{'order'} || 0
l!l
04
$apphash->{$b}{'order'} || 0
l!l
04
MC/DC0%0/2
($apphash->{$a}{'order'} || 0) <=> ($apphash->{$b}{'order'} || 0) || $a cmp $b
$apphash->{$a}{'order'} $a cmp $b
MC/DC0%0/1
$apphash->{$b}{'order'} || 0
$apphash->{$b}{'order'}
Truth table33%1/3
A || B
A= $apphash->{$a}{'order'}B= $a cmp $b
ABresult
1X1
011
000
Truth table50%1/2
A
A= $apphash->{$b}{'order'}
Aresult
11
00
233 or $a cmp $b
234 }
235 keys %$apphash
236 )
237 {
238 push @$applications,
239 16 $self->_buildApplicationHash( $appkey, $apphash->{$appkey} );
240 }
241 }
242  
243 # Display subcategories
244 24 foreach my $catkey (
245 sort {
246 ( $cathash->{$a}->{order} || 0 )
247 4 ▶ <=> ( $cathash->{$b}->{order} || 0 )
Condition42%3/7
($cathash->{$a}{'order'} || 0) <=> ($cathash->{$b}{'order'} || 0) || $a cmp $b
l!l&&r!l&&!r
040
$cathash->{$a}{'order'} || 0
l!l
04
$cathash->{$b}{'order'} || 0
l!l
04
MC/DC0%0/2
($cathash->{$a}{'order'} || 0) <=> ($cathash->{$b}{'order'} || 0) || $a cmp $b
$cathash->{$a}{'order'} $a cmp $b
MC/DC0%0/1
$cathash->{$b}{'order'} || 0
$cathash->{$b}{'order'}
Truth table33%1/3
A || B
A= $cathash->{$a}{'order'}B= $a cmp $b
ABresult
1X1
011
000
Truth table50%1/2
A
A= $cathash->{$b}{'order'}
Aresult
11
00
248 or $a cmp $b
249 }
250 76 grep { not /^(?:catname|type|options|order)$/ } keys %$cathash
251 )
252 {
253  
254 28 ▶ if ( $cathash->{$catkey}->{type} eq "category" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cathash->{$catkey}{"type"} eq "category") 12 16 28
255 push @$categories,
256 12 $self->_buildCategoryHash( $req, $catkey, $cathash->{$catkey},
257 $catlevel + 1 );
258 }
259 }
260  
261 24 my $categoryHash = {
262 category => 1,
263 catname => $catname,
264 catid => $catid,
265 catlevel => $catlevel
266 };
267 24 ▶ $categoryHash->{applications} = $applications if $applications;
Branch: 1 branch
BranchTrueFalseTotal
if $applications 12 12 24
268 24 ▶ $categoryHash->{categories} = $categories if $categories;
Branch: 1 branch
BranchTrueFalseTotal
if $categories 12 12 24
269 24 return $categoryHash;
270 }
271  
272 ## @method private hashref _buildApplicationHash(string appid, hashref apphash)
273 # Build hash for an application
274 # @param $appid Application ID
275 # @param $apphash Hash of application elements
276 # @return Application Hash
277 16 ▶sub _buildApplicationHash {
Subroutine _buildApplicationHash: called CC=14 SCAR=36.1
278 16 my ( $self, $appid, $apphash ) = @_;
279 16 my $applications;
280  
281 # Get application items
282 16 ▶ my $appname = $apphash->{options}->{name} || $appid;
Condition33%1/3
$apphash->{'options'}{'name'} || $appid
l!l&&r!l&&!r
1600
MC/DC0%0/2
$apphash->{'options'}{'name'} || $appid
$apphash->{'options'}{'name'} $appid
Truth table33%1/3
A || B
A= $apphash->{'options'}{'name'}B= $appid
ABresult
1X1
011
000
283 16 ▶ my $appuri = $apphash->{options}->{uri} || "";
Condition50%1/2
$apphash->{'options'}{'uri'} || ''
l!l
160
MC/DC0%0/1
$apphash->{'options'}{'uri'} || ''
$apphash->{'options'}{'uri'}
Truth table50%1/2
A
A= $apphash->{'options'}{'uri'}
Aresult
11
00
284 16 my $appdesc = $apphash->{options}->{description};
285 16 my $applogo = $apphash->{options}->{logo};
286 16 ▶ my $applogo_icon = ( $apphash->{options}->{logo} =~ /\./ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$apphash->{'options'}{'logo'} =~ /\./ ? : 16 0 16
287 16 ▶ my $apptip = $apphash->{options}->{tooltip} || $appname;
Condition66%2/3
$apphash->{'options'}{'tooltip'} || $appname
l!l&&r!l&&!r
4120
MC/DC0%0/2
$apphash->{'options'}{'tooltip'} || $appname
$apphash->{'options'}{'tooltip'} $appname
Truth table66%2/3
A || B
A= $apphash->{'options'}{'tooltip'}B= $appname
ABresult
1X1
011
000
288  
289 # Detect sub applications
290 16 my $subapphash;
291 16 foreach my $key ( sort keys %$apphash ) {
292 32 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 32 0 32
293 0 ▶ if ( $apphash->{$key}->{type} eq "application" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} eq "application") 0 0 0
294 0 $subapphash->{$key} = $apphash->{$key};
295 }
296 }
297  
298 # Display sub applications
299 16 ▶ if ( scalar keys %$subapphash > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$subapphash > 0) 0 16 16
300 0 foreach my $appkey (
301 sort {
302 ( $subapphash->{$a}->{order} || 0 )
303 0 ▶ <=> ( $subapphash->{$b}->{order} || 0 )
Condition0%0/7
($subapphash->{$a}{'order'} || 0) <=> ($subapphash->{$b}{'order'} || 0) || $a cmp $b
l!l&&r!l&&!r
000
$subapphash->{$a}{'order'} || 0
l!l
00
$subapphash->{$b}{'order'} || 0
l!l
00
MC/DC0%0/2
($subapphash->{$a}{'order'} || 0) <=> ($subapphash->{$b}{'order'} || 0) || $a cmp $b
$subapphash->{$a}{'order'} $a cmp $b
MC/DC0%0/1
$subapphash->{$b}{'order'} || 0
$subapphash->{$b}{'order'}
Truth table0%0/3
A || B
A= $subapphash->{$a}{'order'}B= $a cmp $b
ABresult
1X1
011
000
Truth table0%0/2
A
A= $subapphash->{$b}{'order'}
Aresult
11
00
304 or $a cmp $b
305 }
306 keys %$subapphash
307 )
308 {
309 push @$applications,
310 0 $self->_buildApplicationHash( $appkey, $subapphash->{$appkey} );
311 }
312 }
313  
314 16 my $applicationHash = {
315 application => 1,
316 appname => $appname,
317 appuri => $appuri,
318 appdesc => $appdesc,
319 applogo => $applogo,
320 applogo_icon => $applogo_icon,
321 appid => $appid,
322 apptip => $apptip,
323 };
324 16 ▶ $applicationHash->{applications} = $applications if $applications;
Branch: 1 branch
BranchTrueFalseTotal
if $applications 0 16 16
325 16 return $applicationHash;
326 }
327  
328 ## @method private string _filter(hashref apphash)
329 # Duplicate hash reference
330 # Remove unauthorized menu elements
331 # Hide empty categories
332 # @param $apphash Menu elements
333 # @return filtered hash
334 12 ▶sub _filter {
Subroutine _filter: called CC=2 SCAR=6.9
335 12 my ( $self, $req, $apphash ) = @_;
336 12 my $filteredHash;
337 my $key;
338  
339 # Copy hash reference into a new hash
340 12 foreach $key ( keys %$apphash ) {
341 20 $filteredHash->{$key} = $apphash->{$key};
342 }
343  
344 # Filter hash
345 12 $self->_filterHash( $req, $filteredHash );
346  
347 # Hide empty categories
348 12 $self->_isCategoryEmpty($filteredHash);
349  
350 12 return $filteredHash;
351 }
352  
353 ## @method private string _filterHash(hashref apphash, string currentpath)
354 # Remove unauthorized menu elements
355 # @param $apphash Menu elements
356 # @param $currentpath Path of the parent node in the menu tree, used as a
357 # qualified cache key for compiled "display" rules so that two homonymous
358 # applications living in distinct categories do not share the same rule.
359 # @return filtered hash
360 56 ▶sub _filterHash {
Subroutine _filterHash: called CC=20 SCAR=34.8
361 56 my ( $self, $req, $apphash, $currentpath ) = @_;
362 56 ▶ $currentpath //= "";
Condition100%2/2
$currentpath //= ""
l!l
4412
MC/DC100%1/1
$currentpath //= ""
$currentpath
Truth table100%2/2
A
A= $currentpath
Aresult
11
00
363  
364 56 foreach my $key ( keys %$apphash ) {
365 132 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 88 44 132
366 44 ▶ my $path = $currentpath ? "$currentpath/$key" : $key;
Branch: 1 branch
BranchTrueFalseTotal
$currentpath ? : 24 20 44
367 44 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category") 20 24 44
Condition66%2/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
!ll&&!rl&&r
02420
MC/DC50%1/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "category"
Truth table66%2/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "category"
ABresult
0X0
100
111
368 and $apphash->{$key}->{type} eq "category" )
369 {
370  
371 # Filter the category
372 20 $self->_filterHash( $req, $apphash->{$key}, $path );
373 }
374 44 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application") 24 20 44
Condition66%2/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application"
!ll&&!rl&&r
02024
MC/DC50%1/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "application"
Truth table66%2/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "application"
ABresult
0X0
100
111
375 and $apphash->{$key}->{type} eq "application" )
376 {
377  
378 # Filter sub applications
379 24 $self->_filterHash( $req, $apphash->{$key}, $path );
380  
381 # Check rights
382 24 $self->logger->debug("Checking display condition for $path");
383 my $appdisplay = $apphash->{$key}->{options}->{display}
384 24 ▶ || "auto";
Condition50%1/2
$apphash->{$key}{'options'}{'display'} || 'auto'
l!l
240
MC/DC0%0/1
$apphash->{$key}{'options'}{'display'} || 'auto'
$apphash->{$key}{'options'}{'display'}
Truth table50%1/2
A
A= $apphash->{$key}{'options'}{'display'}
Aresult
11
00
385 24 $apphash->{$key}->{options}->{uri} =~ URIRE;
386 24 my ( $vhost, $appuri ) = ( $3, $5 );
387 24 $vhost = $self->p->HANDLER->resolveAlias($vhost);
388 24 $appuri = $self->p->HANDLER->canonicalUri($appuri);
389  
390 # Remove if display is "no" or "off"
391 24 ▶ delete $apphash->{$key} and next if ( $appdisplay =~ /^(no|off)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $appdisplay =~ /^(no|off)$/ 0 24 24
Condition20%1/5
$appdisplay =~ /^(no|off)$/ && (delete $apphash->{$key} && (next))
!ll&&!rl&&r
2400
delete $apphash->{$key} and next
!ll
00
MC/DC0%0/2
$appdisplay =~ /^(no|off)$/ && (delete $apphash->{$key} && (next))
$appdisplay =~ /^(no|off)$/ delete $apphash->{$key}
Truth table33%1/3
A && B
A= $appdisplay =~ /^(no|off)$/B= delete $apphash->{$key}
ABresult
0X0
100
111
392  
393 # Keep node if display is "yes" or "on"
394 24 ▶ next if ( $appdisplay =~ /^(yes|on)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $appdisplay =~ /^(yes|on)$/ 0 24 24
395  
396 24 my $cond = undef;
397  
398 # Handle partner rules (SAML, CAS or OIDC)
399 24 ▶ if ( $appdisplay =~ /^sp:\s*(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($appdisplay =~ /^sp:\s*(.*)$/) 0 24 24
400 0 my $p = $1;
401 0 ▶ if ( my $sub = $self->p->spRules->{$p} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->p->spRules->{$p}) 0 0 0
402 0 eval {
403 0 ▶ delete $apphash->{$key}
Branch: 1 branch
BranchTrueFalseTotal
unless &$sub($req, $req->userData) 0 0 0
404 unless ( $sub->( $req, $req->userData ) );
405 };
406 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
407 0 $self->logger->error("Partner rule $p returns: $@");
408 }
409 }
410 0 next;
411 }
412  
413 # If a specific rule exists, get it from cache or compile it.
414 # The cache key includes the full path because two applications
415 # in different categories may share the same short name with
416 # different display rules (#3612).
417 24 ▶ if ( $appdisplay !~ /^auto$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($appdisplay =~ /^auto$/i) 16 8 24
418 16 ▶ if ( $self->specific->{$path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->specific->{$path}) { } 8 8 16
419 8 $cond = $self->specific->{$path};
420 }
421 else {
422 8 $cond = $self->specific->{$path} =
423 $self->p->HANDLER->buildSub(
424 $self->p->HANDLER->substitute($appdisplay) );
425 }
426 }
427  
428 # Check grant function if display is "auto" (this is the default)
429 24 ▶ delete $apphash->{$key}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->p->HANDLER->grant($req, $req->userData, $appuri, $cond, $vhost) 8 16 24
430 unless (
431 $self->p->HANDLER->grant(
432 $req, $req->userData, $appuri, $cond, $vhost
433 )
434 );
435 24 next;
436 }
437 }
438  
439 }
440  
441 ## @method private void _isCategoryEmpty(hashref apphash)
442 # Check if a category is empty
443 # @param $apphash Menu elements
444 # @return boolean
445 32 ▶sub _isCategoryEmpty {
Subroutine _isCategoryEmpty: called CC=9 SCAR=22.0
446 32 my $self = shift;
447 32 my ($apphash) = @_;
448 32 my $key;
449  
450 # Test sub categories
451 32 foreach $key ( keys %$apphash ) {
452 76 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 40 36 76
453 36 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category") 20 16 36
Condition66%2/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
!ll&&!rl&&r
01620
MC/DC50%1/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "category"
Truth table66%2/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "category"
ABresult
0X0
100
111
454 and $apphash->{$key}->{type} eq "category" )
455 {
456 delete $apphash->{$key}
457 20 ▶ if $self->_isCategoryEmpty( $apphash->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_isCategoryEmpty($apphash->{$key}) 8 12 20
458 }
459 }
460  
461 # Test this category
462 32 ▶ if ( $apphash->{type} and $apphash->{type} eq "category" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{"type"} and $apphash->{"type"} eq "category") 20 12 32
Condition66%2/3
$apphash->{"type"} and $apphash->{"type"} eq "category"
!ll&&!rl&&r
12020
MC/DC50%1/2
$apphash->{"type"} and $apphash->{"type"} eq "category"
$apphash->{"type"} $apphash->{"type"} eq "category"
Truth table66%2/3
A and B
A= $apphash->{"type"}B= $apphash->{"type"} eq "category"
ABresult
0X0
100
111
463  
464 # Temporary store 'options'
465 20 my $tmp_options = $apphash->{options};
466 20 my $tmp_catname = $apphash->{catname};
467 20 my $tmp_order = $apphash->{order};
468  
469 20 delete $apphash->{type};
470 20 delete $apphash->{options};
471 20 delete $apphash->{catname};
472 20 delete $apphash->{order};
473  
474 20 ▶ if ( scalar( keys %$apphash ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$apphash) { } 12 8 20
475  
476 # There are sub categories or sub applications
477 # Restore type and options
478 12 $apphash->{type} = "category";
479 12 $apphash->{options} = $tmp_options;
480 12 $apphash->{catname} = $tmp_catname;
481 12 $apphash->{order} = $tmp_order;
482  
483 # Return false
484 12 return 0;
485 }
486 else {
487  
488 # Return true
489 8 return 1;
490 }
491 }
492 12 return 0;
493 }
494  
495 0 ▶sub _register_tab {
Subroutine _register_tab: not called CC=4 SCAR=30.0
496 0 my ( $self, $plugin ) = @_;
497  
498 0 ▶ my $rule_text = $plugin->rule // "1";
Condition0%0/2
$plugin->rule // 1
l!l
00
MC/DC0%0/1
$plugin->rule // 1
$plugin->rule
Truth table0%0/2
A
A= $plugin->rule
Aresult
11
00
499 0 my $name = $plugin->name;
500  
501 0 ▶ if ( !$name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 0 0
502 0 $self->logger->warn("Could not load custom menu tab: missing name");
503 0 return;
504 }
505  
506 0 my $compiled_rule =
507 $self->p->buildRule( $rule_text, "Rule for $name custom tab" );
508 0 ▶ if ( !$compiled_rule ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compiled_rule) 0 0 0
509 0 return;
510 }
511  
512 0 push @{ $self->menuModules }, [ $name, $compiled_rule, $plugin ];
513  
514 # Sort menuModules array
515 0 @{ $self->menuModules } = $self->_sort_menu( $self->menuModules,
516 0 $self->conf->{portalDisplayOrder} );
517 0 return;
518 }
519  
520 # This function does the sorting work and should be easy to test
521 0 ▶sub _sort_menu {
Subroutine _sort_menu: not called CC=2 SCAR=17.9
522 0 my ( $self, $menuToSort, $displayOrderString ) = @_;
523  
524 0 my @order = $self->_get_display_order($displayOrderString);
525 0 my $orderhash;
526 0 @$orderhash{@order} = 1 .. @order;
527  
528 # If the position of unknown plugins was not specified, put them at the end
529 0 ▶ $orderhash->{_unknown} //= @order + 1;
Condition0%0/2
$orderhash->{"_unknown"} //= @order + 1
l!l
00
MC/DC0%0/1
$orderhash->{"_unknown"} //= @order + 1
$orderhash->{"_unknown"}
Truth table0%0/2
A
A= $orderhash->{"_unknown"}
Aresult
11
00
530  
531 0 return sort { _sort_menu_helper( $orderhash, $a, $b ) } @$menuToSort;
532 }
533  
534 # Sort helper based on portalDisplayOrder
535 # orderhash is a name => position hash
536 # You can use "_unknown" in portalDisplayOrder as a placeholder for plugins of unknown position
537 0 ▶sub _sort_menu_helper {
Subroutine _sort_menu_helper: not called CC=5 SCAR=34.0
538 0 my ( $orderhash, $a, $b ) = @_;
539  
540 return ( $orderhash->{ $a->[0] } || $orderhash->{_unknown} || 0 )
541 0 ▶ <=> ( $orderhash->{ $b->[0] } || $orderhash->{_unknown} || 0 );
Condition0%0/10
$$orderhash{$a->[0]} || $orderhash->{'_unknown'} || 0
l!l
00
$$orderhash{$a->[0]} or $orderhash->{"_unknown"}
l!l&&r!l&&!r
000
$$orderhash{$b->[0]} || $orderhash->{'_unknown'} || 0
l!l
00
$$orderhash{$b->[0]} or $orderhash->{"_unknown"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$orderhash{$a->[0]} || $orderhash->{'_unknown'} || 0
$$orderhash{$a->[0]} $orderhash->{"_unknown"}
MC/DC0%0/2
$$orderhash{$b->[0]} || $orderhash->{'_unknown'} || 0
$$orderhash{$b->[0]} $orderhash->{"_unknown"}
Truth table0%0/3
A or B
A= $$orderhash{$a->[0]}B= $orderhash->{"_unknown"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $$orderhash{$b->[0]}B= $orderhash->{"_unknown"}
ABresult
1X1
011
000
542 }
543  
544 8 ▶sub _get_display_order {
Subroutine _get_display_order: called CC=1 SCAR=0.0
545 8 my ( $self, $displayOrderString ) = @_;
546 8 my %hash;
547 8 return grep { !$hash{$_}++ } split /[,\s]+/, $displayOrderString,;
548 }
549  
550 454 1;
« blib/lib/Lemonldap/NG/Portal/Lib/REST.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/TrustedBrowser.pm »