Skip to content

Commit

Permalink
fixup! Add check-group command
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Jul 20, 2023
1 parent 5d41883 commit 52441b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/user_ldap/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ A user logs into Nextcloud with their LDAP or AD credentials, and is granted acc

<commands>
<command>OCA\User_LDAP\Command\CheckUser</command>
<command>OCA\User_LDAP\Command\CheckGroup</command>
<command>OCA\User_LDAP\Command\CreateEmptyConfig</command>
<command>OCA\User_LDAP\Command\DeleteConfig</command>
<command>OCA\User_LDAP\Command\ResetGroup</command>
Expand Down
24 changes: 8 additions & 16 deletions apps/user_ldap/lib/Command/CheckGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Service\UpdateGroupsService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -41,6 +42,7 @@

class CheckGroup extends Command {
public function __construct(
private UpdateGroupsService $service,
protected Group_Proxy $backend,
protected Helper $helper,
protected GroupMapping $mapping,
Expand Down Expand Up @@ -87,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($exists === true) {
$output->writeln('The group is still available on LDAP.');
if ($input->getOption('update')) {
$this->updateGroup($gid, $output);
$this->updateGroup($gid, $output, $wasMapped);
}
return 0;
} elseif ($wasMapped) {
Expand Down Expand Up @@ -126,23 +128,13 @@ protected function assertAllowed(bool $force): void {
// background job.
}

private function updateGroup(string $gid, OutputInterface $output): void {
private function updateGroup(string $gid, OutputInterface $output, bool $wasMapped): void {
try {
$access = $this->backend->getLDAPAccess($gid);
$attrs = $access->userManager->getAttributes();
$user = $access->userManager->get($gid);
$avatarAttributes = $access->getConnection()->resolveRule('avatar');
$result = $access->search('objectclass=*', $user->getDN(), $attrs, 1, 0);
foreach ($result[0] as $attribute => $valueSet) {
$output->writeln(' ' . $attribute . ': ');
foreach ($valueSet as $value) {
if (in_array($attribute, $avatarAttributes)) {
$value = '{ImageData}';
}
$output->writeln(' ' . $value);
}
if ($wasMapped) {
$this->service->handleKnownGroups([$gid]);
} else {
$this->service->handleCreatedGroups([$gid]);
}
$access->batchApplyUserAttributes($result);
} catch (\Exception $e) {
$output->writeln('<error>Error while trying to lookup and update attributes from LDAP</error>');
}
Expand Down
12 changes: 9 additions & 3 deletions apps/user_ldap/lib/Service/UpdateGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,19 @@ public function handleCreatedGroups(array $createdGroups): void {
$this->logger->info('service "updateGroups" – new group "' . $createdGroup . '" found.');

$users = $this->groupBackend->usersInGroup($createdGroup);
foreach ($users as $user) {
$this->groupMembershipMapper->insert(GroupMembership::fromParams(['groupid' => $createdGroup,'userid' => $user]));
}
$groupObject = $this->groupManager->get($group);

Check failure on line 150 in apps/user_ldap/lib/Service/UpdateGroupsService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

apps/user_ldap/lib/Service/UpdateGroupsService.php:150:44: UndefinedVariable: Cannot find referenced variable $group (see https://psalm.dev/024)

Check failure

Code scanning / Psalm

UndefinedVariable Error

Cannot find referenced variable $group
if ($groupObject instanceof IGroup) {

Check failure on line 151 in apps/user_ldap/lib/Service/UpdateGroupsService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/user_ldap/lib/Service/UpdateGroupsService.php:151:32: UndefinedClass: Class, interface or enum named OCA\User_LDAP\Service\IGroup does not exist (see https://psalm.dev/019)

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCA\User_LDAP\Service\IGroup does not exist
$this->dispatcher->dispatchTyped(new GroupCreatedEvent($groupObject));

Check failure on line 152 in apps/user_ldap/lib/Service/UpdateGroupsService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/user_ldap/lib/Service/UpdateGroupsService.php:152:38: InvalidArgument: Argument 1 of OCP\EventDispatcher\IEventDispatcher::dispatchTyped expects OCP\EventDispatcher\Event, but OCA\User_LDAP\Service\GroupCreatedEvent provided (see https://psalm.dev/004)

Check failure on line 152 in apps/user_ldap/lib/Service/UpdateGroupsService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/user_ldap/lib/Service/UpdateGroupsService.php:152:42: UndefinedClass: Class, interface or enum named OCA\User_LDAP\Service\GroupCreatedEvent does not exist (see https://psalm.dev/019)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OCP\EventDispatcher\IEventDispatcher::dispatchTyped expects OCP\EventDispatcher\Event, but OCA\User_LDAP\Service\GroupCreatedEvent provided

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCA\User_LDAP\Service\GroupCreatedEvent does not exist
}
foreach ($users as $user) {
$this->groupMembershipMapper->insert(GroupMembership::fromParams(['groupid' => $createdGroup,'userid' => $user]));
if ($groupObject instanceof IGroup) {

Check failure on line 156 in apps/user_ldap/lib/Service/UpdateGroupsService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/user_ldap/lib/Service/UpdateGroupsService.php:156:33: UndefinedClass: Class, interface or enum named OCA\User_LDAP\Service\IGroup does not exist (see https://psalm.dev/019)

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCA\User_LDAP\Service\IGroup does not exist
$userObject = $this->userManager->get($user);
if ($userObject instanceof IUser) {
$this->dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject));
}
}
}
}
$this->logger->debug('service "updateGroups" – FINISHED dealing with created Groups.');
}
Expand Down

0 comments on commit 52441b8

Please sign in to comment.