From 93122b7509e7de73db396b874a35c4103d525ac9 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Fri, 5 May 2023 17:24:45 +0200 Subject: [PATCH] Use $group->getDisplayName() instead of just the GID for the display name of "group circles". Fixes nextcloud/circles#1296. Signed-off-by: Claus-Justus Heine --- lib/Service/FederatedUserService.php | 7 ++++--- lib/Service/MembersService.php | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/Service/FederatedUserService.php b/lib/Service/FederatedUserService.php index e3fd406bd..d15396982 100644 --- a/lib/Service/FederatedUserService.php +++ b/lib/Service/FederatedUserService.php @@ -646,7 +646,7 @@ public function setOwnerAsCurrentUser(string $circleId): void { $probe = new CircleProbe(); $probe->includeSystemCircles() ->includePersonalCircles(); - + $localCircle = $this->circleRequest->getCircle($circleId, null, $probe); if ($this->configService->isLocalInstance($localCircle->getInstance())) { $this->setCurrentUser($localCircle->getOwner()); @@ -1241,7 +1241,8 @@ public function getGroupCircle(string $groupId): Circle { $member->setId($this->token(ManagedModel::ID_LENGTH)) ->setCircleId($circle->getSingleId()) ->setLevel(Member::LEVEL_OWNER) - ->setStatus(Member::STATUS_MEMBER); + ->setStatus(Member::STATUS_MEMBER) + ->setDisplayName($group->getDisplayName()); $circle->setOwner($member) ->setInitiator($member); @@ -1250,7 +1251,7 @@ public function getGroupCircle(string $groupId): Circle { } catch (CircleNotFoundException $e) { } - $circle->setDisplayName($groupId); + $circle->setDisplayName($group->getDisplayName()); $event = new FederatedEvent(CircleCreate::class); $event->setCircle($circle); diff --git a/lib/Service/MembersService.php b/lib/Service/MembersService.php index 68c661cd6..06bacac24 100644 --- a/lib/Service/MembersService.php +++ b/lib/Service/MembersService.php @@ -33,7 +33,6 @@ use OCA\Circles\Tools\Traits\TNCRequest; use OCA\Circles\Tools\Traits\TArrayTools; use Exception; -use OC; use OC\User\NoUserException; use OCA\Circles\Circles\FileSharingBroadcaster; use OCA\Circles\Db\AccountsRequest; @@ -56,6 +55,8 @@ use OCA\Circles\Model\GlobalScale\GSEvent; use OCP\IL10N; use OCP\IUserManager; +use OCP\IGroupManager; +use OCP\IGroup; /** * Class MembersService @@ -77,6 +78,9 @@ class MembersService { /** @var IUserManager */ private $userManager; + /** @var IGroupManager */ + private $groupManager; + /** @var ConfigService */ private $configService; @@ -113,6 +117,7 @@ class MembersService { * @param string $userId * @param IL10N $l10n * @param IUserManager $userManager + * @param IGroupManager $groupManager * @param ConfigService $configService * @param DeprecatedCirclesRequest $circlesRequest * @param DeprecatedMembersRequest $membersRequest @@ -125,7 +130,7 @@ class MembersService { * @param MiscService $miscService */ public function __construct( - $userId, IL10N $l10n, IUserManager $userManager, ConfigService $configService, + $userId, IL10N $l10n, IUserManager $userManager, IGroupManager $groupManager, ConfigService $configService, DeprecatedCirclesRequest $circlesRequest, DeprecatedMembersRequest $membersRequest, AccountsRequest $accountsRequest, FileSharesRequest $fileSharesRequest, TokensRequest $tokensRequest, EventsService $eventsService, @@ -135,6 +140,7 @@ public function __construct( $this->userId = $userId; $this->l10n = $l10n; $this->userManager = $userManager; + $this->groupManager = $groupManager; $this->configService = $configService; $this->circlesRequest = $circlesRequest; $this->membersRequest = $membersRequest; @@ -421,8 +427,7 @@ private function verifyIdentContact(&$ident, $type) { * @throws Exception */ private function addGroupMembers(DeprecatedCircle $circle, $groupId): array { - $group = OC::$server->getGroupManager() - ->get($groupId); + $group = $this->groupManager->get($groupId); if ($group === null) { throw new GroupDoesNotExistException($this->l10n->t('This group does not exist')); } @@ -651,6 +656,15 @@ public function updateCachedName(DeprecatedMember $member, bool $fresh = true) { $cachedName = $this->getUserDisplayName($member->getUserId(), $fresh); } + if ($member->getType() === DeprecatedMember::TYPE_GROUP) { + $gid = $member->getUserId(); + /** @var IGroup $group */ + $group = $this->groupManager->get($gid); + if ($group !== null) { + $cachedName = $group->getDisplayName(); + } + } + if ($member->getType() === DeprecatedMember::TYPE_CONTACT) { $cachedName = $this->miscService->getContactDisplayName($member->getUserId()); }