Skip to content

Commit

Permalink
Add output to check-group --update command
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Aug 1, 2023
1 parent 8e86b35 commit 8c80749
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion apps/user_ldap/lib/Command/CheckGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@

namespace OCA\User_LDAP\Command;

use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Service\UpdateGroupsService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\GroupCreatedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -46,6 +50,7 @@ public function __construct(
protected Group_Proxy $backend,
protected Helper $helper,
protected GroupMapping $mapping,
protected IEventDispatcher $dispatcher,
) {
parent::__construct();
}
Expand Down Expand Up @@ -75,6 +80,9 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->dispatcher->addListener(GroupCreatedEvent::class, fn ($event) => $this->onGroupCreatedEvent($event, $output));

Check failure on line 83 in apps/user_ldap/lib/Command/CheckGroup.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/user_ldap/lib/Command/CheckGroup.php:83:102: InvalidArgument: Argument 1 of OCA\User_LDAP\Command\CheckGroup::onGroupCreatedEvent expects OCA\User_LDAP\Command\GroupChangedEvent, but OCP\EventDispatcher\Event provided (see https://psalm.dev/004)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OCA\User_LDAP\Command\CheckGroup::onGroupCreatedEvent expects OCA\User_LDAP\Command\GroupChangedEvent, but OCP\EventDispatcher\Event provided
$this->dispatcher->addListener(UserAddedEvent::class, fn ($event) => $this->onUserAddedEvent($event, $output));

Check notice

Code scanning / Psalm

ArgumentTypeCoercion Note

Argument 1 of OCA\User_LDAP\Command\CheckGroup::onUserAddedEvent expects OCP\Group\Events\UserAddedEvent, but parent type OCP\EventDispatcher\Event provided
$this->dispatcher->addListener(UserRemovedEvent::class, fn ($event) => $this->onUserRemovedEvent($event, $output));

Check notice

Code scanning / Psalm

ArgumentTypeCoercion Note

Argument 1 of OCA\User_LDAP\Command\CheckGroup::onUserRemovedEvent expects OCP\Group\Events\UserRemovedEvent, but parent type OCP\EventDispatcher\Event provided
try {
$this->assertAllowed($input->getOption('force'));
$gid = $input->getArgument('ocName');
Expand Down Expand Up @@ -105,6 +113,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

public function onGroupCreatedEvent(GroupChangedEvent $event, OutputInterface $output): void {

Check failure on line 116 in apps/user_ldap/lib/Command/CheckGroup.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/user_ldap/lib/Command/CheckGroup.php:116:38: UndefinedClass: Class, interface or enum named OCA\User_LDAP\Command\GroupChangedEvent does not exist (see https://psalm.dev/019)

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCA\User_LDAP\Command\GroupChangedEvent does not exist
$output->writeln('<info>The group '.$event->getGroup()->getGID().' was added to Nextcloud with '.$event->getGroup()->count().' users</info>');
}

public function onUserAddedEvent(UserAddedEvent $event, OutputInterface $output): void {
$user = $event->getUser();
$group = $event->getGroup();
$output->writeln('<info>The user '.$user->getUID().' was added to group '.$group->getGID().'</info>');
}

public function onUserRemovedEvent(UserRemovedEvent $event, OutputInterface $output): void {
$user = $event->getUser();
$group = $event->getGroup();
$output->writeln('<info>The user '.$user->getUID().' was removed from group '.$group->getGID().'</info>');
}

/**
* checks whether a group is actually mapped
* @param string $ocName the groupname as used in Nextcloud
Expand Down

0 comments on commit 8c80749

Please sign in to comment.