diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php new file mode 100644 index 0000000000..fc8d5cccfc --- /dev/null +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Delete.php @@ -0,0 +1,93 @@ +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: <<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(); + } +} diff --git a/src/Appwrite/Platform/Modules/Organization/Services/Http.php b/src/Appwrite/Platform/Modules/Organization/Services/Http.php index 4a7cd69220..49a8f7d832 100644 --- a/src/Appwrite/Platform/Modules/Organization/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Organization/Services/Http.php @@ -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()); } }