diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-06-22 13:43:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 13:43:54 +0200 |
commit | d9a4dae5abca96143a9ade6ecbeb7b4ea0fa8c42 (patch) | |
tree | 2052aa1eaa98fa967441ab8cc1210d3f090febc5 | |
parent | bbef4854b035354081cf1726986f2f2f35f4a943 (diff) | |
parent | 4190020a00047803d87ea2d83c2a686f9209f6c9 (diff) |
Merge pull request #9839 from nextcloud/backport/9837/stable27
[stable27] fix(participants): Update cached displayname when a group is renamed
-rw-r--r-- | lib/AppInfo/Application.php | 6 | ||||
-rw-r--r-- | lib/Listener/DisplayNameListener.php (renamed from lib/Listener/UserDisplayNameListener.php) | 28 | ||||
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 19 | ||||
-rw-r--r-- | tests/integration/features/conversation/group-participants.feature | 16 |
4 files changed, 53 insertions, 16 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e15e8acdc..66ef2929c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -55,12 +55,12 @@ use OCA\Talk\Listener\BeforeUserLoggedOutListener; use OCA\Talk\Listener\CircleDeletedListener; use OCA\Talk\Listener\CircleMembershipListener; use OCA\Talk\Listener\CSPListener; +use OCA\Talk\Listener\DisplayNameListener; use OCA\Talk\Listener\FeaturePolicyListener; use OCA\Talk\Listener\GroupDeletedListener; use OCA\Talk\Listener\GroupMembershipListener; use OCA\Talk\Listener\RestrictStartingCalls as RestrictStartingCallsListener; use OCA\Talk\Listener\UserDeletedListener; -use OCA\Talk\Listener\UserDisplayNameListener; use OCA\Talk\Maps\MapsPluginLoader; use OCA\Talk\Middleware\CanUseTalkMiddleware; use OCA\Talk\Middleware\InjectionMiddleware; @@ -92,6 +92,7 @@ use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationProvider; use OCP\Federation\ICloudFederationProviderManager; +use OCP\Group\Events\GroupChangedEvent; use OCP\Group\Events\GroupDeletedEvent; use OCP\Group\Events\UserAddedEvent; use OCP\Group\Events\UserRemovedEvent; @@ -124,14 +125,15 @@ class Application extends App implements IBootstrap { $context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class); $context->registerEventListener(AddFeaturePolicyEvent::class, FeaturePolicyListener::class); $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); + $context->registerEventListener(GroupChangedEvent::class, DisplayNameListener::class); $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); + $context->registerEventListener(UserChangedEvent::class, DisplayNameListener::class); $context->registerEventListener(UserAddedEvent::class, GroupMembershipListener::class); $context->registerEventListener(UserRemovedEvent::class, GroupMembershipListener::class); $context->registerEventListener(BeforeUserLoggedOutEvent::class, BeforeUserLoggedOutListener::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareTemplateLoader::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareAuthTemplateLoader::class); $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, UnifiedSearchCSSLoader::class); - $context->registerEventListener(UserChangedEvent::class, UserDisplayNameListener::class); $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, DeckPluginLoader::class); $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, MapsPluginLoader::class); $context->registerEventListener(RegisterOperationsEvent::class, RegisterOperationsListener::class); diff --git a/lib/Listener/UserDisplayNameListener.php b/lib/Listener/DisplayNameListener.php index e63981e8f..40472649a 100644 --- a/lib/Listener/UserDisplayNameListener.php +++ b/lib/Listener/DisplayNameListener.php @@ -28,12 +28,13 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\PollService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Group\Events\GroupChangedEvent; use OCP\User\Events\UserChangedEvent; /** * @template-implements IEventListener<Event> */ -class UserDisplayNameListener implements IEventListener { +class DisplayNameListener implements IEventListener { private ParticipantService $participantService; private PollService $pollService; @@ -46,26 +47,25 @@ class UserDisplayNameListener implements IEventListener { } public function handle(Event $event): void { - if (!($event instanceof UserChangedEvent)) { - // Unrelated - return; + if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') { + $this->updateCachedName(Attendee::ACTOR_USERS, $event->getUser()->getUID(), (string) $event->getValue()); } - - if ($event->getFeature() !== 'displayName') { - // Unrelated - return; + if ($event instanceof GroupChangedEvent && $event->getFeature() === 'displayName') { + $this->updateCachedName(Attendee::ACTOR_GROUPS, $event->getGroup()->getGID(), (string) $event->getValue()); } + } + protected function updateCachedName(string $actorType, string $actorId, string $newName): void { $this->participantService->updateDisplayNameForActor( - Attendee::ACTOR_USERS, - $event->getUser()->getUID(), - (string) $event->getValue() + $actorType, + $actorId, + $newName ); $this->pollService->updateDisplayNameForActor( - Attendee::ACTOR_USERS, - $event->getUser()->getUID(), - (string) $event->getValue() + $actorType, + $actorId, + $newName ); } } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 97c842e9f..2b3b7b1b6 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -652,6 +652,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { if (isset($expectedKeys['attendeePermissions'])) { $data['attendeePermissions'] = (string) $attendee['attendeePermissions']; } + if (isset($expectedKeys['displayName'])) { + $data['displayName'] = (string) $attendee['displayName']; + } if (!isset(self::$userToAttendeeId[$identifier][$attendee['actorType']])) { self::$userToAttendeeId[$identifier][$attendee['actorType']] = []; @@ -3047,6 +3050,22 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->createdGroups[] = $group; } + /** + * @Given /^set display name of group "([^"]*)" to "([^"]*)"$/ + * @param string $groupId + * @param string $displayName + */ + public function renameGroup(string $groupId, string $displayName): void { + $currentUser = $this->currentUser; + $this->setCurrentUser('admin'); + $this->sendRequest('PUT', '/cloud/groups/' . urlencode($groupId), [ + 'key' => 'displayname', + 'value' => $displayName, + ]); + + $this->assertStatusCode($this->response, 200); + } + private function deleteGroup($group) { $currentUser = $this->currentUser; $this->setCurrentUser('admin'); diff --git a/tests/integration/features/conversation/group-participants.feature b/tests/integration/features/conversation/group-participants.feature index e21774fc4..cb62e6bc1 100644 --- a/tests/integration/features/conversation/group-participants.feature +++ b/tests/integration/features/conversation/group-participants.feature @@ -5,6 +5,7 @@ Feature: conversation/group-participants Given user "participant3" exists And group "group1" exists And group "group2" exists + And group "rename-group" exists And user "participant2" is member of group "group1" Scenario: Owner invites a group @@ -262,3 +263,18 @@ Feature: conversation/group-participants | actorType | actorId | participantType | | users | participant1 | 1 | | groups | group1 | 3 | + + Scenario: Renaming a group reflects in the participant list + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" adds group "rename-group" to room "room" with 200 (v4) + And user "participant1" sees the following attendees in room "room" with 200 (v4) + | actorType | actorId | participantType | displayName | + | users | participant1 | 1 | participant1-displayname | + | groups | rename-group | 3 | rename-group | + When set display name of group "rename-group" to "rename-group-displayname" + Then user "participant1" sees the following attendees in room "room" with 200 (v4) + | actorType | actorId | participantType | displayName | + | users | participant1 | 1 | participant1-displayname | + | groups | rename-group | 3 | rename-group-displayname | |