Add rpc endpoint for deletion of user ranks
authorMarcel Werk <burntime@woltlab.com>
Thu, 26 Sep 2024 16:08:30 +0000 (18:08 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 11:51:53 +0000 (12:51 +0100)
wcfsetup/install/files/lib/system/endpoint/controller/core/users/ranks/DeleteUserRank.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/users/ranks/DeleteUserRank.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/users/ranks/DeleteUserRank.class.php
new file mode 100644 (file)
index 0000000..fa61fec
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace wcf\system\endpoint\controller\core\users\ranks;
+
+use Laminas\Diactoros\Response\JsonResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use wcf\data\user\rank\UserRank;
+use wcf\data\user\rank\UserRankAction;
+use wcf\http\Helper;
+use wcf\system\endpoint\DeleteRequest;
+use wcf\system\endpoint\IController;
+use wcf\system\WCF;
+
+/**
+ * API endpoint for the deletion of user ranks.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since       6.1
+ */
+#[DeleteRequest('/core/users/ranks/{id:\d+}')]
+final class DeleteUserRank implements IController
+{
+    #[\Override]
+    public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
+    {
+        WCF::getSession()->checkPermissions(['admin.user.rank.canManageRank']);
+
+        $rank = Helper::fetchObjectFromRequestParameter($variables['id'], UserRank::class);
+
+        $action = new UserRankAction([$rank], 'delete');
+        $action->executeAction();
+
+        return new JsonResponse([]);
+    }
+}