fix: Make TrustedServers optional in RemotePlugin

The federation app is not always installed, causing errors when
TrustedServers is injected as a hard dependency. This change makes
the dependency optional by using nullable types and null-safe
operators, defaulting to false when unavailable.

Modified backport of #55893 which are required for
the stable31 backport to function correctly.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
pull/55643/head
nfebe 2025-11-11 09:24:02 +07:00 committed by F. E Noel Nfebe
parent 26c452c6ee
commit 6a1fdf5498
3 changed files with 8 additions and 5 deletions

@ -254,10 +254,12 @@ export default {
// remove invalid data and format to user-select layout
const exactSuggestions = this.filterOutExistingShares(rawExactSuggestions)
.filter(result => this.filterByTrustedServer(result))
.map(share => this.formatForMultiselect(share))
// sort by type so we can get user&groups first...
.sort((a, b) => a.shareType - b.shareType)
const suggestions = this.filterOutExistingShares(rawSuggestions)
.filter(result => this.filterByTrustedServer(result))
.map(share => this.formatForMultiselect(share))
// sort by type so we can get user&groups first...
.sort((a, b) => a.shareType - b.shareType)
@ -340,6 +342,7 @@ export default {
// remove invalid data and format to user-select layout
this.recommendations = this.filterOutExistingShares(rawRecommendations)
.filter(result => this.filterByTrustedServer(result))
.map(share => this.formatForMultiselect(share))
.concat(externalResults)

@ -29,7 +29,7 @@ class RemotePlugin implements ISearchPlugin {
private IUserManager $userManager,
IUserSession $userSession,
private IAppConfig $appConfig,
private TrustedServers $trustedServers,
private ?TrustedServers $trustedServers,
) {
$this->userId = $userSession->getUser()?->getUID() ?? '';
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
@ -106,7 +106,7 @@ class RemotePlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_REMOTE,
'shareWith' => $cloudId,
'server' => $serverUrl,
'isTrustedServer' => $this->trustedServers->isTrustedServer($serverUrl),
'isTrustedServer' => $this->trustedServers?->isTrustedServer($serverUrl) ?? false,
],
];
} else {
@ -119,7 +119,7 @@ class RemotePlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_REMOTE,
'shareWith' => $cloudId,
'server' => $serverUrl,
'isTrustedServer' => $this->trustedServers->isTrustedServer($serverUrl),
'isTrustedServer' => $this->trustedServers?->isTrustedServer($serverUrl) ?? false,
],
];
}
@ -146,7 +146,7 @@ class RemotePlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_REMOTE,
'shareWith' => $search,
'server' => $serverUrl,
'isTrustedServer' => $this->trustedServers->isTrustedServer($serverUrl),
'isTrustedServer' => $this->trustedServers?->isTrustedServer($serverUrl) ?? false,
],
];
}

@ -39,7 +39,7 @@ class RemotePluginTest extends TestCase {
protected $cloudIdManager;
protected IAppConfig|MockObject $appConfig;
protected ICloudIdManager|MockObject $trustedServers;
protected TrustedServers|MockObject $trustedServers;
/** @var RemotePlugin */
protected $plugin;