mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add async key cleanup
This commit is contained in:
@@ -431,15 +431,23 @@ App::delete('/v1/teams/:teamId')
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove team from DB');
|
||||
}
|
||||
|
||||
$clone = clone $team;
|
||||
|
||||
// Sync delete
|
||||
$deletes = new Deletes();
|
||||
$deletes->deleteMemberships($getProjectDB, $team, $project);
|
||||
$deletes->deleteMemberships($getProjectDB, $clone, $project);
|
||||
|
||||
if ($project->getId() === 'console') {
|
||||
$queueForDeletes
|
||||
->setType(DELETE_TYPE_TEAM_PROJECTS)
|
||||
->setDocument($team);
|
||||
->setDocument($clone);
|
||||
}
|
||||
|
||||
// Async delete
|
||||
$queueForDeletes
|
||||
->setType(DELETE_TYPE_DOCUMENT)
|
||||
->setDocument($clone);
|
||||
|
||||
$queueForEvents
|
||||
->setParam('teamId', $team->getId())
|
||||
->setPayload($response->output($team, Response::MODEL_TEAM))
|
||||
|
||||
@@ -189,6 +189,7 @@ const DELETE_TYPE_SITES = 'sites';
|
||||
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';
|
||||
|
||||
@@ -120,6 +120,9 @@ class Deletes extends Action
|
||||
case DELETE_TYPE_USERS:
|
||||
$this->deleteUser($getProjectDB, $document, $project);
|
||||
break;
|
||||
case DELETE_TYPE_TEAMS:
|
||||
$this->deleteTeam($getProjectDB, $document, $project);
|
||||
break;
|
||||
case DELETE_TYPE_BUCKETS:
|
||||
$this->deleteBucket($getProjectDB, $deviceForFiles, $document, $project);
|
||||
break;
|
||||
@@ -634,6 +637,24 @@ class Deletes extends Action
|
||||
$deviceForCache->delete($deviceForCache->getRoot(), true);
|
||||
}
|
||||
|
||||
private function deleteTeam(callable $getProjectDB, Document $document, Document $project): void
|
||||
{
|
||||
$teamId = $document->getId();
|
||||
$teamInternalId = $document->getSequence();
|
||||
$dbForProject = $getProjectDB($project);
|
||||
|
||||
if ($project->getId() === 'console') {
|
||||
// Delete Keys
|
||||
$this->deleteByGroup('keys', [
|
||||
Query::equal('resourceInternalId', [$teamInternalId]),
|
||||
Query::equal('resourceType', ['teams']),
|
||||
Query::orderAsc()
|
||||
], $dbForProject);
|
||||
}
|
||||
|
||||
$dbForProject->purgeCachedDocument('teams', $teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $getProjectDB
|
||||
* @param Document $document user document
|
||||
@@ -653,6 +674,15 @@ class Deletes extends Action
|
||||
Query::orderAsc()
|
||||
], $dbForProject);
|
||||
|
||||
if ($project->getId() === 'console') {
|
||||
// Delete Keys
|
||||
$this->deleteByGroup('keys', [
|
||||
Query::equal('resourceInternalId', [$userInternalId]),
|
||||
Query::equal('resourceType', ['users']),
|
||||
Query::orderAsc()
|
||||
], $dbForProject);
|
||||
}
|
||||
|
||||
$dbForProject->purgeCachedDocument('users', $userId);
|
||||
|
||||
// Delete Memberships and decrement team membership counts
|
||||
|
||||
Reference in New Issue
Block a user