Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| UseraccountListByRoleAndDepartments | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| readResponse | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 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 String |
| 21 | */ |
| 22 | public function readResponse( |
| 23 | RequestInterface $request, |
| 24 | ResponseInterface $response, |
| 25 | array $args |
| 26 | ) { |
| 27 | $roleLevel = $args['level']; |
| 28 | $workstation = (new Helper\User($request, 2))->checkRights('useraccount'); |
| 29 | |
| 30 | $rawIds = array_map('trim', explode(',', $args['ids'])); |
| 31 | $rawIds = array_filter($rawIds, 'strlen'); |
| 32 | $requestedDepartmentIds = Helper\User::normalizeDepartmentIds($rawIds); |
| 33 | |
| 34 | $departmentIds = []; |
| 35 | if ($workstation->getUseraccount()->isSuperUser()) { |
| 36 | // Superusers can access all departments; no need to validate via DB here |
| 37 | $departmentIds = $requestedDepartmentIds; |
| 38 | } else { |
| 39 | // Non-superusers must go through Helper\User::checkDepartments for access checks |
| 40 | $departments = Helper\User::checkDepartments($requestedDepartmentIds); |
| 41 | foreach ($departments as $department) { |
| 42 | $departmentIds[] = $department->id; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | $useraccountList = (new Useraccount())->readListByRoleAndDepartmentIds($roleLevel, $departmentIds, 0, false, $workstation); |
| 47 | |
| 48 | $message = Response\Message::create($request); |
| 49 | $message->data = $useraccountList; |
| 50 | |
| 51 | $response = Render::withLastModified($response, time(), '0'); |
| 52 | return Render::withJson($response, $message, 200); |
| 53 | } |
| 54 | } |