Skip to content

Commit

Permalink
fixed stale team memberships on user
Browse files Browse the repository at this point in the history
  • Loading branch information
safwanyp committed Aug 1, 2023
1 parent fcd4a69 commit 0fe59d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/api/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,17 @@
Query::limit(2000), // TODO fix members limit
]);

// TODO delete all members individually from the user object
foreach ($memberships as $membership) {
if (!$dbForProject->deleteDocument('memberships', $membership->getId())) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove membership for team from DB');
}

$user = $dbForProject->getDocument('users', $membership->getAttribute('userId'));
$user->setAttribute('memberships', array_values(array_filter(
$user->getAttribute('memberships', []),
fn($um) => $um['teamId'] !== $membership->getAttribute('teamId'))
));
$dbForProject->updateDocument('users', $user->getId(), $user);
}

if (!$dbForProject->deleteDocument('teams', $teamId)) {
Expand Down

0 comments on commit 0fe59d4

Please sign in to comment.