Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UseraccountEdit
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
1 / 1
5
 writeUpdatedEntity
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 *
5 * @package Zmsadmin
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin;
11
12use BO\Zmsentities\Schema\Loader;
13use BO\Zmsentities\Useraccount as Entity;
14use BO\Mellon\Validator;
15use BO\Zmsclient\Auth;
16
17class UseraccountEdit extends BaseController
18{
19    /**
20     *
21     * @return String
22     */
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
29        $userAccountName = Validator::value($args['loginname'])->isString()->getValue();
30        $confirmSuccess = $request->getAttribute('validator')->getParameter('success')->isString()->getValue();
31        $userAccount = \App::$http->readGetResult('/useraccount/' . $userAccountName . '/')->getEntity();
32        $ownerList = \App::$http->readGetResult('/owner/', ['resolveReferences' => 2])->getCollection();
33
34        if ($request->getMethod() === 'POST') {
35            $input = $request->getParsedBody();
36            $result = $this->writeUpdatedEntity($input, $userAccountName);
37            if ($result instanceof Entity) {
38                return \BO\Slim\Render::redirect(
39                    'useraccountEdit',
40                    array('loginname' => $result->id),
41                    array('success' => 'useraccount_saved')
42                );
43            }
44        }
45
46        $config = \App::$http->readGetResult('/config/', [], \App::CONFIG_SECURE_TOKEN)->getEntity();
47        $allowedProviderList = explode(',', $config->getPreference('oidc', 'provider') ?? '');
48
49        return \BO\Slim\Render::withHtml(
50            $response,
51            'page/useraccountEdit.twig',
52            [
53                'debug' => \App::DEBUG,
54                'userAccount' => $userAccount,
55                'success' => $confirmSuccess,
56                'ownerList' => $ownerList ? $ownerList->toDepartmentListByOrganisationName() : [],
57                'workstation' => $workstation,
58                'title' => 'Nutzer: Einrichtung und Administration','menuActive' => 'useraccount',
59                'exception' => (isset($result)) ? $result : null,
60                'metadata' => $this->getSchemaConstraintList(Loader::asArray(Entity::$schema)),
61                'oidcProviderList' => array_filter($allowedProviderList),
62                'isFromOidc' => in_array($userAccount->getOidcProviderFromName(), $allowedProviderList)
63            ]
64        );
65    }
66
67    protected function writeUpdatedEntity($input, $userAccountName)
68    {
69        $entity = (new Entity($input))->withCleanedUpFormData();
70        // TODO: Remove the password fields when password authentication is removed in the future
71        $entity->setPassword($input);
72        return $this->handleEntityWrite(function () use ($entity, $userAccountName) {
73            return \App::$http
74                ->readPostResult('/useraccount/' . $userAccountName . '/', $entity)
75                ->getEntity();
76        });
77    }
78}