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

filter: Statementstmt 11.5% 26 / 225 Branchbran 0.9% 1 / 104 Conditioncond 0.0% 0 / 74 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 33.3% 7 / 21 Podpod 0.0% 0 / 4 totaltotal 7.2% 34 / 469 CC 95 SCAR 52.9
CC
95
Cov
7%
_filterHash
462.0
_buildCategoryHash
306.0
params
210.0
CRAP 198.2
« blib/lib/Lemonldap/NG/Portal/Plugins/CheckState.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/SAML.pm »
1 ##@file
2 # menu for lemonldap::ng portal
3 package Lemonldap::NG::Portal::Main::Menu;
4  
5 429 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 429 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 429 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 429 ▶use Lemonldap::NG::Portal::Main::Constants 'URIRE';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 429 our $VERSION = '2.18.0';
11  
12 429 extends 'Lemonldap::NG::Portal::Main::Plugin';
13  
14 # PROPERTIES
15  
16 has menuModules => (
17 is => 'rw',
18 lazy => 1,
19 builder => sub {
20 0 ▶ my $conf = $_[0]->{conf};
Subroutine __ANON__: not called CC=4 SCAR=30.0
21 0 my (@res);
22 0 my @modules = $_[0]->_get_display_order( $conf->{portalDisplayOrder} );
23 0 foreach (@modules) {
24 0 ▶ my $cond = $conf->{"portalDisplay$_"} // 1;
Condition0%0/2
$$conf{"portalDisplay$_"} // 1
l!l
00
MC/DC0%0/1
$$conf{"portalDisplay$_"} // 1
$$conf{"portalDisplay$_"}
Truth table0%0/2
A
A= $$conf{"portalDisplay$_"}
Aresult
11
00
25 0 $_[0]->p->logger->debug("Evaluate condition $cond for module $_");
26 0 my $tmp =
27 $_[0]
28 ->p->HANDLER->buildSub( $_[0]->p->HANDLER->substitute($cond) );
29 0 ▶ push @res, [ $_, $tmp ] if $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp 0 0 0
30 }
31 0 return \@res;
32 }
33 429 );
34  
35 490 ▶has specific => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
36 490 ▶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 builder => sub {
41 return $_[0]->conf->{impgPath}
42 0 ▶ || $_[0]->conf->{staticPrefix} . '/logos';
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 429 );
45  
46 # INITIALIZATION
47  
48 sub init {
49 490 ▶ my ($self) = @_;
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
50  
51 $self->sfManagerRule(
52 490 $self->p->buildRule( $self->conf->{sfManagerRule}, 'sfManagerRule' ) );
53 490 ▶ $self->sfManagerRule(1) unless $self->sfManagerRule;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sfManagerRule 0 490 490
54  
55 # Allow custom plugins to register new menu tabs
56 490 $self->addEntryPoint(
57 does => "Lemonldap::NG::Portal::MenuTab",
58 service => "menu",
59 method => "_register_tab",
60 );
61  
62 490 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 sub params {
73 0 ▶ my ( $self, $req ) = @_;
Subroutine params: not called CC=14 SCAR=53.5
Pod undocumented
74 0 ▶ $self->conf->{imgPath} ||= $self->{staticPrefix};
Condition0%0/3
$self->conf->{"imgPath"} ||= $self->{"staticPrefix"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{"imgPath"} ||= $self->{"staticPrefix"}
$self->conf->{"imgPath"} $self->{"staticPrefix"}
Truth table0%0/3
A ||= B
A= $self->conf->{"imgPath"}B= $self->{"staticPrefix"}
ABresult
1X1
011
000
75 0 my %res;
76 0 my @defaultTabs = (qw/appslist password logout loginHistory oidcConsents/);
77 0 ▶ my @customTabs = split /[,\s]+/, $self->conf->{customMenuTabs} || '';
Condition0%0/2
$self->conf->{'customMenuTabs'} || ''
l!l
00
MC/DC0%0/1
$self->conf->{'customMenuTabs'} || ''
$self->conf->{'customMenuTabs'}
Truth table0%0/2
A
A= $self->conf->{'customMenuTabs'}
Aresult
11
00
78  
79 # Modules to display
80 0 $res{DISPLAY_MODULES} = $self->displayModules($req);
81  
82 # Display noApp message
83 0 $res{NO_APP_ALLOWED} = $req->data->{noApp};
84  
85 $res{AUTH_ERROR_TYPE} =
86 0 $req->error_type( $res{AUTH_ERROR} = $req->menuError );
87 0 $res{AUTH_ERROR_ROLE} = $req->error_role;
88 0 ▶ $res{ 'AUTH_ERROR_' . $res{AUTH_ERROR} } = 1 if $res{AUTH_ERROR};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"AUTH_ERROR"} 0 0 0
89  
90 # Display menu 2fRegisters link only if at least a 2F device is registered and rule
91 $res{sfaManager} =
92 0 ▶ $self->p->_sfEngine->display2fRegisters( $req, $req->userData )
Condition0%0/3
$self->p->_sfEngine->display2fRegisters($req, $req->userData) && $self->sfManagerRule->($req, $req->userData)
!ll&&!rl&&r
000
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 table0%0/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 0 ▶ $self->logger->debug('Display 2fRegisters link') if $res{sfaManager};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"sfaManager"} 0 0 0
95  
96 # Display refresh my rights unless disabled
97 0 $res{RefreshMyRights} = $self->conf->{portalDisplayRefreshMyRights};
98 $self->logger->debug('Display RefreshMyRights link')
99 0 ▶ if $res{RefreshMyRights};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"RefreshMyRights"} 0 0 0
100  
101 # Display menu links only if required
102 0 foreach (qw(ContextSwitching DecryptValue Notifications)) {
103 my $plugin =
104 0 $self->p->loadedModules->{"Lemonldap::NG::Portal::Plugins::$_"};
105 0 ▶ $res{$_} =
Branch: 1 branch
BranchTrueFalseTotal
$plugin ? : 0 0 0
106 $plugin
107 ? $plugin->displayLink( $req, $req->userData )
108 : '';
109 0 my $msg = "Display $_ link";
110 $msg .= " -> $res{ContextSwitching}"
111 0 ▶ if ( $_ eq 'ContextSwitching' && $res{$_} );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "ContextSwitching" and $res{$_} 0 0 0
Condition0%0/3
$_ eq "ContextSwitching" and $res{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq "ContextSwitching" and $res{$_}
$_ eq "ContextSwitching" $res{$_}
Truth table0%0/3
A and B
A= $_ eq "ContextSwitching"B= $res{$_}
ABresult
0X0
100
111
112 0 ▶ $self->logger->debug($msg) if $res{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $res{$_} 0 0 0
113 0 undef $plugin;
114 }
115  
116 # Decide whether to display the dropdown or regular text
117 0 $res{DropdownMenu} = 0;
118 0 foreach (
119 qw(RefreshMyRights sfaManager Notifications DecryptValue ContextSwitching)
120 )
121 {
122 0 ▶ if ( $res{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res{$_}) 0 0 0
123 0 $res{DropdownMenu} = 1;
124 0 last;
125 }
126 }
127  
128 0 return %res;
129 }
130  
131 ## @method arrayref displayModules()
132 # List modules that can be displayed in Menu
133 # @return modules list
134 sub displayModules {
135 0 ▶ my ( $self, $req ) = @_;
Subroutine displayModules: not called CC=9 SCAR=45.0
Pod undocumented
136 0 my $displayModules = [];
137  
138 # Foreach module, eval condition
139 # Store module in result if condition is valid
140 0 foreach my $module ( @{ $self->menuModules } ) {
141 0 $self->logger->debug("Check if $module->[0] has to be displayed");
142 0 ▶ if ( $module->[1]->( $req, $req->userData ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->[1]->($req, $req->userData)) 0 0 0
143 0 my $moduleHash = { $module->[0] => 1 };
144 0 ▶ if ( $module->[0] eq 'Appslist' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($module->[0] eq 'Appslist') { } 0 0 0
elsif ($module->[0] eq 'LoginHistory') { } 0 0 0
elsif ($module->[0] eq 'OidcConsents') { } 0 0 0
elsif ($module->[0] eq 'ChangePassword') { } 0 0 0
145 0 $moduleHash->{'APPSLIST_LOOP'} = $self->appslist($req);
146 $req->data->{noApp} = 1
147 0 ▶ unless scalar @{ $moduleHash->{'APPSLIST_LOOP'} };
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$moduleHash->{"APPSLIST_LOOP"};} 0 0 0
148 }
149 elsif ( $module->[0] eq 'LoginHistory' ) {
150 $moduleHash->{'SUCCESS_LOGIN'} =
151 $self->p->mkSessionArray( $req,
152 $req->{userData}->{_loginHistory}->{successLogin},
153 0 "", 0, 0 );
154 $moduleHash->{'FAILED_LOGIN'} =
155 $self->p->mkSessionArray( $req,
156 $req->{userData}->{_loginHistory}->{failedLogin},
157 0 "", 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 0 $moduleHash->{'PPOLICY_RULES'} = $self->p->getPpolicyRules;
165 }
166  
167 # If the current entry is a plugin
168 0 ▶ if ( $module->[2] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->[2]) 0 0 0
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 0 push @$displayModules, $moduleHash;
177 }
178 }
179  
180 0 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 sub appslist {
187 0 ▶ my ( $self, $req ) = @_;
Subroutine appslist: not called CC=3 SCAR=24.8
Pod undocumented
188 0 my $appslist = [];
189  
190 0 ▶ return $appslist unless defined $self->conf->{applicationList};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->conf->{"applicationList"} 0 0 0
191  
192 # Reset level
193 0 my $catlevel = 0;
194  
195 0 my $applicationList = clone( $self->conf->{applicationList} );
196 0 my $filteredList = $self->_filter( $req, $applicationList );
197 0 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 0 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $appslist->[0]{'categories'} eq 'ARRAY' ? : 0 0 0
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 sub _buildCategoryHash {
213 0 ▶ my ( $self, $req, $catid, $cathash, $catlevel ) = @_;
Subroutine _buildCategoryHash: not called CC=17 SCAR=57.2
214 0 ▶ my $catname = $cathash->{catname} || $catid;
Condition0%0/3
$cathash->{'catname'} || $catid
l!l&&r!l&&!r
000
MC/DC0%0/2
$cathash->{'catname'} || $catid
$cathash->{'catname'} $catid
Truth table0%0/3
A || B
A= $cathash->{'catname'}B= $catid
ABresult
1X1
011
000
215 0 my $applications;
216 my $categories;
217  
218 # Extract applications from hash
219 0 my $apphash;
220 0 foreach my $catkey ( sort keys %$cathash ) {
221 0 ▶ next if $catkey =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $catkey =~ /(type|options|catname|order)/ 0 0 0
222 0 ▶ if ( $cathash->{$catkey}->{type} eq "application" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cathash->{$catkey}{"type"} eq "application") 0 0 0
223 0 $apphash->{$catkey} = $cathash->{$catkey};
224 }
225 }
226  
227 # Display applications first
228 0 ▶ if ( scalar keys %$apphash > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$apphash > 0) 0 0 0
229 0 foreach my $appkey (
230 sort {
231 ( $apphash->{$a}->{order} || 0 )
232 0 ▶ <=> ( $apphash->{$b}->{order} || 0 )
Branch: 1 branch
BranchTrueFalseTotal
($apphash->{$a}{"order"} || 0) <=> ($apphash->{$b}{"order"} || 0) or $a cmp $b 0 0 0
Condition0%0/4
$apphash->{$a}{'order'} || 0
l!l
00
$apphash->{$b}{'order'} || 0
l!l
00
MC/DC0%0/1
$apphash->{$a}{'order'} || 0
$apphash->{$a}{'order'}
MC/DC0%0/1
$apphash->{$b}{'order'} || 0
$apphash->{$b}{'order'}
Truth table0%0/2
A
A= $apphash->{$a}{'order'}
Aresult
11
00
Truth table0%0/2
A
A= $apphash->{$b}{'order'}
Aresult
11
00
233 or $a cmp $b
234 }
235 keys %$apphash
236 )
237 {
238 push @$applications,
239 0 $self->_buildApplicationHash( $appkey, $apphash->{$appkey} );
240 }
241 }
242  
243 # Display subcategories
244 0 foreach my $catkey (
245 sort {
246 ( $cathash->{$a}->{order} || 0 )
247 0 ▶ <=> ( $cathash->{$b}->{order} || 0 )
Branch: 1 branch
BranchTrueFalseTotal
($cathash->{$a}{"order"} || 0) <=> ($cathash->{$b}{"order"} || 0) or $a cmp $b 0 0 0
Condition0%0/4
$cathash->{$a}{'order'} || 0
l!l
00
$cathash->{$b}{'order'} || 0
l!l
00
MC/DC0%0/1
$cathash->{$a}{'order'} || 0
$cathash->{$a}{'order'}
MC/DC0%0/1
$cathash->{$b}{'order'} || 0
$cathash->{$b}{'order'}
Truth table0%0/2
A
A= $cathash->{$a}{'order'}
Aresult
11
00
Truth table0%0/2
A
A= $cathash->{$b}{'order'}
Aresult
11
00
248 or $a cmp $b
249 }
250 0 grep { not /^(?:catname|type|options|order)$/ } keys %$cathash
251 )
252 {
253  
254 0 ▶ if ( $cathash->{$catkey}->{type} eq "category" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cathash->{$catkey}{"type"} eq "category") 0 0 0
255 push @$categories,
256 0 $self->_buildCategoryHash( $req, $catkey, $cathash->{$catkey},
257 $catlevel + 1 );
258 }
259 }
260  
261 0 my $categoryHash = {
262 category => 1,
263 catname => $catname,
264 catid => $catid,
265 catlevel => $catlevel
266 };
267 0 ▶ $categoryHash->{applications} = $applications if $applications;
Branch: 1 branch
BranchTrueFalseTotal
if $applications 0 0 0
268 0 ▶ $categoryHash->{categories} = $categories if $categories;
Branch: 1 branch
BranchTrueFalseTotal
if $categories 0 0 0
269 0 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 sub _buildApplicationHash {
278 0 ▶ my ( $self, $appid, $apphash ) = @_;
Subroutine _buildApplicationHash: not called CC=14 SCAR=53.5
279 0 my $applications;
280  
281 # Get application items
282 0 ▶ my $appname = $apphash->{options}->{name} || $appid;
Condition0%0/3
$apphash->{'options'}{'name'} || $appid
l!l&&r!l&&!r
000
MC/DC0%0/2
$apphash->{'options'}{'name'} || $appid
$apphash->{'options'}{'name'} $appid
Truth table0%0/3
A || B
A= $apphash->{'options'}{'name'}B= $appid
ABresult
1X1
011
000
283 0 ▶ my $appuri = $apphash->{options}->{uri} || "";
Condition0%0/2
$apphash->{'options'}{'uri'} || ''
l!l
00
MC/DC0%0/1
$apphash->{'options'}{'uri'} || ''
$apphash->{'options'}{'uri'}
Truth table0%0/2
A
A= $apphash->{'options'}{'uri'}
Aresult
11
00
284 0 my $appdesc = $apphash->{options}->{description};
285 0 my $applogo = $apphash->{options}->{logo};
286 0 ▶ my $applogo_icon = ( $apphash->{options}->{logo} =~ /\./ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$apphash->{'options'}{'logo'} =~ /\./ ? : 0 0 0
287 0 ▶ my $apptip = $apphash->{options}->{tooltip} || $appname;
Condition0%0/3
$apphash->{'options'}{'tooltip'} || $appname
l!l&&r!l&&!r
000
MC/DC0%0/2
$apphash->{'options'}{'tooltip'} || $appname
$apphash->{'options'}{'tooltip'} $appname
Truth table0%0/3
A || B
A= $apphash->{'options'}{'tooltip'}B= $appname
ABresult
1X1
011
000
288  
289 # Detect sub applications
290 0 my $subapphash;
291 0 foreach my $key ( sort keys %$apphash ) {
292 0 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 0 0 0
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 0 ▶ if ( scalar keys %$subapphash > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$subapphash > 0) 0 0 0
300 0 foreach my $appkey (
301 sort {
302 ( $subapphash->{$a}->{order} || 0 )
303 0 ▶ <=> ( $subapphash->{$b}->{order} || 0 )
Branch: 1 branch
BranchTrueFalseTotal
($subapphash->{$a}{"order"} || 0) <=> ($subapphash->{$b}{"order"} || 0) or $a cmp $b 0 0 0
Condition0%0/4
$subapphash->{$a}{'order'} || 0
l!l
00
$subapphash->{$b}{'order'} || 0
l!l
00
MC/DC0%0/1
$subapphash->{$a}{'order'} || 0
$subapphash->{$a}{'order'}
MC/DC0%0/1
$subapphash->{$b}{'order'} || 0
$subapphash->{$b}{'order'}
Truth table0%0/2
A
A= $subapphash->{$a}{'order'}
Aresult
11
00
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 0 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 0 ▶ $applicationHash->{applications} = $applications if $applications;
Branch: 1 branch
BranchTrueFalseTotal
if $applications 0 0 0
325 0 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 sub _filter {
335 0 ▶ my ( $self, $req, $apphash ) = @_;
Subroutine _filter: not called CC=2 SCAR=17.9
336 0 my $filteredHash;
337 my $key;
338  
339 # Copy hash reference into a new hash
340 0 foreach $key ( keys %$apphash ) {
341 0 $filteredHash->{$key} = $apphash->{$key};
342 }
343  
344 # Filter hash
345 0 $self->_filterHash( $req, $filteredHash );
346  
347 # Hide empty categories
348 0 $self->_isCategoryEmpty($filteredHash);
349  
350 0 return $filteredHash;
351 }
352  
353 ## @method private string _filterHash(hashref apphash)
354 # Remove unauthorized menu elements
355 # @param $apphash Menu elements
356 # @return filtered hash
357 sub _filterHash {
358 0 ▶ my ( $self, $req, $apphash ) = @_;
Subroutine _filterHash: not called CC=21 SCAR=61.4
359  
360 0 foreach my $key ( keys %$apphash ) {
361 0 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 0 0 0
362 0 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category") 0 0 0
Condition0%0/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
!ll&&!rl&&r
000
MC/DC0%0/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "category"
Truth table0%0/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "category"
ABresult
0X0
100
111
363 and $apphash->{$key}->{type} eq "category" )
364 {
365  
366 # Filter the category
367 0 $self->_filterHash( $req, $apphash->{$key} );
368 }
369 0 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application") 0 0 0
Condition0%0/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application"
!ll&&!rl&&r
000
MC/DC0%0/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "application"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "application"
Truth table0%0/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "application"
ABresult
0X0
100
111
370 and $apphash->{$key}->{type} eq "application" )
371 {
372  
373 # Find sub applications and filter them
374 0 foreach my $appkey ( keys %{ $apphash->{$key} } ) {
375 0 ▶ next if $appkey =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $appkey =~ /(type|options|catname|order)/ 0 0 0
376  
377 # We have sub elements, so we filter them
378 0 $self->_filterHash( $req, $apphash->{$key} );
379 }
380  
381 # Check rights
382 my $appdisplay = $apphash->{$key}->{options}->{display}
383 0 ▶ || "auto";
Condition0%0/2
$apphash->{$key}{'options'}{'display'} || 'auto'
l!l
00
MC/DC0%0/1
$apphash->{$key}{'options'}{'display'} || 'auto'
$apphash->{$key}{'options'}{'display'}
Truth table0%0/2
A
A= $apphash->{$key}{'options'}{'display'}
Aresult
11
00
384 0 $apphash->{$key}->{options}->{uri} =~ URIRE;
385 0 my ( $vhost, $appuri ) = ( $3, $5 );
386 0 $vhost = $self->p->HANDLER->resolveAlias($vhost);
387 0 ▶ $appuri ||= '/';
Condition0%0/2
$appuri ||= "/"
l!l
00
MC/DC0%0/1
$appuri ||= "/"
$appuri
Truth table0%0/2
A
A= $appuri
Aresult
11
00
388  
389 # Remove if display is "no" or "off"
390 0 ▶ delete $apphash->{$key} and next if ( $appdisplay =~ /^(no|off)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $appdisplay =~ /^(no|off)$/ 0 0 0
Condition0%0/5
$appdisplay =~ /^(no|off)$/ && (delete $apphash->{$key} && (next))
!ll&&!rl&&r
000
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 table0%0/3
A && B
A= $appdisplay =~ /^(no|off)$/B= delete $apphash->{$key}
ABresult
0X0
100
111
391  
392 # Keep node if display is "yes" or "on"
393 0 ▶ next if ( $appdisplay =~ /^(yes|on)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $appdisplay =~ /^(yes|on)$/ 0 0 0
394  
395 0 my $cond = undef;
396  
397 # Handle partner rules (SAML, CAS or OIDC)
398 0 ▶ if ( $appdisplay =~ /^sp:\s*(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($appdisplay =~ /^sp:\s*(.*)$/) 0 0 0
399 0 my $p = $1;
400 0 ▶ if ( my $sub = $self->p->spRules->{$p} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->p->spRules->{$p}) 0 0 0
401 0 eval {
402 0 ▶ delete $apphash->{$key}
Branch: 1 branch
BranchTrueFalseTotal
unless &$sub($req, $req->userData) 0 0 0
403 unless ( $sub->( $req, $req->userData ) );
404 };
405 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
406 0 $self->logger->error("Partner rule $p returns: $@");
407 }
408 }
409 0 next;
410 }
411  
412 # If a specific rule exists, get it from cache or compile it
413 0 ▶ if ( $appdisplay !~ /^auto$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($appdisplay =~ /^auto$/i) 0 0 0
414 0 ▶ if ( $self->specific->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->specific->{$key}) { } 0 0 0
415 0 $cond = $self->specific->{$key};
416 }
417 else {
418 0 $cond = $self->specific->{$key} =
419 $self->p->HANDLER->buildSub(
420 $self->p->HANDLER->substitute($appdisplay) );
421 }
422 }
423  
424 # Check grant function if display is "auto" (this is the default)
425 0 ▶ delete $apphash->{$key}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->p->HANDLER->grant($req, $req->userData, $appuri, $cond, $vhost) 0 0 0
426 unless (
427 $self->p->HANDLER->grant(
428 $req, $req->userData, $appuri, $cond, $vhost
429 )
430 );
431 0 next;
432 }
433 }
434  
435 }
436  
437 ## @method private void _isCategoryEmpty(hashref apphash)
438 # Check if a category is empty
439 # @param $apphash Menu elements
440 # @return boolean
441 sub _isCategoryEmpty {
442 0 ▶ my $self = shift;
Subroutine _isCategoryEmpty: not called CC=9 SCAR=45.0
443 0 my ($apphash) = @_;
444 0 my $key;
445  
446 # Test sub categories
447 0 foreach $key ( keys %$apphash ) {
448 0 ▶ next if $key =~ /(type|options|catname|order)/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /(type|options|catname|order)/ 0 0 0
449 0 ▶ if ( $apphash->{$key}->{type}
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category") 0 0 0
Condition0%0/3
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
!ll&&!rl&&r
000
MC/DC0%0/2
$apphash->{$key}{"type"} and $apphash->{$key}{"type"} eq "category"
$apphash->{$key}{"type"} $apphash->{$key}{"type"} eq "category"
Truth table0%0/3
A and B
A= $apphash->{$key}{"type"}B= $apphash->{$key}{"type"} eq "category"
ABresult
0X0
100
111
450 and $apphash->{$key}->{type} eq "category" )
451 {
452 delete $apphash->{$key}
453 0 ▶ if $self->_isCategoryEmpty( $apphash->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_isCategoryEmpty($apphash->{$key}) 0 0 0
454 }
455 }
456  
457 # Test this category
458 0 ▶ if ( $apphash->{type} and $apphash->{type} eq "category" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apphash->{"type"} and $apphash->{"type"} eq "category") 0 0 0
Condition0%0/3
$apphash->{"type"} and $apphash->{"type"} eq "category"
!ll&&!rl&&r
000
MC/DC0%0/2
$apphash->{"type"} and $apphash->{"type"} eq "category"
$apphash->{"type"} $apphash->{"type"} eq "category"
Truth table0%0/3
A and B
A= $apphash->{"type"}B= $apphash->{"type"} eq "category"
ABresult
0X0
100
111
459  
460 # Temporary store 'options'
461 0 my $tmp_options = $apphash->{options};
462 0 my $tmp_catname = $apphash->{catname};
463 0 my $tmp_order = $apphash->{order};
464  
465 0 delete $apphash->{type};
466 0 delete $apphash->{options};
467 0 delete $apphash->{catname};
468 0 delete $apphash->{order};
469  
470 0 ▶ if ( scalar( keys %$apphash ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$apphash) { } 0 0 0
471  
472 # There are sub categories or sub applications
473 # Restore type and options
474 0 $apphash->{type} = "category";
475 0 $apphash->{options} = $tmp_options;
476 0 $apphash->{catname} = $tmp_catname;
477 0 $apphash->{order} = $tmp_order;
478  
479 # Return false
480 0 return 0;
481 }
482 else {
483  
484 # Return true
485 0 return 1;
486 }
487 }
488 0 return 0;
489 }
490  
491 sub _register_tab {
492 0 ▶ my ( $self, $plugin ) = @_;
Subroutine _register_tab: not called CC=4 SCAR=30.0
493  
494 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
495 0 my $name = $plugin->name;
496  
497 0 ▶ if ( !$name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 0 0
498 0 $self->logger->warn("Could not load custom menu tab: missing name");
499 0 return;
500 }
501  
502 0 my $compiled_rule =
503 $self->p->buildRule( $rule_text, "Rule for $name custom tab" );
504 0 ▶ if ( !$compiled_rule ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compiled_rule) 0 0 0
505 0 return;
506 }
507  
508 0 push @{ $self->menuModules }, [ $name, $compiled_rule, $plugin ];
509  
510 # Sort menuModules array
511 0 @{ $self->menuModules } = $self->_sort_menu( $self->menuModules,
512 0 $self->conf->{portalDisplayOrder} );
513 0 return;
514 }
515  
516 # This function does the sorting work and should be easy to test
517 sub _sort_menu {
518 0 ▶ my ( $self, $menuToSort, $displayOrderString ) = @_;
Subroutine _sort_menu: not called CC=2 SCAR=17.9
519  
520 0 my @order = $self->_get_display_order($displayOrderString);
521 0 my $orderhash;
522 0 @$orderhash{@order} = 1 .. @order;
523  
524 # If the position of unknown plugins was not specified, put them at the end
525 0 ▶ $orderhash->{_unknown} //= @order + 1;
Condition0%0/3
$orderhash->{"_unknown"} //= @order + 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$orderhash->{"_unknown"} //= @order + 1
$orderhash->{"_unknown"} @order + 1
Truth table0%0/3
A //= B
A= $orderhash->{"_unknown"}B= @order + 1
ABresult
1X1
011
000
526  
527 0 return sort { _sort_menu_helper( $orderhash, $a, $b ) } @$menuToSort;
528 }
529  
530 # Sort helper based on portalDisplayOrder
531 # orderhash is a name => position hash
532 # You can use "_unknown" in portalDisplayOrder as a placeholder for plugins of unknown position
533 sub _sort_menu_helper {
534 0 ▶ my ( $orderhash, $a, $b ) = @_;
Subroutine _sort_menu_helper: not called CC=5 SCAR=34.0
535  
536 return ( $orderhash->{ $a->[0] } || $orderhash->{_unknown} || 0 )
537 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
538 }
539  
540 sub _get_display_order {
541 0 ▶ my ( $self, $displayOrderString ) = @_;
Subroutine _get_display_order: not called CC=1 SCAR=6.9
542 0 my %hash;
543 0 return grep { !$hash{$_}++ } split /[,\s]+/, $displayOrderString,;
544 }
545  
546 429 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/CheckState.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/SAML.pm »