Lemonldap-NG-Manager
view release on metacpan or search on metacpan
lib/Lemonldap/NG/Manager/Api/Menu/App.pm view on Meta::CPAN
my ( $self, $req ) = @_;
my $add = $req->jsonBodyToObj;
my $catConfKey = $req->params('confKey')
or return $self->sendError( $req, 'Category confKey is missing', 400 );
return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
unless ($add);
return $self->sendError( $req, 'Invalid input: confKey is missing', 400 )
unless ( defined $add->{confKey} );
return $self->sendError( $req, 'Invalid input: confKey is not a string',
400 )
if ( ref $add->{confKey} );
return $self->sendError( $req,
'Invalid input: confKey contains invalid characters', 400 )
unless ( $add->{confKey} =~ '^\w[\w\.\-]*$' );
return $self->sendError( $req, 'Invalid input: name is missing', 400 )
unless ( defined $add->{options} && defined $add->{options}{name} );
return $self->sendError( $req, 'Invalid input: name is not a string', 400 )
if ( ref $add->{options}{name} );
$self->logger->debug(
"[API] Add Menu Application from category $catConfKey with confKey $add->{confKey} requested"
);
# Get latest configuration
my $conf = $self->_confAcc->getConf( { noCache => 1 } );
# Check if catConfKey is defined
return $self->sendError( $req,
"Menu category '$catConfKey' not found", 404 )
unless ( defined $conf->{applicationList}->{$catConfKey} );
return $self->sendError(
$req,
"Invalid input: A Menu Application with confKey $add->{confKey} already exists in category $catConfKey",
409
)
if (
defined $self->_getMenuAppByConfKey( $conf, $catConfKey,
$add->{confKey} ) );
my $res =
$self->_pushMenuApp( $conf, $catConfKey, $add->{confKey}, $add, 1 );
return $self->sendError( $req, $res->{msg}, $res->{code} || 400 )
unless ( $res->{res} eq 'ok' );
return $self->sendJSONresponse(
$req,
{ message => "Successful operation" },
code => 201
);
}
sub updateMenuApp {
my ( $self, $req ) = @_;
my $catConfKey = $req->params('confKey')
or return $self->sendError( $req, 'Category confKey is missing', 400 );
my $appConfKey = $req->params('appConfKey')
or return $self->sendError( $req, 'Application confKey is missing', 400 );
my $update = $req->jsonBodyToObj;
return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
unless ($update);
$self->logger->debug(
"[API] Menu application $appConfKey from category $catConfKey configuration update requested"
);
# Get latest configuration
my $conf = $self->_confAcc->getConf( { noCache => 1 } );
# Return 404 if not found
return $self->sendError( $req,
"Menu category '$catConfKey' not found", 404 )
unless ( defined $self->_getMenuCatByConfKey( $conf, $catConfKey ) );
return $self->sendError(
$req,
"Menu application '$appConfKey' from category '$catConfKey' not found",
404
)
unless (
defined $self->_getMenuAppByConfKey( $conf, $catConfKey, $appConfKey )
);
my $res =
$self->_pushMenuApp( $conf, $catConfKey, $appConfKey, $update, 0 );
return $self->sendError( $req, $res->{msg}, $res->{code} || 400 )
unless ( $res->{res} eq 'ok' );
return $self->sendJSONresponse( $req, undef, code => 204 );
}
sub replaceMenuApp {
my ( $self, $req ) = @_;
my $catConfKey = $req->params('confKey')
or return $self->sendError( $req, 'Category confKey is missing', 400 );
my $appConfKey = $req->params('appConfKey')
or return $self->sendError( $req, 'Application confKey is missing', 400 );
my $replace = $req->jsonBodyToObj;
return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
unless ($replace);
return $self->sendError( $req, 'Invalid input: confKey is missing', 400 )
unless ( defined $replace->{confKey} );
( run in 2.804 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )