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:
parent
3bb22c38cc
commit
3f2f6ab43a
1 changed files with 35 additions and 8 deletions
|
@ -481,16 +481,43 @@ App::patch('/v1/projects/:projectId/team')
|
||||||
throw new Exception(Exception::TEAM_NOT_FOUND);
|
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('teamId', $teamId)
|
||||||
->setAttribute('teamInternalId', $team->getInternalId())
|
->setAttribute('teamInternalId', $team->getInternalId())
|
||||||
->setAttribute('$permissions', [
|
->setAttribute('$permissions', $permissions);
|
||||||
Permission::read(Role::team(ID::custom($teamId))),
|
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project);
|
||||||
Permission::update(Role::team(ID::custom($teamId), 'owner')),
|
|
||||||
Permission::update(Role::team(ID::custom($teamId), 'developer')),
|
$installations = $dbForConsole->find('installations', [
|
||||||
Permission::delete(Role::team(ID::custom($teamId), 'owner')),
|
Query::equal('projectInternalId', [$project->getInternalId()]),
|
||||||
Permission::delete(Role::team(ID::custom($teamId), 'developer')),
|
]);
|
||||||
]));
|
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);
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue