Skip to content
Merged
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 @@ -12,6 +12,7 @@
namespace OCA\Circles\AppInfo;

use Closure;
use OCA\Circles\ConfigLexicon;
use OCA\Circles\Dashboard\TeamDashboardWidget;
use OCA\Circles\Events\AddingCircleMemberEvent;
use OCA\Circles\Events\CircleMemberAddedEvent;
Expand Down Expand Up @@ -122,6 +123,8 @@ public function register(IRegistrationContext $context): void {

$context->registerDashboardWidget(TeamDashboardWidget::class);
$context->registerTeamResourceProvider(FileSharingTeamResourceProvider::class);

$context->registerConfigLexicon(ConfigLexicon::class);
}


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

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

namespace OCA\Circles;

use OCP\Config\IUserConfig;
use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for circles/teams.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*/
class ConfigLexicon implements ILexicon {
public const USER_SINGLE_ID = 'userSingleId';

public function getStrictness(): Strictness {
return Strictness::IGNORE;
}

public function getAppConfigs(): array {
return [
];
}

public function getUserConfigs(): array {
return [
new Entry(key: self::USER_SINGLE_ID, type: ValueType::STRING, defaultRaw: '', definition: 'caching singleId for each local account', lazy: false, flags: IUserConfig::FLAG_INDEXED),
];
}
}
38 changes: 37 additions & 1 deletion lib/Service/FederatedUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Exception;
use OC;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\ConfigLexicon;
use OCA\Circles\Db\AccountsRequest;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\MemberRequest;
Expand Down Expand Up @@ -54,6 +55,7 @@
use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use OCP\Config\IUserConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IGroupManager;
Expand Down Expand Up @@ -177,6 +179,7 @@ public function __construct(
ContactService $contactService,
InterfaceService $interfaceService,
ConfigService $configService,
private readonly IUserConfig $userConfig,
) {
$this->userSession = $userSession;
$this->userManager = $userManager;
Expand Down Expand Up @@ -520,11 +523,44 @@ public function getLocalFederatedUser(string $userId, bool $check = true, bool $

$federatedUser = new FederatedUser();
$federatedUser->set($userId, '', Member::TYPE_USER, $displayName);
$this->fillSingleCircleId($federatedUser, ($check || $generate));

$cached = $this->getCachedLocalFederatedUser($federatedUser);
if (!$cached) {
$this->fillSingleCircleId($federatedUser, ($check || $generate));
$this->userConfig->setValueString($userId, Application::APP_ID, ConfigLexicon::USER_SINGLE_ID, $federatedUser->getSingleId());
}

return $federatedUser;
}

/**
* get singleId from UserConfig (already loaded from database)
* and emulate FederatedUser for local accounts.
*/
private function getCachedLocalFederatedUser(IFederatedUser $federatedUser): bool {
if ($federatedUser->getUserType() !== Member::TYPE_USER || !$federatedUser->isLocal()) {
return false;
}

$userSingleId = $this->userConfig->getValueString($federatedUser->getUserId(), Application::APP_ID, ConfigLexicon::USER_SINGLE_ID);
if ($userSingleId === '') {
return false;
}

$federatedUser->setSingleId($userSingleId);
// setBasedOn() should be useless, but we want to keep backward compatibility
$federatedUser->setBasedOn(
(new Circle())->import([
'id' => $userSingleId,
'name' => 'user:' . $federatedUser->getUserId() . ':' . $userSingleId,
'displayName' => $federatedUser->getDisplayName(),
'source' => 1,
'config' => 1,
])
);

return true;
}

/**
* Get the full FederatedUser for a local user.
Expand Down
Loading