| 1 | package CallBackery::Controller::RpcService; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use Mojo::Base qw(Mojolicious::Plugin::Qooxdoo::JsonRpcController), | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | -signatures,-async_await; | |||||||||||||||||||||||||||
| 5 | 11 | ▶ | use CallBackery::Exception qw(mkerror); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use CallBackery::Translate qw(trm); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Mojo::JSON qw(encode_json decode_json from_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # RPC error code the qooxdoo frontend maps to "session expired -> reload". | ||||||||||||||||||||||||||||
| 12 | # Distinct from code 6 ("login required -> show login dialog"). | ||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use constant RPC_SESSION_EXPIRED => 7; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | CallBackery::RpcService - RPC services for CallBackery | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | This module gets instantiated by L<CallBackery> and provides backend | ||||||||||||||||||||||||||||
| 22 | functionality. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | This module provides the following methods | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # the name of the service we provide | ||||||||||||||||||||||||||||
| 31 | 11 | has service => 'default'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 allow_rpc_access(method) | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Decide whether the current request may invoke C<$method>. Returns C<1> when | ||||||||||||||||||||||||||||
| 36 | access is granted and C<0> when it is refused (the dispatcher turns a C<0> into a | ||||||||||||||||||||||||||||
| 37 | code 6 "access denied" reply, which the frontend maps to the login dialog). When | ||||||||||||||||||||||||||||
| 38 | access is refused specifically because a previously valid session has expired, | ||||||||||||||||||||||||||||
| 39 | this instead C<die>s a code 7 (C<RPC_SESSION_EXPIRED>) exception so the frontend | ||||||||||||||||||||||||||||
| 40 | can prompt a reload rather than a fresh login. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | The rules are evaluated in order: | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =over | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item * | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Non-C<POST> requests are refused (C<return 0>). | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item * | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Methods not listed in C<%allow> are refused (C<return 0>). | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =item * | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Public methods (C<%allow> level C<1>) are always allowed. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item * | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Any authenticated user is allowed. Reading C<isUserAuthenticated> forces the | ||||||||||||||||||||||||||||
| 61 | session cookie to be evaluated, which is also what sets C<sessionExpired> on the | ||||||||||||||||||||||||||||
| 62 | user object. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item * | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Level C<3> methods are additionally allowed for an unauthenticated user when the | ||||||||||||||||||||||||||||
| 67 | target plugin opts into anonymous access (C<mayAnonymous>). The plugin | ||||||||||||||||||||||||||||
| 68 | instantiation is wrapped in C<eval>, because instantiating a plugin as an | ||||||||||||||||||||||||||||
| 69 | unauthenticated user commonly dies (plugins read user rights/config); such a | ||||||||||||||||||||||||||||
| 70 | death resolves to "not anonymous" here and must never escape as a generic | ||||||||||||||||||||||||||||
| 71 | code 9999 error. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item * | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Otherwise the method requires authentication the user does not have: if the | ||||||||||||||||||||||||||||
| 76 | user's session has merely expired, C<die> a C<RPC_SESSION_EXPIRED> (code 7) | ||||||||||||||||||||||||||||
| 77 | exception; otherwise C<return 0> for the ordinary login-required path. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =back | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 11 | my %allow = ( | |||||||||||||||||||||||||||
| 84 | getBaseConfig => 1, | ||||||||||||||||||||||||||||
| 85 | login => 1, | ||||||||||||||||||||||||||||
| 86 | logout => 1, | ||||||||||||||||||||||||||||
| 87 | ping => 1, | ||||||||||||||||||||||||||||
| 88 | getUserConfig => 2, | ||||||||||||||||||||||||||||
| 89 | getPluginConfig => 3, | ||||||||||||||||||||||||||||
| 90 | validatePluginData => 3, | ||||||||||||||||||||||||||||
| 91 | processPluginData => 3, | ||||||||||||||||||||||||||||
| 92 | getPluginData => 3, | ||||||||||||||||||||||||||||
| 93 | getSessionCookie => 2 | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 9 | ▶ | has config => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | 9 | $self->app->config; | |||||||||||||||||||||||||||
| 98 | 11 | }, weak => 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 8 | ▶ | has user => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 8 | my $obj = $self->app->userObject->new(app=>$self->app,controller=>$self,log=>$self->log); | |||||||||||||||||||||||||||
| 102 | 8 | return $obj; | |||||||||||||||||||||||||||
| 103 | 11 | }; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | has pluginMap => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 2 | my $map = $self->config->cfgHash->{PLUGIN}; | |||||||||||||||||||||||||||
| 107 | 2 | return $map; | |||||||||||||||||||||||||||
| 108 | 11 | }, weak => 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 16 | ▶ | sub allow_rpc_access ($self,$method) { | ||||||||||||||||||||||||||
|
Subroutine
allow_rpc_access: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 16 | ▶ | if (not $self->req->method eq 'POST') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | # sorry we do not allow GET requests | ||||||||||||||||||||||||||||
| 114 | 0 | $self->log->error("refused ".$self->req->method." request"); | |||||||||||||||||||||||||||
| 115 | 0 | return 0; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 16 | ▶ | if (not exists $allow{$method}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 1 | return 0; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 15 | for ($allow{$method}){ | |||||||||||||||||||||||||||
| 121 | 15 | ▶ | /1/ && return 1; # public method | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 10 | ▶ | return 1 if ($self->user->isUserAuthenticated); # forces cookieConf (sets sessionExpired) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 4 | ▶ | /3/ && do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | # Level-3: allowed only for plugins that opt into anonymous access. | ||||||||||||||||||||||||||||
| 125 | # Guard the instantiation: for an unauthenticated user it commonly | ||||||||||||||||||||||||||||
| 126 | # dies (plugins read user rights/config); that death must resolve to | ||||||||||||||||||||||||||||
| 127 | # "not anonymous" here, never escape as a generic code-9999 popup. | ||||||||||||||||||||||||||||
| 128 | 2 | my $plugin = $self->rpcParams->[0]; | |||||||||||||||||||||||||||
| 129 | 2 | my $anon = eval { | |||||||||||||||||||||||||||
| 130 | 2 | $self->config->instantiatePlugin($plugin,$self->user)->mayAnonymous | |||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||
| 132 | 2 | ▶ | return 1 if $anon; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||
| 134 | # Method needs auth and the user is not authenticated. If a session was | ||||||||||||||||||||||||||||
| 135 | # present and merely expired, signal that distinctly (code 7 -> reload); | ||||||||||||||||||||||||||||
| 136 | # otherwise fall through to code 6 (login dialog). | ||||||||||||||||||||||||||||
| 137 | 4 | ▶ | die mkerror(RPC_SESSION_EXPIRED, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | trm('Your session has expired. Please reload to log in.')) | ||||||||||||||||||||||||||||
| 139 | if $self->user->sessionExpired; | ||||||||||||||||||||||||||||
| 140 | 2 | last; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 2 | return 0; | |||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 1 | ▶ | has passMatch => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | 1 | qr{(?i)(?:password|_pass)}; | |||||||||||||||||||||||||||
| 147 | 11 | }; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 5 | ▶ | sub perMethodCleaner ($self,$method=undef) { | ||||||||||||||||||||||||||
|
Subroutine
perMethodCleaner: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 150 | 5 | ▶ | $method or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | return { | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | login => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 153 | 1 | my $data = shift; | |||||||||||||||||||||||||||
| 154 | 1 | ▶ | if (ref $data eq 'ARRAY'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 1 | $data->[1] = 'xxx'; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 1 | return; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | 2 | }->{$method}; | |||||||||||||||||||||||||||
| 160 | }; | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 5 | ▶ | sub dataCleaner ($self,$data,$method=undef) { | ||||||||||||||||||||||||||
|
Subroutine
dataCleaner: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 5 | ▶ | if (my $perMethodCleaner = $self->perMethodCleaner($method)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 1 | return $perMethodCleaner->($data); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 4 | my $match = $self->passMatch; | |||||||||||||||||||||||||||
| 168 | 4 | my $type = ref $data; | |||||||||||||||||||||||||||
| 169 | 4 | for ($type) { | |||||||||||||||||||||||||||
| 170 | 4 | ▶ | /ARRAY/ && do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 1 | $self->dataCleaner($_) for @$data; | |||||||||||||||||||||||||||
| 172 | }; | ||||||||||||||||||||||||||||
| 173 | 4 | ▶ | /HASH/ && do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 3 | for my $key (keys %$data) { | |||||||||||||||||||||||||||
| 175 | 5 | my $value = $data->{$key}; | |||||||||||||||||||||||||||
| 176 | 5 | ▶ | if ($key =~ /$match/){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 177 | 1 | $data->{$key} = 'xxx'; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | elsif (ref $value){ | ||||||||||||||||||||||||||||
| 180 | 1 | $self->dataCleaner($value); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =head2 logRpcCall | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Set CALLBACKERY_RPC_LOG for extensive logging messages. Note that all | ||||||||||||||||||||||||||||
| 190 | values with keys matching /password|_pass/ do get replaced with 'xxx' | ||||||||||||||||||||||||||||
| 191 | in the output. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # our own logging | ||||||||||||||||||||||||||||
| 196 | 10 | ▶ | sub logRpcCall { | ||||||||||||||||||||||||||
|
Subroutine
logRpcCall: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 198 | 10 | ▶ | if ($ENV{CALLBACKERY_RPC_LOG}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 1 | my $method = shift; | |||||||||||||||||||||||||||
| 200 | 1 | my $data = shift; | |||||||||||||||||||||||||||
| 201 | 1 | $self->dataCleaner($data,$method); | |||||||||||||||||||||||||||
| 202 | 1 | ▶ | my $userId = eval { $self->user->loginName } // '*UNKNOWN*'; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$self->user->loginName
}
} // "*UNKNOWN*"
MC/DC0%0/1
eval {
do {
$self->user->loginName
}
} // "*UNKNOWN*"
eval {
do {
$self->user->loginName
}
}
Truth table50%1/2
A
A= eval {
do {
$self->user->loginName
}
}
| |||||||||||||||||||||||||||||
| 203 | 1 | my $remoteAddr = $self->tx->remote_address; | |||||||||||||||||||||||||||
| 204 | 1 | $self->log->debug("[$userId|$remoteAddr] CALL $method(".encode_json($data).")"); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||
| 207 | 9 | $self->SUPER::logRpcCall(@_); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head2 logRpcReturn | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | Set CALLBACKERY_RPC_LOG for extensive logging messages. Note that all | ||||||||||||||||||||||||||||
| 214 | values with keys matching /password|_pass/ do get replaced with 'xxx' | ||||||||||||||||||||||||||||
| 215 | in the output. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | # our own logging | ||||||||||||||||||||||||||||
| 220 | 9 | ▶ | sub logRpcReturn { | ||||||||||||||||||||||||||
|
Subroutine
logRpcReturn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 222 | 9 | ▶ | if ($ENV{CALLBACKERY_RPC_LOG}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 1 | my $data = shift; | |||||||||||||||||||||||||||
| 224 | 1 | $self->dataCleaner($data); | |||||||||||||||||||||||||||
| 225 | 1 | ▶ | my $userId = eval { $self->user->loginName } // '*UNKNOWN*'; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$self->user->loginName
}
} // "*UNKNOWN*"
MC/DC0%0/1
eval {
do {
$self->user->loginName
}
} // "*UNKNOWN*"
eval {
do {
$self->user->loginName
}
}
Truth table50%1/2
A
A= eval {
do {
$self->user->loginName
}
}
| |||||||||||||||||||||||||||||
| 226 | 1 | my $remoteAddr = $self->tx->remote_address; | |||||||||||||||||||||||||||
| 227 | 1 | $self->log->debug("[$userId|$remoteAddr] RETURN ".encode_json($data).")"); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||
| 230 | 8 | $self->SUPER::logRpcReturn(@_); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =head2 ping() | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | check if the server is happy with our authentication state | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 3 | ▶ | sub ping { | ||||||||||||||||||||||||||
|
Subroutine
ping: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 242 | 3 | return 'pong'; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =head2 getSessionCookie() | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | Return a timeestamped session cookie. For use in the X-Session-Cookie header or as a xsc field | ||||||||||||||||||||||||||||
| 248 | in form submissions. Note that session cookies for form submissions are only valid for 2 seconds. | ||||||||||||||||||||||||||||
| 249 | So you have to get a fresh one from the server before submitting your form. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =cut | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub getSessionCookie { | ||||||||||||||||||||||||||
|
Subroutine
getSessionCookie: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 0 | shift->user->makeSessionCookie(); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =head2 getConfig() | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | get some gloabal configuration information into the interface | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =cut | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub getBaseConfig { | ||||||||||||||||||||||||||
|
Subroutine
getBaseConfig: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 264 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 265 | 0 | return $self->config->cfgHash->{FRONTEND}; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =head2 login(user,password) | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | Check login and provide the user specific interface configuration as a response. | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 2 | ▶ | async sub login { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
login: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 275 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 276 | 2 | my $login = shift; | |||||||||||||||||||||||||||
| 277 | 2 | my $password = shift; | |||||||||||||||||||||||||||
| 278 | 2 | my $cfg = $self->config->cfgHash->{BACKEND}; | |||||||||||||||||||||||||||
| 279 | 2 | ▶ | if (my $ok = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | await $self->config->promisify($self->user->login($login,$password))){ | ||||||||||||||||||||||||||||
| 281 | return { | ||||||||||||||||||||||||||||
| 282 | 2 | sessionCookie => $self->user->makeSessionCookie() | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | } else { | ||||||||||||||||||||||||||||
| 285 | 0 | return; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 11 | } | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =head2 logout | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | Kill the session. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub logout { | ||||||||||||||||||||||||||
|
Subroutine
logout: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 296 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 297 | 0 | $self->session(expires=>1); | |||||||||||||||||||||||||||
| 298 | 0 | return 'http://youtu.be/KGsTNugVctI'; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =head2 instantiatePlugin_p | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | get an instance for the given plugin | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 7 | ▶ | async sub instantiatePlugin_p { | ||||||||||||||||||||||||||
|
Subroutine
instantiatePlugin_p: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 310 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 311 | 7 | my $name = shift; | |||||||||||||||||||||||||||
| 312 | 7 | my $args = shift; | |||||||||||||||||||||||||||
| 313 | 7 | my $user = $self->user; | |||||||||||||||||||||||||||
| 314 | 7 | my $plugin = await $self->config->instantiatePlugin_p($name,$user,$args); | |||||||||||||||||||||||||||
| 315 | 4 | $plugin->log($self->log); | |||||||||||||||||||||||||||
| 316 | 4 | return $plugin; | |||||||||||||||||||||||||||
| 317 | 11 | } | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub instantiatePlugin { | ||||||||||||||||||||||||||
|
Subroutine
instantiatePlugin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 320 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 321 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 322 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 323 | 0 | my $user = $self->user; | |||||||||||||||||||||||||||
| 324 | 0 | my $plugin = $self->config->instantiatePlugin($name,$user,$args); | |||||||||||||||||||||||||||
| 325 | 0 | $plugin->log($self->log); | |||||||||||||||||||||||||||
| 326 | 0 | return $plugin; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =head2 processPluginData(plugin,args) | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | handle form sumissions | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =cut | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 1 | ▶ | async sub processPluginData { | ||||||||||||||||||||||||||
|
Subroutine
processPluginData: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 336 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 337 | 1 | my $plugin = shift; | |||||||||||||||||||||||||||
| 338 | # "Localizing" required as it seems to be changed somewhere. | ||||||||||||||||||||||||||||
| 339 | 1 | my @args = @_; | |||||||||||||||||||||||||||
| 340 | # Creating two statements will make things easier to debug since | ||||||||||||||||||||||||||||
| 341 | # there is only one thing that can go wrong per line. | ||||||||||||||||||||||||||||
| 342 | 1 | my $instance = await $self->instantiatePlugin_p($plugin); | |||||||||||||||||||||||||||
| 343 | 0 | return $instance->processData(@args); | |||||||||||||||||||||||||||
| 344 | 11 | } | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =head2 validateField(plugin,args) | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | validate the content of the given field for the given plugin | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =cut | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | async sub validatePluginData { | ||||||||||||||||||||||||||
|
Subroutine
validatePluginData: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 353 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 354 | 0 | my $plugin = shift; | |||||||||||||||||||||||||||
| 355 | # "Localizing" required as it seems to be changed somewhere. | ||||||||||||||||||||||||||||
| 356 | 0 | my @args = @_; | |||||||||||||||||||||||||||
| 357 | 0 | return (await $self->instantiatePlugin_p($plugin)) | |||||||||||||||||||||||||||
| 358 | ->validateData(@args); | ||||||||||||||||||||||||||||
| 359 | 11 | } | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | =head2 getPluginData(plugin,args); | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | return the current value for the given field | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =cut | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 2 | ▶ | async sub getPluginData { | ||||||||||||||||||||||||||
|
Subroutine
getPluginData: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 368 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 369 | 2 | my $plugin = shift; | |||||||||||||||||||||||||||
| 370 | # "Localizing" required as it seems to be changed somewhere. | ||||||||||||||||||||||||||||
| 371 | 2 | my @args = @_; | |||||||||||||||||||||||||||
| 372 | 2 | return (await $self->instantiatePlugin_p($plugin)) | |||||||||||||||||||||||||||
| 373 | ->getData(@args); | ||||||||||||||||||||||||||||
| 374 | 11 | } | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | =head2 getUserConfig | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | returns user specific configuration information | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | =cut | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 2 | ▶ | async sub getUserConfig { | ||||||||||||||||||||||||||
|
Subroutine
getUserConfig: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 385 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 386 | 2 | my $args = shift; | |||||||||||||||||||||||||||
| 387 | 2 | my @plugins; | |||||||||||||||||||||||||||
| 388 | 2 | for my $plugin ($self->pluginMap->{list}->@*){ | |||||||||||||||||||||||||||
| 389 | try { | ||||||||||||||||||||||||||||
| 390 | 4 | my $obj = await $self->instantiatePlugin_p($plugin,$args); | |||||||||||||||||||||||||||
| 391 | #$obj = $self->instantiatePlugin($plugin,$args); | ||||||||||||||||||||||||||||
| 392 | # $self->log->debug("instanciate $plugin"); | ||||||||||||||||||||||||||||
| 393 | 2 | push @plugins, { | |||||||||||||||||||||||||||
| 394 | tabName => $obj->tabName, | ||||||||||||||||||||||||||||
| 395 | name => $obj->name, | ||||||||||||||||||||||||||||
| 396 | instantiationMode => $obj->instantiationMode | ||||||||||||||||||||||||||||
| 397 | }; | ||||||||||||||||||||||||||||
| 398 | 4 | } catch ($error) { | |||||||||||||||||||||||||||
| 399 | 2 | warn "$error"; | |||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | 2 | my $userConfig = { %{ await $self->config->promisify($self->user->userInfo) } }; | |||||||||||||||||||||||||||
| 403 | 2 | delete $userConfig->{cbuser_password}; | |||||||||||||||||||||||||||
| 404 | 2 | ▶ | delete $userConfig->{cbuser_note} unless $self->user->may('admin'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | return { | ||||||||||||||||||||||||||||
| 406 | 2 | userInfo => $userConfig, | |||||||||||||||||||||||||||
| 407 | plugins => \@plugins, | ||||||||||||||||||||||||||||
| 408 | }; | ||||||||||||||||||||||||||||
| 409 | 11 | } | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =head2 getPluginConfig(plugin,args) | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | Returns a plugin configuration removing all the 'back end' keys and | ||||||||||||||||||||||||||||
| 414 | non ARRAY or HASH references in the process. | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | =cut | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | ▶ | async sub getPluginConfig { | ||||||||||||||||||||||||||
|
Subroutine
getPluginConfig: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 419 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 420 | 0 | my $plugin = shift; | |||||||||||||||||||||||||||
| 421 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 422 | 0 | my $obj = await $self->instantiatePlugin_p($plugin,$args); | |||||||||||||||||||||||||||
| 423 | 0 | return $obj->filterHashKey($obj->screenCfg,'backend'); | |||||||||||||||||||||||||||
| 424 | 11 | } | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =head2 runEventActions(event[,args]) | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | Call the eventAction handlers of all configured plugins. Currently the | ||||||||||||||||||||||||||||
| 429 | following events are known: | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | changeConfig | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub runEventActions { | ||||||||||||||||||||||||||
|
Subroutine
runEventActions: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 436 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 437 | 0 | my $event = shift; | |||||||||||||||||||||||||||
| 438 | 0 | my @args = @_; | |||||||||||||||||||||||||||
| 439 | 0 | for my $obj (@{$self->config->configPlugins}){ | |||||||||||||||||||||||||||
| 440 | 0 | ▶ | if (my $action = $obj->eventActions->{$event}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 0 | $action->(@args) | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | =head2 setPreDestroyAction(key,callback); | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | This can be used to have tasks completed at the end of a webtransaction since | ||||||||||||||||||||||||||||
| 449 | the controller gets instantiated per transaction. | ||||||||||||||||||||||||||||
| 450 | An example application would be backing up the configuration changes only | ||||||||||||||||||||||||||||
| 451 | once even if more than one configChange event has occured. | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =cut | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 0 | ▶ | my $runPreDestroyActions = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=28.4
| |||||||||||||||||||||||||||||
| 456 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 457 | 0 | ▶ | my $actions = $self->{preDestroyActions} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"preDestroyActions"} // {}
MC/DC0%0/1
$self->{"preDestroyActions"} // {}
$self->{"preDestroyActions"}
Truth table0%0/2
A
A= $self->{"preDestroyActions"}
| |||||||||||||||||||||||||||||
| 458 | 0 | $self->log->debug('destroying controller'); | |||||||||||||||||||||||||||
| 459 | 0 | for my $key (keys %$actions){ | |||||||||||||||||||||||||||
| 460 | 0 | $self->log->debug('running preDestroyAction '.$key); | |||||||||||||||||||||||||||
| 461 | 0 | eval { | |||||||||||||||||||||||||||
| 462 | 0 | $actions->{$key}->(); | |||||||||||||||||||||||||||
| 463 | }; | ||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | 0 | $self->log->error("preDestoryAction $key: ".$@); | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | # and thus hopefully releasing the controller | ||||||||||||||||||||||||||||
| 468 | 0 | delete $actions->{$key}; | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | delete $self->{preDestroyActions} | ||||||||||||||||||||||||||||
| 471 | 0 | }; | |||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub setPreDestroyAction { | ||||||||||||||||||||||||||
|
Subroutine
setPreDestroyAction: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 474 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 475 | 0 | my $key = shift; | |||||||||||||||||||||||||||
| 476 | 0 | my $cb = shift; | |||||||||||||||||||||||||||
| 477 | 0 | ▶ | if (not $self->{preDestroyActions}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | # we want to run these pretty soon, basically as soon as | ||||||||||||||||||||||||||||
| 479 | # controll returns to the ioloop | ||||||||||||||||||||||||||||
| 480 | 0 | ▶ | Mojo::IOLoop->timer("0.2" => sub{ $self->$runPreDestroyActions }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | 0 | $self->{preDestroyActions}{$key} = $cb; | |||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =head2 handleUpload | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | Process incoming upload request. This is getting called via a route and NOT | ||||||||||||||||||||||||||||
| 488 | in the usual way, hence we have to render our own response! | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | =cut | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 0 | ▶ | async sub handleUpload { | ||||||||||||||||||||||||||
|
Subroutine
handleUpload: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 495 | 0 | $self->render_later; | |||||||||||||||||||||||||||
| 496 | 0 | ▶ | if (not $self->user->isUserAuthenticated){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | 0 | return $self->render(json => {exception=>{ | |||||||||||||||||||||||||||
| 498 | message=>trm('Access Denied'),code=>4922}}); | ||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | 0 | my $name = $self->req->param('name'); | |||||||||||||||||||||||||||
| 501 | 0 | ▶ | if (not $name){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 502 | 0 | return $self->render(json => {exception=>{ | |||||||||||||||||||||||||||
| 503 | message=>trm('Plugin Name missing'),code=>3934}}); | ||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 0 | my $upload = $self->req->upload('file'); | |||||||||||||||||||||||||||
| 507 | 0 | ▶ | if (not $upload){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | 0 | return $self->render(json => {exception=>{ | |||||||||||||||||||||||||||
| 509 | message=>trm('Upload Missing'),code=>9384}}); | ||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | 0 | my $obj = await $self->instantiatePlugin_p($name); | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 0 | my $form; | |||||||||||||||||||||||||||
| 514 | 0 | ▶ | if (my $formData = $self->req->param('formData')){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 515 | 0 | $form = eval { decode_json($formData) }; | |||||||||||||||||||||||||||
| 516 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 518 | message=>trm('Data Decoding Problem %1',$@),code=>7932}}); | ||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | 0 | $form->{uploadObj} = $upload; | |||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 0 | my $return; | |||||||||||||||||||||||||||
| 524 | try { | ||||||||||||||||||||||||||||
| 525 | 0 | $return = await $self->config->promisify($obj->processData({ | |||||||||||||||||||||||||||
| 526 | key => $self->req->param('key'), | ||||||||||||||||||||||||||||
| 527 | formData => $form, | ||||||||||||||||||||||||||||
| 528 | })); | ||||||||||||||||||||||||||||
| 529 | 0 | } catch ($error) { | |||||||||||||||||||||||||||
| 530 | 0 | ▶ | if (blessed $error){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if ($error->isa('CallBackery::Exception')){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 532 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 533 | message=>$error->message,code=>$error->code}}); | ||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | elsif ($error->isa('Mojo::Exception')){ | ||||||||||||||||||||||||||||
| 536 | 0 | return $self->render(json=>{exception=>{message=>$error->message,code=>9999}}); | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | 0 | return $self->render(json=>{exception=>{message=>$error,code=>9999}}); | |||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | 0 | return $self->render(json=>$return); | |||||||||||||||||||||||||||
| 543 | 11 | } | |||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | =head2 handleDownload | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | Process incoming download request. The handler expects two parameters: name | ||||||||||||||||||||||||||||
| 548 | for the plugin instance and formData for the data of the webform. | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | The handler getting the request must return a hash with the following elements: | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | =over | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | =item filename | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | name of the download when saved | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | =item type | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | mime-type of the download | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | =item asset | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | a L<Mojo::Asset>. eg C<Mojo::Asset::File->new(path => '/etc/passwd')>. | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | =back | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =cut | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 0 | ▶ | async sub handleDownload { | ||||||||||||||||||||||||||
|
Subroutine
handleDownload: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 571 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | ▶ | if (not $self->user->isUserAuthenticated){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 574 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 575 | message=>trm('Access Denied'),code=>3928}}); | ||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 0 | my $name = $self->param('name'); | |||||||||||||||||||||||||||
| 579 | 0 | my $key = $self->param('key'); | |||||||||||||||||||||||||||
| 580 | 0 | ▶ | if (not $name){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 582 | message=>trm('Plugin Name missing'),code=>3923}}); | ||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||
| 584 | 0 | $self->render_later; | |||||||||||||||||||||||||||
| 585 | 0 | my $obj = await $self->instantiatePlugin_p($name); | |||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 0 | my $form; | |||||||||||||||||||||||||||
| 588 | 0 | ▶ | if (my $formData = $self->req->param('formData')){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 589 | 0 | $form = eval { from_json($formData) }; | |||||||||||||||||||||||||||
| 590 | 0 | ▶ | if ($@){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 591 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 592 | message=>trm('Data Decoding Problem %1',$@),code=>3923}}); | ||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | 0 | my $map; | |||||||||||||||||||||||||||
| 596 | try { | ||||||||||||||||||||||||||||
| 597 | 0 | $map = await $self->config->promisify($obj->processData({ | |||||||||||||||||||||||||||
| 598 | key => $key, | ||||||||||||||||||||||||||||
| 599 | formData => $form, | ||||||||||||||||||||||||||||
| 600 | })); | ||||||||||||||||||||||||||||
| 601 | 0 | } catch ($error) { | |||||||||||||||||||||||||||
| 602 | 0 | ▶ | if (blessed $error){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 603 | 0 | ▶ | if ($error->isa('CallBackery::Exception')){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 604 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 605 | message=>$error->message,code=>$error->code}}); | ||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | elsif ($error->isa('Mojo::Exception')){ | ||||||||||||||||||||||||||||
| 608 | 0 | return $self->render(json=>{exception=>{ | |||||||||||||||||||||||||||
| 609 | message=>$error->message,code=>9999}}); | ||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | 0 | return $self->render(json=>{exception=>{message=>$error,code=>9999}}); | |||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | 0 | $self->res->headers->content_type($map->{type}.';name=' .$map->{filename}); | |||||||||||||||||||||||||||
| 616 | 0 | ▶ | if (not $self->param('display')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 617 | 0 | $self->res->headers->content_disposition('attachment;filename='.$map->{filename}); | |||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||
| 619 | 0 | $self->res->content->asset($map->{asset}); | |||||||||||||||||||||||||||
| 620 | 0 | $self->rendered(200); | |||||||||||||||||||||||||||
| 621 | 11 | } | |||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 19 | ▶ | sub DESTROY ($self) { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=5 SCAR=25.7
| |||||||||||||||||||||||||||||
| 624 | # we are only interested in objects that get destroyed during | ||||||||||||||||||||||||||||
| 625 | # global destruction as this is a potential problem | ||||||||||||||||||||||||||||
| 626 | 19 | ▶ | my $class = ref($self) // "child of ". __PACKAGE__; | ||||||||||||||||||||||||||
|
Condition50%1/2
ref $self // "child of CallBackery::Controller::RpcService"
MC/DC0%0/1
ref $self // "child of CallBackery::Controller::RpcService"
ref $self
Truth table50%1/2
A
A= ref $self
| |||||||||||||||||||||||||||||
| 627 | 19 | ▶ | if (${^GLOBAL_PHASE} ne 'DESTRUCT') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 628 | # $self->log->debug($class." DESTROYed"); | ||||||||||||||||||||||||||||
| 629 | 19 | return; | |||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | 0 | ▶ | if (blessed $self && ref $self->log){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($self) and ref $self->log
MC/DC0%0/2
builtin::blessed($self) and ref $self->log
builtin::blessed($self)
ref $self->log
Truth table0%0/3
A and B
A= builtin::blessed($self)B= ref $self->log
| |||||||||||||||||||||||||||||
| 632 | 0 | $self->log->debug("late destruction of $class object during global destruction"); | |||||||||||||||||||||||||||
| 633 | 0 | return; | |||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | 0 | warn "extra late destruction of $class object during global destruction\n"; | |||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 11 | 1; | |||||||||||||||||||||||||||
| 639 | __END__ | ||||||||||||||||||||||||||||