From 5dd9c2f8e85816f5c588d9539ec33b97d111287e Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 30 May 2024 16:46:32 +0200 Subject: feat: Add admin delegation for webhooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/webhooks/appinfo/info.xml | 4 ++ .../composer/composer/autoload_classmap.php | 1 + .../webhooks/composer/composer/autoload_static.php | 1 + .../webhooks/lib/Controller/WebhooksController.php | 6 +++ apps/webhooks/lib/Settings/Admin.php | 60 ++++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 apps/webhooks/lib/Settings/Admin.php 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 @@ OCA\Webhooks\Command\Index + + + OCA\Webhooks\Settings\Admin + 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 @@ +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 []; + } +} -- cgit v1.2.3