delete leftovers & reserve id
- delete team memberships - create a reserved id
This commit is contained in:
parent
6bcbf113bc
commit
4c6a300a22
|
@ -1187,6 +1187,13 @@ $collections = [
|
|||
],
|
||||
],
|
||||
],
|
||||
Database::SYSTEM_COLLECTION_RESERVED => [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS,
|
||||
'$id' => Database::SYSTEM_COLLECTION_RESERVED,
|
||||
'$permissions' => ['read' => ['*']],
|
||||
'name' => 'Reserved',
|
||||
'structure' => true,
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
|
|
|
@ -208,6 +208,19 @@ $utopia->delete('/v1/users/:userId')
|
|||
if (!$projectDB->deleteDocument($userId)) {
|
||||
throw new Exception('Failed to remove file from DB', 500);
|
||||
}
|
||||
|
||||
$reservedId = $projectDB->createDocument([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RESERVED,
|
||||
'$id' => $userId,
|
||||
'$permissions' => [
|
||||
'read' => ['*'],
|
||||
],
|
||||
]);
|
||||
|
||||
if (false === $reservedId) {
|
||||
throw new Exception('Failed saving reserved id to DB', 500);
|
||||
}
|
||||
|
||||
$tokens = $user->getAttribute('tokens', []);
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
|
@ -216,6 +229,21 @@ $utopia->delete('/v1/users/:userId')
|
|||
}
|
||||
}
|
||||
|
||||
$memberships = $projectDB->getCollection([
|
||||
'limit' => 2000,
|
||||
'offset' => 0,
|
||||
'filters' => [
|
||||
'$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS,
|
||||
'userId='.$userId,
|
||||
],
|
||||
]);
|
||||
|
||||
foreach ($memberships as $membership) {
|
||||
if (!$projectDB->deleteDocument($membership->getId())) {
|
||||
throw new Exception('Failed to remove team membership from DB', 500);
|
||||
}
|
||||
}
|
||||
|
||||
$response->noContent();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -23,6 +23,7 @@ class Database
|
|||
const SYSTEM_COLLECTION_USAGES = 'usages'; //TODO add structure
|
||||
const SYSTEM_COLLECTION_DOMAINS = 'domains';
|
||||
const SYSTEM_COLLECTION_CERTIFICATES = 'certificates';
|
||||
const SYSTEM_COLLECTION_RESERVED = 'reserved';
|
||||
|
||||
// Auth, Account and Users (private to user)
|
||||
const SYSTEM_COLLECTION_USERS = 'users';
|
||||
|
|
Loading…
Reference in a new issue