Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
pivnicek committed Oct 3, 2023
1 parent 186a3dc commit fbded23
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/Keboola/Console/Command/RemoveUserFromOrganizationProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,43 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$projects = $organization['projects'];
$output->writeln(
sprintf(
'Removing %s from "%d" projects',
$userEmail,
count($projects)
'Checking "%d" projects for user %s',
count($projects),
$userEmail
)
);
$affectedProjects = 0;
foreach ($projects as $project) {
$output->writeln(sprintf(
'Removing user "%s" from project "%d":"%s"',
$projectUsers = $manageClient->listProjectUsers((int) $project['id']);
if ($this->isUserInProject((int) $user['id'], $projectUsers)) {
$output->writeln(sprintf(
'Removing user "%s" from project "%d":"%s"',
$userEmail,
$project['id'],
$project['name']
));
if ($force) {
$manageClient->removeUserFromProject((int) $project['id'], $user['id']);
}
$affectedProjects++;
}
}
$output->writeln(
sprintf(
'Finished. %s has been removed from %d projects.',
$userEmail,
$project['id'],
$project['name']
));
if ($force) {
$manageClient->removeUserFromProject($project['id'], $user['id']);
$affectedProjects
)
);
}

private function isUserInProject(int $userId, array $projectUsers): bool
{
foreach ($projectUsers as $projectUser) {
if ((int) $projectUser['id'] === $userId) {
return true;
}
}
return false;
}
}

0 comments on commit fbded23

Please sign in to comment.