From 4e4fcc06fde6b398ffcbc04e09644690012433f4 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:27:04 -0400 Subject: [PATCH] refactor: Project deletion in worker --- app/controllers/api/teams.php | 12 ++++++++-- app/init.php | 2 +- src/Appwrite/Platform/Workers/Deletes.php | 28 ++++------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index db98ddd1d9..474a94faca 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -4,6 +4,7 @@ use Appwrite\Auth\Auth; use Appwrite\Auth\MFA\Type\TOTP; use Appwrite\Auth\Validator\Phone; use Appwrite\Detector\Detector; +use Appwrite\Event\Delete; use Appwrite\Event\Event; use Appwrite\Event\Mail; use Appwrite\Event\Messaging; @@ -341,9 +342,10 @@ App::delete('/v1/teams/:teamId') ->inject('getProjectDB') ->inject('dbForProject') ->inject('dbForConsole') + ->inject('queueForDeletes') ->inject('queueForEvents') ->inject('project') - ->action(function (string $teamId, Response $response, callable $getProjectDB, Database $dbForProject, Database $dbForConsole, Event $queueForEvents, Document $project) { + ->action(function (string $teamId, Response $response, callable $getProjectDB, Database $dbForProject, Database $dbForConsole, Delete $queueForDeletes, Event $queueForEvents, Document $project) { $team = $dbForProject->getDocument('teams', $teamId); @@ -356,7 +358,13 @@ App::delete('/v1/teams/:teamId') } $deletes = new Deletes(); - $deletes->deleteTeam($dbForConsole, $getProjectDB, $team, $project); + $deletes->deleteMemberships($getProjectDB, $team, $project); + + if ($project->getId() === 'console') { + $queueForDeletes + ->setType(DELETE_TYPE_TEAM_PROJECTS) + ->setDocument($team); + } $queueForEvents ->setParam('teamId', $team->getId()) diff --git a/app/init.php b/app/init.php index c6fe6e2409..981198058c 100644 --- a/app/init.php +++ b/app/init.php @@ -167,7 +167,7 @@ const DELETE_TYPE_PROJECTS = 'projects'; const DELETE_TYPE_FUNCTIONS = 'functions'; const DELETE_TYPE_DEPLOYMENTS = 'deployments'; const DELETE_TYPE_USERS = 'users'; -const DELETE_TYPE_TEAMS = 'teams'; +const DELETE_TYPE_TEAM_PROJECTS = 'teams_projects'; const DELETE_TYPE_EXECUTIONS = 'executions'; const DELETE_TYPE_AUDIT = 'audit'; const DELETE_TYPE_ABUSE = 'abuse'; diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 0f1dcce96b..7d164c2b5d 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -95,9 +95,6 @@ class Deletes extends Action case DELETE_TYPE_USERS: $this->deleteUser($getProjectDB, $document, $project); break; - case DELETE_TYPE_TEAMS: - $this->deleteTeam($dbForConsole, $getProjectDB, $document, $project); - break; case DELETE_TYPE_BUCKETS: $this->deleteBucket($getProjectDB, $deviceForFiles, $document, $project); break; @@ -112,6 +109,9 @@ class Deletes extends Action break; } break; + case DELETE_TYPE_TEAM_PROJECTS: + $this->deleteProjectsByTeam($dbForConsole, $getProjectDB, $document); + break; case DELETE_TYPE_EXECUTIONS: $this->deleteExecutionLogs($project, $getProjectDB, $executionRetention); break; @@ -416,7 +416,7 @@ class Deletes extends Action * @return void * @throws Exception */ - private function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void + public function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void { $dbForProject = $getProjectDB($project); $teamInternalId = $document->getInternalId(); @@ -1162,24 +1162,4 @@ class Deletes extends Action ); } } - - /** - * @param Database $dbForConsole - * @param callable $getProjectDB - * @param Document $team - * @param Document $project - * @throws Authorization - * @throws Conflict - * @throws DatabaseException - * @throws Exception - * @throws Restricted - * @throws Structure - */ - public function deleteTeam(Database $dbForConsole, callable $getProjectDB, Document $team, Document $project): void - { - $this->deleteMemberships($getProjectDB, $team, $project); - if ($project->getId() === 'console') { - $this->deleteProjectsByTeam($dbForConsole, $getProjectDB, $team); - } - } }