diff options
author | Joas Schilling <coding@schilljs.com> | 2023-08-09 15:35:19 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-08-10 16:26:00 +0200 |
commit | 29445b6a71b4f4a40d7272abaf93700f6ddc5c43 (patch) | |
tree | 86dffe35cb9cb32546d2c12f14a42bc5c03f76bd | |
parent | 732d9fb1cc4cd9c92239057cc63c764e449e1177 (diff) |
feat: Add admin endpoint so we can list installed bots in the admin page
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | appinfo/routes/routesBotController.php | 2 | ||||
-rw-r--r-- | lib/Controller/BotController.php | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/appinfo/routes/routesBotController.php b/appinfo/routes/routesBotController.php index 90910d2a3..3578cc7f5 100644 --- a/appinfo/routes/routesBotController.php +++ b/appinfo/routes/routesBotController.php @@ -48,6 +48,8 @@ return [ ['name' => 'Bot#react', 'url' => '/api/{apiVersion}/bot/{token}/reaction/{messageId}', 'verb' => 'POST', 'requirements' => $requirementsWithMessageId], /** @see \OCA\Talk\Controller\BotController::deleteReaction() */ ['name' => 'Bot#deleteReaction', 'url' => '/api/{apiVersion}/bot/{token}/reaction/{messageId}', 'verb' => 'DELETE', 'requirements' => $requirementsWithMessageId], + /** @see \OCA\Talk\Controller\BotController::adminListBots() */ + ['name' => 'Bot#adminListBots', 'url' => '/api/{apiVersion}/bot/admin', 'verb' => 'GET', 'requirements' => $requirements], /** @see \OCA\Talk\Controller\BotController::listBots() */ ['name' => 'Bot#listBots', 'url' => '/api/{apiVersion}/bot/{token}', 'verb' => 'GET', 'requirements' => $requirements], /** @see \OCA\Talk\Controller\BotController::enableBot() */ diff --git a/lib/Controller/BotController.php b/lib/Controller/BotController.php index 3e763dc13..24dbe149e 100644 --- a/lib/Controller/BotController.php +++ b/lib/Controller/BotController.php @@ -238,6 +238,21 @@ class BotController extends AEnvironmentAwareController { return new DataResponse([], Http::STATUS_OK); } + /** + * Admin required + */ + public function adminListBots(): DataResponse { + $data = []; + $bots = $this->botServerMapper->getAllBots(); + foreach ($bots as $bot) { + $botData = $bot->jsonSerialize(); + unset($botData['secret']); + $data[] = $botData; + } + + return new DataResponse($data); + } + #[NoAdminRequired] #[RequireLoggedInModeratorParticipant] public function listBots(): DataResponse { |