Skip to content

Commit

Permalink
Merge pull request #928 from nextcloud/feat/noid/rm-context
Browse files Browse the repository at this point in the history
API endpoint to delete a context
  • Loading branch information
blizzz authored Mar 14, 2024
2 parents 3aac5fa + 82c4fb8 commit b10f12d
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
['name' => 'Context#show', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'GET'],
['name' => 'Context#create', 'url' => '/api/2/contexts', 'verb' => 'POST'],
['name' => 'Context#update', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'PUT'],
['name' => 'Context#destroy', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'DELETE'],
['name' => 'Context#transfer', 'url' => '/api/2/contexts/{contextId}/transfer', 'verb' => 'PUT'],
['name' => 'Context#addNode', 'url' => '/api/2/contexts/{contextId}/nodes', 'verb' => 'POST'],
['name' => 'Context#removeNode', 'url' => '/api/2/contexts/{contextId}/nodes/{nodeRelId}', 'verb' => 'DELETE'],
Expand Down
23 changes: 23 additions & 0 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ public function update(int $contextId, ?string $name, ?string $iconName, ?string
}
}

/**
* [api v2] Delete an existing context and return it
*
* @param int $contextId ID of the context
* @return DataResponse<Http::STATUS_OK, TablesContext, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: returning the full context information
* 403: No permissions
* 404: Not found
*
* @NoAdminRequired
* @CanManageContext
*/
public function destroy(int $contextId): DataResponse {
try {
return new DataResponse($this->contextService->delete($contextId, $this->userId)->jsonSerialize());
} catch (Exception $e) {
return $this->handleError($e);
} catch (NotFoundError $e) {
return $this->handleNotFoundError($e);
}
}

/**
* [api v2] Transfer the ownership of a context and return it
*
Expand Down
9 changes: 9 additions & 0 deletions lib/Service/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public function update(int $contextId, string $userId, ?string $name, ?string $i
return $context;
}

/**
* @throws NotFoundError
* @throws Exception
*/
public function delete(int $contextId, string $userId): Context {
$context = $this->contextMapper->findById($contextId, $userId);
return $this->contextMapper->delete($context);
}

/**
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
Expand Down
145 changes: 145 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -8475,6 +8475,151 @@
}
}
}
},
"delete": {
"operationId": "context-destroy",
"summary": "[api v2] Delete an existing context and return it",
"tags": [
"context"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "contextId",
"in": "path",
"description": "ID of the context",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"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": "returning the full context information",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Context"
}
}
}
}
}
}
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"404": {
"description": "Not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/tables/api/2/contexts/{contextId}/transfer": {
Expand Down
53 changes: 53 additions & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export type paths = {
get: operations["context-show"];
/** [api v2] Update an existing context and return it */
put: operations["context-update"];
/** [api v2] Delete an existing context and return it */
delete: operations["context-destroy"];
};
"/ocs/v2.php/apps/tables/api/2/contexts/{contextId}/transfer": {
/** [api v2] Transfer the ownership of a context and return it */
Expand Down Expand Up @@ -3164,6 +3166,57 @@ export type operations = {
};
};
};
/** [api v2] Delete an existing context and return it */
"context-destroy": {
parameters: {
header: {
/** @description Required to be true for the API request to pass */
"OCS-APIRequest": boolean;
};
path: {
/** @description ID of the context */
contextId: number;
};
};
responses: {
/** @description returning the full context information */
200: {
content: {
"application/json": {
ocs: {
meta: components["schemas"]["OCSMeta"];
data: components["schemas"]["Context"];
};
};
};
};
/** @description Not found */
404: {
content: {
"application/json": {
ocs: {
meta: components["schemas"]["OCSMeta"];
data: {
message: string;
};
};
};
};
};
500: {
content: {
"application/json": {
ocs: {
meta: components["schemas"]["OCSMeta"];
data: {
message: string;
};
};
};
};
};
};
};
/** [api v2] Transfer the ownership of a context and return it */
"context-transfer": {
parameters: {
Expand Down

0 comments on commit b10f12d

Please sign in to comment.