Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ModuleAccess | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| rejectWrongModuleAccess | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
56 | |||
| endSession | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsclient; |
| 4 | |
| 5 | use BO\Zmsentities\Workstation; |
| 6 | use Psr\Http\Message\ResponseInterface; |
| 7 | |
| 8 | class ModuleAccess |
| 9 | { |
| 10 | public const MODULE_ADMIN = 'zmsadmin'; |
| 11 | |
| 12 | public const MODULE_STATISTIC = 'zmsstatistic'; |
| 13 | |
| 14 | public static function rejectWrongModuleAccess( |
| 15 | string $application, |
| 16 | Workstation $workstation, |
| 17 | ResponseInterface $response |
| 18 | ): ?ResponseInterface { |
| 19 | $useraccount = $workstation->getUseraccount(); |
| 20 | |
| 21 | if ($useraccount->isSuperUser()) { |
| 22 | return null; |
| 23 | } |
| 24 | |
| 25 | $rejected = ($application === self::MODULE_STATISTIC && !$useraccount->hasPermissions(['statistic'])) |
| 26 | || ($application === self::MODULE_ADMIN && $useraccount->hasExclusivePermission('statistic')); |
| 27 | |
| 28 | if ($rejected) { |
| 29 | self::endSession($workstation); |
| 30 | $template = $application === self::MODULE_ADMIN |
| 31 | ? 'exception/bo/slim/exception/wrongmodulestatistic.twig' |
| 32 | : 'exception/bo/slim/exception/wrongmoduleadmin.twig'; |
| 33 | return \BO\Slim\Render::withHtml($response, $template, [], 403); |
| 34 | } else { |
| 35 | return null; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | private static function endSession(Workstation $workstation): void |
| 40 | { |
| 41 | try { |
| 42 | if (Auth::getKey()) { |
| 43 | \App::$http->readDeleteResult('/workstation/login/' . $workstation->getUseraccount()->id . '/'); |
| 44 | } |
| 45 | } catch (\Exception $exception) { |
| 46 | } |
| 47 | |
| 48 | Auth::removeKey(); |
| 49 | } |
| 50 | } |