mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
Merge pull request #47845 from nextcloud/feat/webhook_listeners-remove-all-from-appid
Add an endpoint to remove all webhook registrations from an app
This commit is contained in:
commit
8ea42224ec
3 changed files with 175 additions and 2 deletions
|
|
@ -247,7 +247,7 @@ class WebhooksController extends OCSController {
|
|||
*
|
||||
* @return DataResponse<Http::STATUS_OK, bool, array{}>
|
||||
*
|
||||
* 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 @@ class WebhooksController extends OCSController {
|
|||
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<Http::STATUS_OK, int, array{}>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,6 +159,21 @@ class WebhookListenerMapper extends QBMapper {
|
|||
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<string>
|
||||
|
|
|
|||
|
|
@ -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": []
|
||||
|
|
|
|||
Loading…
Reference in a new issue