1
0
Fork 0
mirror of synced 2024-07-03 21:50:34 +12:00

Ensure permissions are updated when a project moves orgs

Since the following collections also have permissions set to the team,
the team should be updated for consistency:

- installations
- repositories
- vcsComments
This commit is contained in:
Steven Nguyen 2023-10-12 17:34:53 -07:00
parent 3bb22c38cc
commit 3f2f6ab43a
No known key found for this signature in database

View file

@ -481,16 +481,43 @@ App::patch('/v1/projects/:projectId/team')
throw new Exception(Exception::TEAM_NOT_FOUND);
}
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project
$permissions = [
Permission::read(Role::team(ID::custom($teamId))),
Permission::update(Role::team(ID::custom($teamId), 'owner')),
Permission::update(Role::team(ID::custom($teamId), 'developer')),
Permission::delete(Role::team(ID::custom($teamId), 'owner')),
Permission::delete(Role::team(ID::custom($teamId), 'developer')),
];
$project
->setAttribute('teamId', $teamId)
->setAttribute('teamInternalId', $team->getInternalId())
->setAttribute('$permissions', [
Permission::read(Role::team(ID::custom($teamId))),
Permission::update(Role::team(ID::custom($teamId), 'owner')),
Permission::update(Role::team(ID::custom($teamId), 'developer')),
Permission::delete(Role::team(ID::custom($teamId), 'owner')),
Permission::delete(Role::team(ID::custom($teamId), 'developer')),
]));
->setAttribute('$permissions', $permissions);
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project);
$installations = $dbForConsole->find('installations', [
Query::equal('projectInternalId', [$project->getInternalId()]),
]);
foreach ($installations as $installation) {
$installation->getAttribute('$permissions', $permissions);
$dbForConsole->updateDocument('installations', $installation->getId(), $installation);
}
$repositories = $dbForConsole->find('repositories', [
Query::equal('projectInternalId', [$project->getInternalId()]),
]);
foreach ($repositories as $repository) {
$repository->getAttribute('$permissions', $permissions);
$dbForConsole->updateDocument('repositories', $repository->getId(), $repository);
}
$vcsComments = $dbForConsole->find('vcsComments', [
Query::equal('projectInternalId', [$project->getInternalId()]),
]);
foreach ($vcsComments as $vcsComment) {
$vcsComment->getAttribute('$permissions', $permissions);
$dbForConsole->updateDocument('vcsComments', $vcsComment->getId(), $vcsComment);
}
$response->dynamic($project, Response::MODEL_PROJECT);
});