1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

delete leftovers & reserve id

- delete team memberships
- create a reserved id
This commit is contained in:
Torsten Dittmann 2020-07-02 23:48:37 +02:00
parent 6bcbf113bc
commit 4c6a300a22
3 changed files with 36 additions and 0 deletions

View file

@ -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,
],
];
/*

View file

@ -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();
}
);

View file

@ -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';