Lines 88.00% 22 / 25
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 readResponse 86.36% 19 / 22 0.00% 0 / 1 3.02
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
15class UseraccountListByRoleAndDepartments extends \BO\Zmsbackend\Api\BaseController
16{
17    /**
18     * @SuppressWarnings(Param)
19     * @return \Psr\Http\Message\ResponseInterface
20     */
21    #[\Override]
22    public function readResponse(
23        RequestInterface $request,
24        ResponseInterface $response,
25        array $args
26    ) {
27        $roleName = $args['roleName'];
28        $workstation = (new \BO\Zmsbackend\Helper\User($request, 2))->checkPermissions('useraccount');
29
30        $rawIds = array_map('trim', explode(',', $args['ids']));
31        $rawIds = array_filter($rawIds, 'strlen');
32        $requestedDepartmentIds = \BO\Zmsbackend\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 \BO\Zmsbackend\Helper\User::checkDepartments for access checks
40            $departments = \BO\Zmsbackend\Helper\User::checkDepartments($requestedDepartmentIds);
41            foreach ($departments as $department) {
42                $departmentIds[] = $department->id;
43            }
44        }
45
46        $useraccountList = (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->readListByRoleAndDepartmentIds(
47            $roleName,
48            $departmentIds,
49            0,
50            false,
51            $workstation
52        );
53
54        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
55        $message->data = $useraccountList;
56
57        $response = Render::withLastModified($response, time(), '0');
58        return Render::withJson($response, $message, 200);
59    }
60}

Inherited from BO\Zmsbackend\Api\BaseController

20    public function __invoke(RequestInterface $request, ResponseInterface $response, array $args)
21    {
22        $request = $this->initRequest($request);
23        $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0');
24        return $this->readResponse($request, $noCacheResponse, $args);
25    }