« blib/lib/Lemonldap/NG/Manager/Api/Providers/OidcRp.pm
↑ Summary
blib/lib/Lemonldap/NG/Manager/Build/Attributes.pm »
| 1 | package Lemonldap::NG::Manager::Api::Menu::App; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 28 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | package Lemonldap::NG::Manager::Api; | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 28 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Lemonldap::NG::Manager::Conf::Parser; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 28 | extends 'Lemonldap::NG::Manager::Api::Common'; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 22 | ▶ | sub getMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
getMenuApp: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 15 | 22 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 22 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 18 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 22 | my $appConfKey = $req->params('appConfKey'); | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 23 | 22 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | # Check if catConfKey is defined | ||||||||||||||||||||||||||||||||||
| 26 | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||||
| 27 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 28 | 22 | ▶ | unless ( defined $conf->{applicationList}->{$catConfKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 20 | ▶ | if ( defined $appConfKey ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # Return one application referenced with this appConfKey | ||||||||||||||||||||||||||||||||||
| 33 | 17 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 34 | "[API] Menu application $appConfKey from category $catConfKey configuration requested" | ||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 17 | my $menuApp = | |||||||||||||||||||||||||||||||||
| 38 | $self->_getMenuAppByConfKey( $conf, $catConfKey, $appConfKey ); | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | # Return 404 if not found | ||||||||||||||||||||||||||||||||||
| 41 | 17 | ▶ | return $self->sendError( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | $req, | ||||||||||||||||||||||||||||||||||
| 43 | "Menu application '$appConfKey' from category '$catConfKey' not found", | ||||||||||||||||||||||||||||||||||
| 44 | 404 | ||||||||||||||||||||||||||||||||||
| 45 | ) unless ( defined $menuApp ); | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 16 | return $self->sendJSONresponse( $req, $menuApp ); | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | # Return all applications for this category | ||||||||||||||||||||||||||||||||||
| 53 | 3 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 54 | "[API] Menu applications from category $catConfKey configuration requested" | ||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 3 | my $cat = $conf->{applicationList}->{$catConfKey}; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | my @menuApps = | ||||||||||||||||||||||||||||||||||
| 60 | map { | ||||||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | $self->_isCatApp( $cat->{$_} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | ? $self->_getMenuAppByConfKey( $conf, $catConfKey, $_ ) | ||||||||||||||||||||||||||||||||||
| 63 | : () | ||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | 3 | keys %{$cat}; | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 3 | return $self->sendJSONresponse( $req, [@menuApps] ); | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub findMenuAppByConfKey { | ||||||||||||||||||||||||||||||||
|
Subroutine
findMenuAppByConfKey: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 73 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 76 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | my $pattern = ( | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 79 | defined $req->params('uPattern') | ||||||||||||||||||||||||||||||||||
| 80 | ? $req->params('uPattern') | ||||||||||||||||||||||||||||||||||
| 81 | : ( defined $req->params('pattern') ? $req->params('pattern') : undef ) | ||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | return $self->sendError( $req, 'Invalid input: pattern is missing', 400 ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | unless ( defined $pattern ); | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | unless ( $pattern = $self->_getRegexpFromPattern($pattern) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | 2 | return $self->sendError( $req, 'Invalid input: pattern is invalid', | |||||||||||||||||||||||||||||||||
| 89 | 400 ); | ||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | $self->logger->debug( | ||||||||||||||||||||||||||||||||||
| 93 | 2 | "[API] Find Menu Applications from category $catConfKey by confKey regexp $pattern requested" | |||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 97 | 2 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | # Check if catConfKey is defined | ||||||||||||||||||||||||||||||||||
| 100 | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||||
| 101 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | unless ( defined $conf->{applicationList}->{$catConfKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 2 | my $cat = $conf->{applicationList}->{$catConfKey}; | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | my @menuApps = | ||||||||||||||||||||||||||||||||||
| 107 | map { | ||||||||||||||||||||||||||||||||||
| 108 | 10 | ▶ | $self->_isCatApp( $cat->{$_} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_isCatApp($cat->{$_}) and $_ =~ /$pattern/
MC/DC100%2/2
$self->_isCatApp($cat->{$_}) and $_ =~ /$pattern/
$self->_isCatApp($cat->{$_})
$_ =~ /$pattern/
Truth table100%3/3
A and B
A= $self->_isCatApp($cat->{$_})B= $_ =~ /$pattern/
| |||||||||||||||||||||||||||||||||||
| 109 | && $_ =~ $pattern | ||||||||||||||||||||||||||||||||||
| 110 | ? $self->_getMenuAppByConfKey( $conf, $catConfKey, $_ ) | ||||||||||||||||||||||||||||||||||
| 111 | : () | ||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | 2 | keys %{$cat}; | |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 2 | return $self->sendJSONresponse( $req, [@menuApps] ); | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub addMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
addMenuApp: called CC=12 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 119 | 6 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 120 | 6 | my $add = $req->jsonBodyToObj; | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 6 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 6 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | unless ($add); | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | return $self->sendError( $req, 'Invalid input: confKey is missing', 400 ) | ||||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | unless ( defined $add->{confKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | return $self->sendError( $req, 'Invalid input: confKey is not a string', | ||||||||||||||||||||||||||||||||||
| 132 | 400 ) | ||||||||||||||||||||||||||||||||||
| 133 | 6 | ▶ | if ( ref $add->{confKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||||
| 136 | 'Invalid input: confKey contains invalid characters', 400 ) | ||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | unless ( $add->{confKey} =~ '^\w[\w\.\-]*$' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | return $self->sendError( $req, 'Invalid input: name is missing', 400 ) | ||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | unless ( defined $add->{options} && defined $add->{options}{name} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $add->{"options"} and defined $add->{"options"}{"name"}
MC/DC0%0/2
defined $add->{"options"} and defined $add->{"options"}{"name"}
defined $add->{"options"}
defined $add->{"options"}{"name"}
Truth table33%1/3
A and B
A= defined $add->{"options"}B= defined $add->{"options"}{"name"}
| |||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | return $self->sendError( $req, 'Invalid input: name is not a string', 400 ) | ||||||||||||||||||||||||||||||||||
| 143 | 5 | ▶ | if ( ref $add->{options}{name} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 5 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 146 | "[API] Add Menu Application from category $catConfKey with confKey $add->{confKey} requested" | ||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 150 | 5 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | # Check if catConfKey is defined | ||||||||||||||||||||||||||||||||||
| 153 | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||||
| 154 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 155 | 5 | ▶ | unless ( defined $conf->{applicationList}->{$catConfKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | return $self->sendError( | ||||||||||||||||||||||||||||||||||
| 158 | $req, | ||||||||||||||||||||||||||||||||||
| 159 | "Invalid input: A Menu Application with confKey $add->{confKey} already exists in category $catConfKey", | ||||||||||||||||||||||||||||||||||
| 160 | 409 | ||||||||||||||||||||||||||||||||||
| 161 | ) | ||||||||||||||||||||||||||||||||||
| 162 | if ( | ||||||||||||||||||||||||||||||||||
| 163 | defined $self->_getMenuAppByConfKey( $conf, $catConfKey, | ||||||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | $add->{confKey} ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | my $res = | ||||||||||||||||||||||||||||||||||
| 167 | 3 | $self->_pushMenuApp( $conf, $catConfKey, $add->{confKey}, $add, 1 ); | |||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 3 | return $self->sendJSONresponse( | |||||||||||||||||||||||||||||||||
| 173 | $req, | ||||||||||||||||||||||||||||||||||
| 174 | { message => "Successful operation" }, | ||||||||||||||||||||||||||||||||||
| 175 | code => 201 | ||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | sub updateMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
updateMenuApp: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 180 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 183 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | my $appConfKey = $req->params('appConfKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 186 | or return $self->sendError( $req, 'Application confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 3 | my $update = $req->jsonBodyToObj; | |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 191 | unless ($update); | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 3 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 194 | "[API] Menu application $appConfKey from category $catConfKey configuration update requested" | ||||||||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 198 | 3 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | # Return 404 if not found | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 204 | unless ( defined $self->_getMenuCatByConfKey( $conf, $catConfKey ) ); | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | return $self->sendError( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 207 | $req, | ||||||||||||||||||||||||||||||||||
| 208 | "Menu application '$appConfKey' from category '$catConfKey' not found", | ||||||||||||||||||||||||||||||||||
| 209 | 404 | ||||||||||||||||||||||||||||||||||
| 210 | ) | ||||||||||||||||||||||||||||||||||
| 211 | unless ( | ||||||||||||||||||||||||||||||||||
| 212 | defined $self->_getMenuAppByConfKey( $conf, $catConfKey, $appConfKey ) | ||||||||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 1 | my $res = | |||||||||||||||||||||||||||||||||
| 216 | $self->_pushMenuApp( $conf, $catConfKey, $appConfKey, $update, 0 ); | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 1 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | sub replaceMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
replaceMenuApp: called CC=13 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 225 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | 3 | ▶ | my $appConfKey = $req->params('appConfKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 230 | or return $self->sendError( $req, 'Application confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | 3 | my $replace = $req->jsonBodyToObj; | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | 3 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | unless ($replace); | ||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | return $self->sendError( $req, 'Invalid input: confKey is missing', 400 ) | ||||||||||||||||||||||||||||||||||
| 238 | 3 | ▶ | unless ( defined $replace->{confKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | return $self->sendError( $req, 'Invalid input: confKey is not a string', | ||||||||||||||||||||||||||||||||||
| 241 | 400 ) | ||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | if ( ref $replace->{confKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||||
| 245 | 'Invalid input: confKey contains invalid characters', 400 ) | ||||||||||||||||||||||||||||||||||
| 246 | 3 | ▶ | unless ( $replace->{confKey} =~ '^\w[\w\.\-]*$' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||
| 248 | return $self->sendError( $req, 'Invalid input: name is missing', 400 ) | ||||||||||||||||||||||||||||||||||
| 249 | unless ( defined $replace->{options} | ||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | && defined $replace->{options}{name} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $replace->{"options"} and defined $replace->{"options"}{"name"}
MC/DC0%0/2
defined $replace->{"options"} and defined $replace->{"options"}{"name"}
defined $replace->{"options"}
defined $replace->{"options"}{"name"}
Truth table33%1/3
A and B
A= defined $replace->{"options"}B= defined $replace->{"options"}{"name"}
| |||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | return $self->sendError( $req, 'Invalid input: name is not a string', 400 ) | ||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | if ( ref $replace->{options}{name} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||
| 255 | 3 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 256 | "[API] Menu application $appConfKey from category $catConfKey configuration replace requested" | ||||||||||||||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 260 | 3 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | # Return 404 if not found | ||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | 3 | ▶ | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 265 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 266 | unless ( defined $self->_getMenuCatByConfKey( $conf, $catConfKey ) ); | ||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | return $self->sendError( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 269 | $req, | ||||||||||||||||||||||||||||||||||
| 270 | "Menu application '$appConfKey' from category '$catConfKey' not found", | ||||||||||||||||||||||||||||||||||
| 271 | 404 | ||||||||||||||||||||||||||||||||||
| 272 | ) | ||||||||||||||||||||||||||||||||||
| 273 | unless ( | ||||||||||||||||||||||||||||||||||
| 274 | defined $self->_getMenuAppByConfKey( $conf, $catConfKey, $appConfKey ) | ||||||||||||||||||||||||||||||||||
| 275 | ); | ||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | 1 | my $res = | |||||||||||||||||||||||||||||||||
| 278 | $self->_pushMenuApp( $conf, $catConfKey, $appConfKey, $replace, 1 ); | ||||||||||||||||||||||||||||||||||
| 279 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | 1 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | 2 | ▶ | sub deleteMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
deleteMenuApp: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 286 | 2 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | my $catConfKey = $req->params('confKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | or return $self->sendError( $req, 'Category confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 2 | ▶ | my $appConfKey = $req->params('appConfKey') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 292 | or return $self->sendError( $req, 'Application confKey is missing', 400 ); | ||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | 2 | $self->logger->debug( | |||||||||||||||||||||||||||||||||
| 295 | "[API] Menu Application $appConfKey from category $catConfKey configuration delete requested" | ||||||||||||||||||||||||||||||||||
| 296 | ); | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | # Get latest configuration | ||||||||||||||||||||||||||||||||||
| 299 | 2 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | "Menu category '$catConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 303 | unless ( defined $self->_getMenuCatByConfKey( $conf, $catConfKey ) ); | ||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | 2 | my $delete = $self->_getMenuAppByConfKey( $conf, $catConfKey, $appConfKey ); | |||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | # Return 404 if not found | ||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | return $self->sendError( $req, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 310 | "Menu category '$appConfKey' not found", 404 ) | ||||||||||||||||||||||||||||||||||
| 311 | unless ( defined $delete ); | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | 1 | delete $conf->{applicationList}->{$catConfKey}->{$appConfKey}; | |||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | # Save configuration | ||||||||||||||||||||||||||||||||||
| 316 | 1 | $self->_saveApplyConf($conf); | |||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 1 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 22 | ▶ | sub _isCatApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
_isCatApp: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||
| 322 | 22 | my ( $self, $candidate ) = @_; | |||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||
| 324 | # Check if candidate is a hash, has "type" defined and if "type" equals "application". | ||||||||||||||||||||||||||||||||||
| 325 | return | ||||||||||||||||||||||||||||||||||
| 326 | ref $candidate eq ref {} | ||||||||||||||||||||||||||||||||||
| 327 | && defined $candidate->{type} | ||||||||||||||||||||||||||||||||||
| 328 | 22 | ▶ | && $candidate->{type} eq 'application'; | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
ref $candidate eq ref {} && defined $candidate->{'type'} && $candidate->{'type'} eq 'application'
ref $candidate eq ref {} and defined $candidate->{"type"}
MC/DC33%1/3
ref $candidate eq ref {} && defined $candidate->{'type'} && $candidate->{'type'} eq 'application'
ref $candidate eq ref {}
defined $candidate->{"type"}
$candidate->{'type'} eq 'application'
Truth table50%2/4
A and B && C
A= ref $candidate eq ref {}B= defined $candidate->{"type"}C= $candidate->{'type'} eq 'application'
| |||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | 34 | ▶ | sub _getMenuAppByConfKey { | ||||||||||||||||||||||||||||||||
|
Subroutine
_getMenuAppByConfKey: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||
| 332 | 34 | my ( $self, $conf, $catConfKey, $appConfKey ) = @_; | |||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | # Check if catConfKey is defined | ||||||||||||||||||||||||||||||||||
| 335 | 34 | ▶ | return undef unless ( defined $conf->{applicationList}->{$catConfKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | # Check if appConfKey is defined | ||||||||||||||||||||||||||||||||||
| 338 | return undef | ||||||||||||||||||||||||||||||||||
| 339 | 34 | ▶ | unless ( defined $conf->{applicationList}->{$catConfKey}->{$appConfKey} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | 27 | my $cat = $conf->{applicationList}->{$catConfKey}; | |||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | 27 | my $menuApp = { confKey => $appConfKey }; | |||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | $menuApp->{order} = $cat->{$appConfKey}->{order} | ||||||||||||||||||||||||||||||||||
| 346 | 27 | ▶ | if ( defined $cat->{$appConfKey}->{order} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||
| 348 | # Get options | ||||||||||||||||||||||||||||||||||
| 349 | 27 | my $options = {}; | |||||||||||||||||||||||||||||||||
| 350 | 27 | for my $configOption ( keys %{ $cat->{$appConfKey}->{options} } ) { | |||||||||||||||||||||||||||||||||
| 351 | $options->{ $self->_translateOptionConfToApi($configOption) } = | ||||||||||||||||||||||||||||||||||
| 352 | 162 | $cat->{$appConfKey}->{options}->{$configOption}; | |||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | 27 | $menuApp->{options} = $options; | |||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||
| 357 | 27 | return $menuApp; | |||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | 5 | ▶ | sub _pushMenuApp { | ||||||||||||||||||||||||||||||||
|
Subroutine
_pushMenuApp: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||
| 361 | 5 | my ( $self, $conf, $catConfKey, $appConfKey, $push, $replace ) = @_; | |||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||
| 363 | 5 | ▶ | if ($replace) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 364 | 4 | $conf->{applicationList}->{$catConfKey}->{$appConfKey} = {}; | |||||||||||||||||||||||||||||||||
| 365 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{type} = | ||||||||||||||||||||||||||||||||||
| 366 | 4 | "application"; | |||||||||||||||||||||||||||||||||
| 367 | 4 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{options} = {}; | |||||||||||||||||||||||||||||||||
| 368 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{options} | ||||||||||||||||||||||||||||||||||
| 369 | 4 | ->{display} = "auto"; | |||||||||||||||||||||||||||||||||
| 370 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{options} | ||||||||||||||||||||||||||||||||||
| 371 | 4 | ->{logo} = "network.png"; | |||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||
| 374 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{order} = | ||||||||||||||||||||||||||||||||||
| 375 | $push->{order} | ||||||||||||||||||||||||||||||||||
| 376 | 5 | ▶ | if ( defined $push->{order} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||
| 378 | 5 | ▶ | if ( defined $push->{options} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 379 | 5 | foreach ( keys %{ $push->{options} } ) { | |||||||||||||||||||||||||||||||||
| 380 | $conf->{applicationList}->{$catConfKey}->{$appConfKey}->{options} | ||||||||||||||||||||||||||||||||||
| 381 | 25 | ->{$_} = $push->{options}->{$_}; | |||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||
| 385 | # Test new configuration | ||||||||||||||||||||||||||||||||||
| 386 | 5 | my $parser = Lemonldap::NG::Manager::Conf::Parser->new( { | |||||||||||||||||||||||||||||||||
| 387 | refConf => $self->_confAcc->getConf( { noCache => 1 } ), | ||||||||||||||||||||||||||||||||||
| 388 | newConf => $conf, | ||||||||||||||||||||||||||||||||||
| 389 | req => {}, | ||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||
| 392 | 5 | ▶ | unless ( $parser->testNewConf( $self->p ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 393 | return { | ||||||||||||||||||||||||||||||||||
| 394 | res => 'ko', | ||||||||||||||||||||||||||||||||||
| 395 | code => 400, | ||||||||||||||||||||||||||||||||||
| 396 | msg => "Configuration error: " | ||||||||||||||||||||||||||||||||||
| 397 | 0 | . join( ". ", map { $_->{message} } @{ $parser->errors } ), | |||||||||||||||||||||||||||||||||
| 398 | }; | ||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | # Save configuration | ||||||||||||||||||||||||||||||||||
| 402 | 5 | $self->_saveApplyConf($conf); | |||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||
| 404 | 5 | return { res => 'ok' }; | |||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | 28 | 1; | |||||||||||||||||||||||||||||||||