Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require confirmation on enable and disable user links
- Loading branch information
1 parent
0a8ae19
commit bcdd8bb
Showing
7 changed files
with
208 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/Module/Application/Admin/User/ConfirmDisableAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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\Module\User\UserStateTogglerInterface; | ||
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 ConfirmDisableAction extends AbstractUserAction | ||
{ | ||
public const REQUEST_KEY = 'confirm_disable'; | ||
|
||
private UiInterface $ui; | ||
|
||
private ModelFactoryInterface $modelFactory; | ||
|
||
private ConfigContainerInterface $configContainer; | ||
|
||
private UserStateTogglerInterface $userStateToggler; | ||
|
||
public function __construct( | ||
UiInterface $ui, | ||
ModelFactoryInterface $modelFactory, | ||
ConfigContainerInterface $configContainer, | ||
UserStateTogglerInterface $userStateToggler | ||
) { | ||
$this->ui = $ui; | ||
$this->modelFactory = $modelFactory; | ||
$this->configContainer = $configContainer; | ||
$this->userStateToggler = $userStateToggler; | ||
} | ||
|
||
protected function handle(ServerRequestInterface $request): ?ResponseInterface | ||
{ | ||
if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) === true) { | ||
return null; | ||
} | ||
|
||
if (!Core::form_verify('disable_user')) { | ||
throw new AccessDeniedException(); | ||
} | ||
$this->ui->showHeader(); | ||
|
||
$user = $this->modelFactory->createUser((int) Core::get_request('user_id')); | ||
|
||
if ($this->userStateToggler->disable($user) === true) { | ||
$this->ui->showConfirmation( | ||
T_('No Problem'), | ||
/* HINT: Username and fullname together: Username (fullname) */ | ||
sprintf(T_('%s (%s) has been disabled'), $user->username, $user->fullname), | ||
'admin/users.php' | ||
); | ||
} else { | ||
$this->ui->showConfirmation( | ||
T_('There Was a Problem'), | ||
T_('You need at least one active Administrator account'), | ||
'admin/users.php' | ||
); | ||
} | ||
|
||
$this->ui->showQueryStats(); | ||
$this->ui->showFooter(); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?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\Module\User\UserStateTogglerInterface; | ||
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 ConfirmEnableAction extends AbstractUserAction | ||
{ | ||
public const REQUEST_KEY = 'confirm_enable'; | ||
|
||
private UiInterface $ui; | ||
|
||
private ModelFactoryInterface $modelFactory; | ||
|
||
private ConfigContainerInterface $configContainer; | ||
|
||
private UserStateTogglerInterface $userStateToggler; | ||
|
||
public function __construct( | ||
UiInterface $ui, | ||
ModelFactoryInterface $modelFactory, | ||
ConfigContainerInterface $configContainer, | ||
UserStateTogglerInterface $userStateToggler | ||
) { | ||
$this->ui = $ui; | ||
$this->modelFactory = $modelFactory; | ||
$this->configContainer = $configContainer; | ||
$this->userStateToggler = $userStateToggler; | ||
} | ||
|
||
protected function handle(ServerRequestInterface $request): ?ResponseInterface | ||
{ | ||
if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) === true) { | ||
return null; | ||
} | ||
|
||
if (!Core::form_verify('enable_user')) { | ||
throw new AccessDeniedException(); | ||
} | ||
$this->ui->showHeader(); | ||
|
||
$user = $this->modelFactory->createUser((int) Core::get_request('user_id')); | ||
|
||
$this->userStateToggler->enable($user); | ||
|
||
$this->ui->showConfirmation( | ||
T_('No Problem'), | ||
/* HINT: Username and fullname together: Username (fullname) */ | ||
sprintf(T_('%s (%s) has been enabled'), $user->username, $user->fullname), | ||
'admin/users.php' | ||
); | ||
|
||
$this->ui->showQueryStats(); | ||
$this->ui->showFooter(); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters