Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: propagate group name changes #1829

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\Circles\Listeners\Files\PreparingShareSendMail as ListenerFilesPreparingShareSendMail;
use OCA\Circles\Listeners\Files\RemovingMember as ListenerFilesRemovingMember;
use OCA\Circles\Listeners\Files\ShareCreatedSendMail as ListenerFilesShareCreatedSendMail;
use OCA\Circles\Listeners\GroupChanged;
use OCA\Circles\Listeners\GroupCreated;
use OCA\Circles\Listeners\GroupDeleted;
use OCA\Circles\Listeners\GroupMemberAdded;
Expand All @@ -52,6 +53,7 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Group\Events\GroupChangedEvent;
use OCP\Group\Events\GroupCreatedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
Expand Down Expand Up @@ -98,6 +100,7 @@ public function register(IRegistrationContext $context): void {

// Group Events
$context->registerEventListener(GroupCreatedEvent::class, GroupCreated::class);
$context->registerEventListener(GroupChangedEvent::class, GroupChanged::class);
$context->registerEventListener(GroupDeletedEvent::class, GroupDeleted::class);
$context->registerEventListener(UserAddedEvent::class, GroupMemberAdded::class);
$context->registerEventListener(UserRemovedEvent::class, GroupMemberRemoved::class);
Expand Down
55 changes: 55 additions & 0 deletions lib/Listeners/GroupChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Circles\Listeners;

use OCA\Circles\Exceptions\CircleNotFoundException;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\FederatedUserService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Group\Events\GroupChangedEvent;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<GroupChangedEvent|Event> */
class GroupChanged implements IEventListener {
public function __construct(
private readonly IUserSession $userSession,
private readonly FederatedUserService $federatedUserService,
private readonly CircleService $circleService,
private readonly LoggerInterface $logger,
) {
}

public function handle(Event $event): void {
if (!($event instanceof GroupChangedEvent)) {
return;
}

if ($event->getFeature() !== 'displayName') {
return;
}

$user = $this->userSession->getUser();
$this->federatedUserService->setLocalCurrentUser($user);

$groupId = $event->getGroup()->getGID();
try {
$this->circleService->updateName("group:$groupId", $event->getValue());
} catch (CircleNotFoundException $e) {
// Silently ignore (there is no circle for the group yet)
} catch (\Exception $e) {
$this->logger->warning("Failed to update display name of circle of group $groupId: " . $e->getMessage(), [
'exception' => $e,
'groupId' => $groupId,
]);
}
}
}
Loading