Skip to content
Open
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
13 changes: 12 additions & 1 deletion lib/Db/RowCellUsergroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCA\Tables\Constants\UsergroupType;
use OCA\Tables\Helper\CircleHelper;
use OCA\Tables\Helper\GroupHelper;
use OCA\Tables\Share\ShareContext;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\IUserSession;
Expand All @@ -26,6 +27,7 @@ public function __construct(
private CircleHelper $circleHelper,
private GroupHelper $groupHelper,
protected IUserSession $userSession,
private ShareContext $shareContext,
) {
parent::__construct($db, $this->table, RowCellUsergroup::class);
}
Expand All @@ -49,7 +51,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->getCurrentUserId()) ?: $value;
} elseif ($valueType === UsergroupType::GROUP) {
$displayName = $this->groupHelper->getGroupDisplayName($value) ?: $value;
}
Expand All @@ -63,4 +65,13 @@ public function formatRowData(Column $column, array $row) {
public function hasMultipleValues(): bool {
return true;
}

private function getCurrentUserId(): string {
$remoteUserId = $this->shareContext->getRemoteUserId();
if ($remoteUserId !== null) {
return $remoteUserId;
}

return $this->userSession->getUser()?->getUID() ?: '';
}
}
14 changes: 11 additions & 3 deletions lib/Helper/CircleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
class CircleHelper {
private bool $circlesEnabled;
private ?CirclesManager $circlesManager;
private array $circleDisplayNames = [];
private array $federatedUsers = [];
private array $unreachableUserIds = [];

/**
* @psalm-suppress UndefinedClass
Expand Down Expand Up @@ -50,21 +53,26 @@ public function isCirclesEnabled(): bool {
}

public function getCircleDisplayName(string $circleId, string $userId): string {
if (!$this->circlesEnabled) {
return $this->circleDisplayNames[$userId][$circleId] ??= $this->resolveCircleDisplayName($circleId, $userId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might sense to ALSO cache it with $userId only, to avoid multiple requests against the userId in more circles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also addressed this in 58c7895 - the resolved user is now also cached per userId, so additional teams don't trigger another request.

}

private function resolveCircleDisplayName(string $circleId, string $userId): string {
if (!$this->circlesEnabled || isset($this->unreachableUserIds[$userId])) {
return $circleId;
}

try {
$federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER);
$federatedUser = $this->federatedUsers[$userId] ??= $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER);
$this->circlesManager->startSession($federatedUser);

$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->unreachableUserIds[$userId] = true;
$this->logger->warning('Failed to get circle display name: ' . $e->getMessage(), [
'circleId' => $circleId,
'userId' => $userId
Expand Down
3 changes: 3 additions & 0 deletions lib/Middleware/ShareControlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCA\Tables\Service\ConfigService;
use OCA\Tables\Service\ShareService;
use OCA\Tables\Service\ValueObject\ShareToken;
use OCA\Tables\Share\ShareContext;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -41,6 +42,7 @@ public function __construct(
private readonly IOCMDiscoveryService $ocmDiscoveryService,
private readonly ICloudIdManager $cloudIdManager,
private readonly ConfigService $configService,
private readonly ShareContext $shareContext,
) {
}

Expand All @@ -56,6 +58,7 @@ public function beforeController(Controller $controller, string $methodName): vo
$tokenInput = $this->request->getParam('token', '');
$this->assertShareTokenIsValidAndExisting($tokenInput);
$this->assertIsAccessible($tokenInput);
$this->shareContext->setShare($this->share);
}
}

Expand Down
28 changes: 28 additions & 0 deletions lib/Share/ShareContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Tables\Share;

use OCA\Tables\Constants\ShareReceiverType;
use OCA\Tables\Db\Share;

class ShareContext {
private ?Share $share = null;

public function setShare(Share $share): void {
$this->share = $share;
}

public function getRemoteUserId(): ?string {
if ($this->share?->getReceiverType() !== ShareReceiverType::REMOTE) {
return null;
}

return $this->share->getReceiver();
}
}
Loading