Skip to content

Commit

Permalink
fix(Controller): remove unneeded endpoints
Browse files Browse the repository at this point in the history
- nodes can be added and removed via `update()`, this is what web UI uses

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 10, 2024
1 parent 26b5216 commit b1d1cec
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 589 deletions.
2 changes: 0 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
['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'],
['name' => 'Context#updateContentOrder', 'url' => '/api/2/contexts/{contextId}/pages/{pageId}', 'verb' => 'PUT'],
]
];
70 changes: 0 additions & 70 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,76 +235,6 @@ public function transfer(int $contextId, string $newOwnerId, int $newOwnerType =
}
}

/**
* [api v2] Add a node to a Context
*
* @param int $contextId ID of the context
* @param int $nodeId ID of the node
* @param int $nodeType any Application::NODE_TYPE_* constant
* @param int $permissions bitmask of the permissions for context recipients
* @param ?int $order in which order the node should appear within the context
*
* @return DataResponse<Http::STATUS_OK, TablesContext, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Node added successfully
* 403: No permissions
* 404: Not found
*
* @NoAdminRequired
* @CanManageNode
*/
public function addNode(int $contextId, int $nodeId, int $nodeType, int $permissions, ?int $order = null): DataResponse {
try {
$rel = $this->contextService->addNodeToContextById($contextId, $nodeId, $nodeType, $permissions, $this->userId);
$this->contextService->addNodeRelToPage($rel, $order);
$context = $this->contextService->findById($rel->getContextId(), $this->userId);
return new DataResponse($context->jsonSerialize());
} catch (NotFoundError $e) {
return $this->handleNotFoundError($e);
} catch (DoesNotExistException $e) {
return $this->handleNotFoundError(new NotFoundError($e->getMessage(), $e->getCode(), $e));
} catch (MultipleObjectsReturnedException|Exception|InternalError $e) {
return $this->handleError($e);
}
}

/**
* [api v2] Remove a node from a Context
*
* @param int $contextId ID of the context
* @param int $nodeRelId ID of the node-in-context relation
*
* @return DataResponse<Http::STATUS_OK, TablesContext, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
*
* 200: Node removed successfully
* 400: Invalid request
* 403: No permissions
* 404: Not found
*
* @NoAdminRequired
* @CanManageContext
*/
public function removeNode(int $contextId, int $nodeRelId): DataResponse {
// we could do without the contextId, however it is used by the Permission Middleware
// and also results in a more consistent endpoint url
try {
$context = $this->contextService->findById($contextId, $this->userId);
if (!isset($context->getNodes()[$nodeRelId])) {
return $this->handleBadRequestError(new BadRequestError('Node Relation ID not found in given Context'));
}
$nodeRelation = $this->contextService->removeNodeFromContextById($nodeRelId);
$this->contextService->removeNodeRelFromAllPages($nodeRelation);
$context = $this->contextService->findById($contextId, $this->userId);
return new DataResponse($context->jsonSerialize());
} catch (NotFoundError $e) {
return $this->handleNotFoundError($e);
} catch (DoesNotExistException $e) {
return $this->handleNotFoundError(new NotFoundError($e->getMessage(), $e->getCode(), $e));
} catch (MultipleObjectsReturnedException|Exception|InternalError $e) {
return $this->handleError($e);
}
}

/**
* [api v2] Update the order on a page of a context
*
Expand Down
Loading

0 comments on commit b1d1cec

Please sign in to comment.