diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-05-30 16:46:32 +0200 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-06-11 14:10:29 +0200 |
commit | 5dd9c2f8e85816f5c588d9539ec33b97d111287e (patch) | |
tree | 2b9d3a5ec721bbc3fc03469188fa74cb1bb4d3f1 | |
parent | 3b64e525fbbea479887a7b57307c8d53aea3b3f5 (diff) | |
download | nextcloud-server-5dd9c2f8e85816f5c588d9539ec33b97d111287e.tar.gz nextcloud-server-5dd9c2f8e85816f5c588d9539ec33b97d111287e.zip |
feat: Add admin delegation for webhooks
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/webhooks/appinfo/info.xml | 4 | ||||
-rw-r--r-- | apps/webhooks/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/webhooks/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/webhooks/lib/Controller/WebhooksController.php | 6 | ||||
-rw-r--r-- | apps/webhooks/lib/Settings/Admin.php | 60 |
5 files changed, 72 insertions, 0 deletions
diff --git a/apps/webhooks/appinfo/info.xml b/apps/webhooks/appinfo/info.xml index 9261ed646ef..6b9a809dba0 100644 --- a/apps/webhooks/appinfo/info.xml +++ b/apps/webhooks/appinfo/info.xml @@ -26,4 +26,8 @@ <commands> <command>OCA\Webhooks\Command\Index</command> </commands> + + <settings> + <admin>OCA\Webhooks\Settings\Admin</admin> + </settings> </info> diff --git a/apps/webhooks/composer/composer/autoload_classmap.php b/apps/webhooks/composer/composer/autoload_classmap.php index f8ea080f691..3411d0b6b96 100644 --- a/apps/webhooks/composer/composer/autoload_classmap.php +++ b/apps/webhooks/composer/composer/autoload_classmap.php @@ -16,4 +16,5 @@ return array( 'OCA\\Webhooks\\Listener\\WebhooksEventListener' => $baseDir . '/../lib/Listener/WebhooksEventListener.php', 'OCA\\Webhooks\\Migration\\Version1000Date20240527153425' => $baseDir . '/../lib/Migration/Version1000Date20240527153425.php', 'OCA\\Webhooks\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php', + 'OCA\\Webhooks\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', ); diff --git a/apps/webhooks/composer/composer/autoload_static.php b/apps/webhooks/composer/composer/autoload_static.php index 684e0d96464..e631fdfb975 100644 --- a/apps/webhooks/composer/composer/autoload_static.php +++ b/apps/webhooks/composer/composer/autoload_static.php @@ -31,6 +31,7 @@ class ComposerStaticInitWebhooks 'OCA\\Webhooks\\Listener\\WebhooksEventListener' => __DIR__ . '/..' . '/../lib/Listener/WebhooksEventListener.php', 'OCA\\Webhooks\\Migration\\Version1000Date20240527153425' => __DIR__ . '/..' . '/../lib/Migration/Version1000Date20240527153425.php', 'OCA\\Webhooks\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php', + 'OCA\\Webhooks\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', ); public static function getInitializer(ClassLoader $loader) diff --git a/apps/webhooks/lib/Controller/WebhooksController.php b/apps/webhooks/lib/Controller/WebhooksController.php index b5aa14449ec..9d4c7c70279 100644 --- a/apps/webhooks/lib/Controller/WebhooksController.php +++ b/apps/webhooks/lib/Controller/WebhooksController.php @@ -12,6 +12,7 @@ namespace OCA\Webhooks\Controller; use Doctrine\DBAL\Exception; use OCA\Webhooks\Db\WebhookListenerMapper; use OCP\AppFramework\Http\Attribute\ApiRoute; +use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; use OCP\AppFramework\Http\Attribute\OpenAPI; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; @@ -44,6 +45,7 @@ class WebhooksController extends OCSController { * 200: Webhook registrations returned */ #[ApiRoute(verb: 'GET', url: '/api/v1/webhooks')] + #[AuthorizedAdminSetting(settings:'OCA\Webhooks\Settings\Admin')] public function index(): DataResponse { $webhookListeners = $this->mapper->getAll(); @@ -60,6 +62,7 @@ class WebhooksController extends OCSController { * 200: Webhook registration returned */ #[ApiRoute(verb: 'GET', url: '/api/v1/webhooks/{id}')] + #[AuthorizedAdminSetting(settings:'OCA\Webhooks\Settings\Admin')] public function show(int $id): DataResponse { return new DataResponse($this->mapper->getById($id)); } @@ -83,6 +86,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'POST', url: '/api/v1/webhooks')] + #[AuthorizedAdminSetting(settings:'OCA\Webhooks\Settings\Admin')] public function create( string $httpMethod, string $uri, @@ -132,6 +136,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'POST', url: '/api/v1/webhooks/{id}')] + #[AuthorizedAdminSetting(settings:'OCA\Webhooks\Settings\Admin')] public function update( int $id, string $httpMethod, @@ -177,6 +182,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'DELETE', url: '/api/v1/webhooks/{id}')] + #[AuthorizedAdminSetting(settings:'OCA\Webhooks\Settings\Admin')] public function destroy(int $id): DataResponse { try { $deleted = $this->mapper->deleteById($id); diff --git a/apps/webhooks/lib/Settings/Admin.php b/apps/webhooks/lib/Settings/Admin.php new file mode 100644 index 00000000000..748b8536e4f --- /dev/null +++ b/apps/webhooks/lib/Settings/Admin.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Webhooks\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IL10N; +use OCP\Settings\IDelegatedSettings; + +/** + * Empty settings class, used only for admin delegation for now as there is no UI + */ +class Admin implements IDelegatedSettings { + + public function __construct( + protected string $appName, + private IL10N $l10n, + ) { + } + + /** + * Empty template response + */ + public function getForm(): TemplateResponse { + return new class($this->appName, '') extends TemplateResponse { + public function render(): string { + return ''; + } + }; + } + + public function getSection(): ?string { + return 'admindelegation'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority(): int { + return 0; + } + + public function getName(): string { + return $this->l10n->t('Webhooks'); + } + + public function getAuthorizedAppConfig(): array { + return []; + } +} |