Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix check-group command for new groups
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Aug 10, 2023
commit 1026b2131c53d074cf71e8e3ca4766b0a1b4ead3
18 changes: 12 additions & 6 deletions apps/user_ldap/lib/Command/CheckGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$this->assertAllowed($input->getOption('force'));
$gid = $input->getArgument('ocName');
$wasMapped = $this->groupWasMapped($gid);
if ($this->backend->getLDAPAccess($gid)->stringResemblesDN($gid)) {
$groupname = $this->backend->dn2GroupName($gid);
if ($groupname !== false) {
$gid = $groupname;
}
}
$wasMapped = $this->groupWasMapped($gid);
/* Search to trigger mapping for new groups */
$this->backend->getGroups($gid);
$exists = $this->backend->groupExistsOnLDAP($gid, true);
if ($exists === true) {
$output->writeln('The group is still available on LDAP.');
Expand All @@ -113,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

public function onGroupCreatedEvent(GroupChangedEvent $event, OutputInterface $output): void {
public function onGroupCreatedEvent(GroupCreatedEvent $event, OutputInterface $output): void {
$output->writeln('<info>The group '.$event->getGroup()->getGID().' was added to Nextcloud with '.$event->getGroup()->count().' users</info>');
}

Expand All @@ -131,11 +133,15 @@ public function onUserRemovedEvent(UserRemovedEvent $event, OutputInterface $out

/**
* checks whether a group is actually mapped
* @param string $ocName the groupname as used in Nextcloud
* @param string $gid the groupname as passed to the command
*/
protected function groupWasMapped(string $ocName): bool {
$dn = $this->mapping->getDNByName($ocName);
return $dn !== false;
protected function groupWasMapped(string $gid): bool {
$dn = $this->mapping->getDNByName($gid);
if ($dn !== false) {
return true;
}
$name = $this->mapping->getNameByDN($gid);
return $name !== false;
}

/**
Expand Down