Add missing delete endpoint

This commit is contained in:
Matej Bačo
2026-05-20 13:49:40 +02:00
parent e69b9eb428
commit cbcf86e362
2 changed files with 95 additions and 0 deletions
@@ -0,0 +1,93 @@
<?php
namespace Appwrite\Platform\Modules\Organization\Http\Projects;
use Appwrite\Event\Message\Delete as DeleteMessage;
use Appwrite\Event\Publisher\Delete as DeletePublisher;
use Appwrite\Extend\Exception;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\ContentType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Response;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID;
use Utopia\Platform\Scope\HTTP;
class Delete extends Action
{
use HTTP;
public static function getName()
{
return 'deleteOrganizationProject';
}
public function __construct()
{
$this
->setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE)
->setHttpPath('/v1/organization/projects/:projectId')
->desc('Delete organization project')
->groups(['api', 'organization'])
->label('scope', 'projects.write')
->label('audits.event', 'projects.delete')
->label('audits.resource', 'project/{request.projectId}')
->label('sdk', new Method(
namespace: 'organization',
group: 'projects',
name: 'deleteProject',
description: <<<EOT
Delete a project by its unique ID.
EOT,
auth: [AuthType::ADMIN, AuthType::KEY],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_NOCONTENT,
model: Response::MODEL_NONE,
)
],
contentType: ContentType::NONE
))
->param('projectId', '', new UID(), 'Project unique ID.')
->inject('response')
->inject('dbForPlatform')
->inject('publisherForDeletes')
->inject('authorization')
->inject('team')
->callback($this->action(...));
}
public function action(
string $projectId,
Response $response,
Database $dbForPlatform,
DeletePublisher $publisherForDeletes,
Authorization $authorization,
Document $team,
) {
$project = $dbForPlatform->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
if ($project->getAttribute('teamInternalId') !== $team->getSequence()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
if (!$authorization->skip(fn () => $dbForPlatform->deleteDocument('projects', $project->getId()))) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove project from DB');
}
$publisherForDeletes->enqueue(new DeleteMessage(
project: $project,
type: DELETE_TYPE_DOCUMENT,
document: $project,
));
$response->noContent();
}
}
@@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Organization\Services;
use Appwrite\Platform\Modules\Organization\Http\Init as Init;
use Appwrite\Platform\Modules\Organization\Http\Projects\Create as CreateProject;
use Appwrite\Platform\Modules\Organization\Http\Projects\Delete as DeleteProject;
use Appwrite\Platform\Modules\Organization\Http\Projects\Get as GetProject;
use Appwrite\Platform\Modules\Organization\Http\Projects\Update as UpdateProject;
use Appwrite\Platform\Modules\Organization\Http\Projects\XList as ListProjects;
@@ -23,5 +24,6 @@ class Http extends Service
$this->addAction(ListProjects::getName(), new ListProjects());
$this->addAction(GetProject::getName(), new GetProject());
$this->addAction(UpdateProject::getName(), new UpdateProject());
$this->addAction(DeleteProject::getName(), new DeleteProject());
}
}