-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration user option list to grid view
- Loading branch information
Showing
12 changed files
with
355 additions
and
132 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
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
19 changes: 19 additions & 0 deletions
19
wcfsetup/install/files/lib/event/gridView/UserOptionGridViewInitialized.class.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,19 @@ | ||
<?php | ||
|
||
namespace wcf\event\gridView; | ||
|
||
use wcf\event\IPsr14Event; | ||
use wcf\system\view\grid\UserOptionGridView; | ||
|
||
/** | ||
* Indicates that the user option grid view has been initialized. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
*/ | ||
final class UserOptionGridViewInitialized implements IPsr14Event | ||
{ | ||
public function __construct(public readonly UserOptionGridView $gridView) {} | ||
} |
46 changes: 46 additions & 0 deletions
46
...up/install/files/lib/system/endpoint/controller/core/users/options/DeleteOption.class.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,46 @@ | ||
<?php | ||
|
||
namespace wcf\system\endpoint\controller\core\users\options; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use wcf\data\user\option\UserOption; | ||
use wcf\http\Helper; | ||
use wcf\system\endpoint\DeleteRequest; | ||
use wcf\system\endpoint\IController; | ||
use wcf\system\exception\PermissionDeniedException; | ||
use wcf\system\WCF; | ||
|
||
/** | ||
* API endpoint for deleting user options. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
*/ | ||
#[DeleteRequest('/core/users/options/{id:\d+}')] | ||
final class DeleteOption implements IController | ||
{ | ||
#[\Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
$option = Helper::fetchObjectFromRequestParameter($variables['id'], UserOption::class); | ||
|
||
$this->assertOptionCanBeDeleted($option); | ||
|
||
(new \wcf\system\user\option\command\DeleteOption($option))(); | ||
|
||
return new JsonResponse([]); | ||
} | ||
|
||
private function assertOptionCanBeDeleted(UserOption $option): void | ||
{ | ||
WCF::getSession()->checkPermissions(['admin.user.canManageUserOption']); | ||
|
||
if (!$option->canDelete()) { | ||
throw new PermissionDeniedException(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...p/install/files/lib/system/endpoint/controller/core/users/options/DisableOption.class.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,43 @@ | ||
<?php | ||
|
||
namespace wcf\system\endpoint\controller\core\users\options; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use wcf\data\user\option\UserOption; | ||
use wcf\http\Helper; | ||
use wcf\system\endpoint\IController; | ||
use wcf\system\endpoint\PostRequest; | ||
use wcf\system\WCF; | ||
|
||
/** | ||
* API endpoint for disabling user options. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
*/ | ||
#[PostRequest('/core/users/options/{id:\d+}/disable')] | ||
final class DisableOption implements IController | ||
{ | ||
#[\Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
$option = Helper::fetchObjectFromRequestParameter($variables['id'], UserOption::class); | ||
|
||
$this->assertOptionCanBeDisabled(); | ||
|
||
if (!$option->isDisabled) { | ||
(new \wcf\system\user\option\command\DisableOption($option))(); | ||
} | ||
|
||
return new JsonResponse([]); | ||
} | ||
|
||
private function assertOptionCanBeDisabled(): void | ||
{ | ||
WCF::getSession()->checkPermissions(['admin.user.canManageUserOption']); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...up/install/files/lib/system/endpoint/controller/core/users/options/EnableOption.class.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,43 @@ | ||
<?php | ||
|
||
namespace wcf\system\endpoint\controller\core\users\options; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use wcf\data\user\option\UserOption; | ||
use wcf\http\Helper; | ||
use wcf\system\endpoint\IController; | ||
use wcf\system\endpoint\PostRequest; | ||
use wcf\system\WCF; | ||
|
||
/** | ||
* API endpoint for enabling user options. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
*/ | ||
#[PostRequest('/core/users/options/{id:\d+}/enable')] | ||
final class EnableOption implements IController | ||
{ | ||
#[\Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
$option = Helper::fetchObjectFromRequestParameter($variables['id'], UserOption::class); | ||
|
||
$this->assertOptionCanBeEnabled(); | ||
|
||
if ($option->isDisabled) { | ||
(new \wcf\system\user\option\command\EnableOption($option))(); | ||
} | ||
|
||
return new JsonResponse([]); | ||
} | ||
|
||
private function assertOptionCanBeEnabled(): void | ||
{ | ||
WCF::getSession()->checkPermissions(['admin.user.canManageUserOption']); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
wcfsetup/install/files/lib/system/user/option/command/DeleteOption.class.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,27 @@ | ||
<?php | ||
|
||
namespace wcf\system\user\option\command; | ||
|
||
use wcf\data\user\option\UserOption; | ||
use wcf\data\user\option\UserOptionAction; | ||
|
||
/** | ||
* Deletes a user option. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
*/ | ||
final class DeleteOption | ||
{ | ||
public function __construct( | ||
private readonly UserOption $option, | ||
) {} | ||
|
||
public function __invoke(): void | ||
{ | ||
$action = new UserOptionAction([$this->option], 'delete'); | ||
$action->executeAction(); | ||
} | ||
} |
Oops, something went wrong.