Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UseraccountEdit
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
2 / 2
9
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%
14 / 14
100.00% covered (success)
100.00%
1 / 1
4
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        $entity->setPassword($input);
71        try {
72            $entity = \App::$http->readPostResult('/useraccount/' . $userAccountName . '/', $entity)->getEntity();
73        } catch (\BO\Zmsclient\Exception $exception) {
74            $template = Helper\TwigExceptionHandler::getExceptionTemplate($exception);
75            if (
76                '' != $exception->template
77                && \App::$slim->getContainer()->get('view')->getLoader()->exists($template)
78            ) {
79                return [
80                    'template' => $template,
81                    'include' => true,
82                    'data' => $exception->data
83                ];
84            }
85            throw $exception;
86        }
87        return $entity;
88    }
89}