From 4fc8aa5a060675d65379db0abb50cbd9c93b4f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 9 Sep 2024 14:39:41 +0200 Subject: [PATCH 1/3] feat(webhook_listeners): Add mapper method to remove all registrations from a given AppAPI id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Db/WebhookListenerMapper.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/webhook_listeners/lib/Db/WebhookListenerMapper.php b/apps/webhook_listeners/lib/Db/WebhookListenerMapper.php index a55a8c7f6a0b1..c0d96891ecc2b 100644 --- a/apps/webhook_listeners/lib/Db/WebhookListenerMapper.php +++ b/apps/webhook_listeners/lib/Db/WebhookListenerMapper.php @@ -159,6 +159,21 @@ public function deleteById(int $id): bool { return ($qb->executeStatement() > 0); } + /** + * Delete all registrations made by the given appId + * + * @throws Exception + * @return int number of registration deleted + */ + public function deleteByAppId(string $appId): int { + $qb = $this->db->getQueryBuilder(); + + $qb->delete($this->getTableName()) + ->where($qb->expr()->eq('app_id', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))); + + return $qb->executeStatement(); + } + /** * @throws Exception * @return list From 4459af41c92748bceb7d7c6ef5f55a568a7fff01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 9 Sep 2024 14:41:20 +0200 Subject: [PATCH 2/3] feat(webhook_listeners): Add API endpoint to remove all registrations from an AppAPI app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Controller/WebhooksController.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/webhook_listeners/lib/Controller/WebhooksController.php b/apps/webhook_listeners/lib/Controller/WebhooksController.php index eeb26b570309d..1d5e37cb373b0 100644 --- a/apps/webhook_listeners/lib/Controller/WebhooksController.php +++ b/apps/webhook_listeners/lib/Controller/WebhooksController.php @@ -247,7 +247,7 @@ public function update( * * @return DataResponse * - * 200: Boolean returned whether something was deleted FIXME + * 200: Boolean returned whether something was deleted * * @throws OCSBadRequestException Bad request * @throws OCSForbiddenException Insufficient permissions @@ -269,4 +269,34 @@ public function destroy(int $id): DataResponse { throw new OCSException('An internal error occurred', Http::STATUS_INTERNAL_SERVER_ERROR, $e); } } + + /** + * Remove all existing webhook registration mapped to an AppAPI app id + * + * @param string $appid id of the app, as in the EX-APP-ID for creation + * + * @return DataResponse + * + * 200: Integer number of registrations deleted + * + * @throws OCSBadRequestException Bad request + * @throws OCSForbiddenException Insufficient permissions + * @throws OCSException Other error + */ + #[ApiRoute(verb: 'DELETE', url: '/api/v1/webhooks/byappid/{appid}')] + #[AuthorizedAdminSetting(settings:Admin::class)] + #[AppApiAdminAccessWithoutUser] + public function deleteByAppId(string $appid): DataResponse { + try { + $deletedCount = $this->mapper->deleteByAppId($appid); + return new DataResponse($deletedCount); + } catch (\UnexpectedValueException $e) { + throw new OCSBadRequestException($e->getMessage(), $e); + } catch (\DomainException $e) { + throw new OCSForbiddenException($e->getMessage(), $e); + } catch (\Exception $e) { + $this->logger->error('Error when deleting flows for app id ' . $appid, ['exception' => $e]); + throw new OCSException('An internal error occurred', Http::STATUS_INTERNAL_SERVER_ERROR, $e); + } + } } From 22a2893addb857b7007d0d9322aeca1bbd87b16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 9 Sep 2024 14:50:52 +0200 Subject: [PATCH 3/3] chore(webhook_listeners): Update openapi.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/webhook_listeners/openapi.json | 130 +++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/apps/webhook_listeners/openapi.json b/apps/webhook_listeners/openapi.json index 7b6fdd6241f4d..fcd26efdf6d69 100644 --- a/apps/webhook_listeners/openapi.json +++ b/apps/webhook_listeners/openapi.json @@ -686,7 +686,7 @@ ], "responses": { "200": { - "description": "Boolean returned whether something was deleted FIXME", + "description": "Boolean returned whether something was deleted", "content": { "application/json": { "schema": { @@ -773,6 +773,134 @@ } } } + }, + "/ocs/v2.php/apps/webhook_listeners/api/v1/webhooks/byappid/{appid}": { + "delete": { + "operationId": "webhooks-delete-by-app-id", + "summary": "Remove all existing webhook registration mapped to an AppAPI app id", + "description": "This endpoint requires admin access", + "tags": [ + "webhooks" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "appid", + "in": "path", + "description": "id of the app, as in the EX-APP-ID for creation", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Integer number of registrations deleted", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "integer", + "format": "int64" + } + } + } + } + } + } + } + }, + "400": { + "description": "Bad request", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "403": { + "description": "Insufficient permissions", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + } + } + } } }, "tags": []