diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-11-28 22:07:29 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-12-01 12:48:24 +0100 |
commit | 37237dc1831d437e10ed47a2799443ba2831f684 (patch) | |
tree | 55918aa088236f018866d243ce82d0c2df01457b /apps/user_ldap | |
parent | 18e6c9f5bc95c9c96755cac5b514c4f12f86435b (diff) | |
download | nextcloud-server-37237dc1831d437e10ed47a2799443ba2831f684.tar.gz nextcloud-server-37237dc1831d437e10ed47a2799443ba2831f684.zip |
feat(LDAP): warn about demoting a group while promoting another
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/Command/PromoteGroup.php | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/apps/user_ldap/lib/Command/PromoteGroup.php b/apps/user_ldap/lib/Command/PromoteGroup.php index 5fc3905414f..7ec18064332 100644 --- a/apps/user_ldap/lib/Command/PromoteGroup.php +++ b/apps/user_ldap/lib/Command/PromoteGroup.php @@ -61,21 +61,36 @@ class PromoteGroup extends Command { ); } + protected function formatGroupName(IGroup $group): string { + $idLabel = ''; + if ($group->getGID() !== $group->getDisplayName()) { + $idLabel = sprintf(' (Group ID: %s)', $group->getGID()); + } + return sprintf('%s%s', $group->getDisplayName(), $idLabel); + } + protected function promoteGroup(IGroup $group, InputInterface $input, OutputInterface $output): void { - if ($input->getOption('yes') === false) { - /** @var QuestionHelper $helper */ - $helper = $this->getHelper('question'); + $access = $this->backend->getLDAPAccess($group->getGID()); + $currentlyPromotedGroupId = $access->connection->ldapAdminGroup; + if ($currentlyPromotedGroupId === $group->getGID()) { + $output->writeln('<info>The specified group is already promoted</info>'); + return; + } - $idLabel = ''; - if ($group->getGID() !== $group->getDisplayName()) { - $idLabel = sprintf(' (Group ID: %s)', $group->getGID()); + if ($input->getOption('yes') === false) { + $currentlyPromotedGroup = $this->groupManager->get($currentlyPromotedGroupId); + $demoteLabel = ''; + if ($currentlyPromotedGroup instanceof IGroup && $this->backend->groupExists($currentlyPromotedGroup->getGID())) { + $groupNameLabel = $this->formatGroupName($currentlyPromotedGroup); + $demoteLabel = sprintf('and demote %s ', $groupNameLabel); } - $q = new Question(sprintf('Promote %s%s to the admin group (y|N)? ', $group->getDisplayName(), $idLabel)); + /** @var QuestionHelper $helper */ + $helper = $this->getHelper('question'); + $q = new Question(sprintf('Promote %s to the admin group %s(y|N)? ', $this->formatGroupName($group), $demoteLabel)); $input->setOption('yes', $helper->ask($input, $output, $q) === 'y'); } if ($input->getOption('yes') === true) { - $access = $this->backend->getLDAPAccess($group->getGID()); $access->connection->setConfiguration(['ldapAdminGroup' => $group->getGID()]); $access->connection->saveConfiguration(); $output->writeln(sprintf('<info>Group %s was promoted</info>', $group->getDisplayName())); |