diff --git a/lib/Db/RowCellUsergroupMapper.php b/lib/Db/RowCellUsergroupMapper.php index af975a8c37..f4ac9c65ec 100644 --- a/lib/Db/RowCellUsergroupMapper.php +++ b/lib/Db/RowCellUsergroupMapper.php @@ -19,6 +19,7 @@ class RowCellUsergroupMapper extends RowCellMapperSuper { use RowCellBulkFetchTrait; protected string $table = 'tables_row_cells_usergroup'; + private ?string $userId = null; public function __construct( IDBConnection $db, @@ -30,6 +31,10 @@ public function __construct( parent::__construct($db, $this->table, RowCellUsergroup::class); } + public function setUserId(string $userId): void { + $this->userId = $userId; + } + public function filterValueToQueryParam(Column $column, mixed $value): mixed { return $value; } @@ -49,7 +54,7 @@ public function formatRowData(Column $column, array $row) { if ($valueType === UsergroupType::USER) { $displayName = $this->userManager->getDisplayName($value) ?? $value; } elseif ($valueType === UsergroupType::CIRCLE) { - $displayName = $this->circleHelper->getCircleDisplayName($value, ($this->userSession->getUser()?->getUID() ?: '')) ?: $value; + $displayName = $this->circleHelper->getCircleDisplayName($value, $this->userId ?? ($this->userSession->getUser()?->getUID() ?: '')) ?: $value; } elseif ($valueType === UsergroupType::GROUP) { $displayName = $this->groupHelper->getGroupDisplayName($value) ?: $value; } diff --git a/lib/Helper/CircleHelper.php b/lib/Helper/CircleHelper.php index 34b2477e95..831c851c10 100644 --- a/lib/Helper/CircleHelper.php +++ b/lib/Helper/CircleHelper.php @@ -23,6 +23,7 @@ class CircleHelper { private bool $circlesEnabled; private ?CirclesManager $circlesManager; + private array $federatedUsers = []; /** * @psalm-suppress UndefinedClass @@ -55,14 +56,14 @@ public function getCircleDisplayName(string $circleId, string $userId): string { } try { - $federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); - $this->circlesManager->startSession($federatedUser); + $this->federatedUsers[$userId] ??= $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER); + $this->circlesManager->startSession($this->federatedUsers[$userId]); $circle = $this->circlesManager->getCircle($circleId); return $circle ? ($circle->getDisplayName() ?: $circleId) : $circleId; } catch (Throwable $e) { if ($e->getCode() === 404) { - return $this->l10n->t('Deleted team %s.', [$circleId]); + return $this->l10n->t('Team not found'); } $this->logger->warning('Failed to get circle display name: ' . $e->getMessage(), [ diff --git a/lib/Middleware/ShareControlMiddleware.php b/lib/Middleware/ShareControlMiddleware.php index 76bfa0bcac..f584700b66 100644 --- a/lib/Middleware/ShareControlMiddleware.php +++ b/lib/Middleware/ShareControlMiddleware.php @@ -10,6 +10,7 @@ use InvalidArgumentException; use OCA\Tables\Constants\ShareReceiverType; +use OCA\Tables\Db\RowCellUsergroupMapper; use OCA\Tables\Db\Share; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -41,6 +42,7 @@ public function __construct( private readonly IOCMDiscoveryService $ocmDiscoveryService, private readonly ICloudIdManager $cloudIdManager, private readonly ConfigService $configService, + private readonly RowCellUsergroupMapper $usergroupMapper, ) { } @@ -56,6 +58,10 @@ public function beforeController(Controller $controller, string $methodName): vo $tokenInput = $this->request->getParam('token', ''); $this->assertShareTokenIsValidAndExisting($tokenInput); $this->assertIsAccessible($tokenInput); + + if ($this->share->getReceiverType() === ShareReceiverType::REMOTE) { + $this->usergroupMapper->setUserId($this->share->getReceiver()); + } } }