Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
81.25% |
13 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| UseraccountListByRoleAndDepartments | |
81.25% |
13 / 16 |
|
0.00% |
0 / 1 |
3.06 | |
0.00% |
0 / 1 |
| readResponse | |
81.25% |
13 / 16 |
|
0.00% |
0 / 1 |
3.06 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package ZMS API |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsapi; |
| 9 | |
| 10 | use BO\Mellon\Validator; |
| 11 | use BO\Slim\Render; |
| 12 | use BO\Zmsdb\Useraccount; |
| 13 | use Psr\Http\Message\RequestInterface; |
| 14 | use Psr\Http\Message\ResponseInterface; |
| 15 | |
| 16 | class UseraccountListByRoleAndDepartments extends BaseController |
| 17 | { |
| 18 | /** |
| 19 | * @SuppressWarnings(Param) |
| 20 | * @return \Psr\Http\Message\ResponseInterface |
| 21 | */ |
| 22 | #[\Override] |
| 23 | public function readResponse( |
| 24 | RequestInterface $request, |
| 25 | ResponseInterface $response, |
| 26 | array $args |
| 27 | ) { |
| 28 | $roleLevel = $args['level']; |
| 29 | $workstation = (new Helper\User($request, 2))->checkPermissions('useraccount'); |
| 30 | |
| 31 | $rawIds = array_map('trim', explode(',', $args['ids'])); |
| 32 | $rawIds = array_filter($rawIds, 'strlen'); |
| 33 | $requestedDepartmentIds = Helper\User::normalizeDepartmentIds($rawIds); |
| 34 | |
| 35 | $departmentIds = []; |
| 36 | if ($workstation->getUseraccount()->isSuperUser()) { |
| 37 | // Superusers can access all departments; no need to validate via DB here |
| 38 | $departmentIds = $requestedDepartmentIds; |
| 39 | } else { |
| 40 | // Non-superusers must go through Helper\User::checkDepartments for access checks |
| 41 | $departments = Helper\User::checkDepartments($requestedDepartmentIds); |
| 42 | foreach ($departments as $department) { |
| 43 | $departmentIds[] = $department->id; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | $useraccountList = (new Useraccount())->readListByRoleAndDepartmentIds($roleLevel, $departmentIds, 0, false, $workstation); |
| 48 | |
| 49 | $message = Response\Message::create($request); |
| 50 | $message->data = $useraccountList; |
| 51 | |
| 52 | $response = Render::withLastModified($response, time(), '0'); |
| 53 | return Render::withJson($response, $message, 200); |
| 54 | } |
| 55 | } |