/
ConfirmDeleteAction.php
89 lines (75 loc) · 2.93 KB
/
ConfirmDeleteAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
* vim:set softtabstop=4 shiftwidth=4 expandtab:
*
* LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
* Copyright 2001 - 2020 Ampache.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
declare(strict_types=0);
namespace Ampache\Module\Application\Admin\User;
use Ampache\Config\ConfigContainerInterface;
use Ampache\Config\ConfigurationKeyEnum;
use Ampache\Repository\Model\ModelFactoryInterface;
use Ampache\Module\Application\Exception\AccessDeniedException;
use Ampache\Module\System\Core;
use Ampache\Module\Util\UiInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
final class ConfirmDeleteAction extends AbstractUserAction
{
public const REQUEST_KEY = 'confirm_delete';
private UiInterface $ui;
private ModelFactoryInterface $modelFactory;
private ConfigContainerInterface $configContainer;
public function __construct(
UiInterface $ui,
ModelFactoryInterface $modelFactory,
ConfigContainerInterface $configContainer
) {
$this->ui = $ui;
$this->modelFactory = $modelFactory;
$this->configContainer = $configContainer;
}
protected function handle(ServerRequestInterface $request): ?ResponseInterface
{
if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) === true) {
return null;
}
if (!Core::form_verify('delete_user')) {
throw new AccessDeniedException();
}
$this->ui->showHeader();
$client = $this->modelFactory->createUser((int) Core::get_request('user_id'));
if ($client->delete()) {
$this->ui->showConfirmation(
T_('No Problem'),
/* HINT: Username (Short Name) */
sprintf(T_('%s has been deleted'), $client->username),
sprintf('%s/admin/users.php', $this->configContainer->getWebPath())
);
} else {
$this->ui->showConfirmation(
T_('There Was a Problem'),
T_('You need at least one active Administrator account'),
sprintf('%s/admin/users.php', $this->configContainer->getWebPath())
);
}
$this->ui->showQueryStats();
$this->ui->showFooter();
return null;
}
}