fix(sharing): Add isTrustedServer flag to lookup results

When `show_federated_shares_to_trusted_servers_as_internal` is enabled,
lookup server results were being filtered out because they lacked the
`isTrustedServer` flag. This adds the flag to lookup results by:

- Injecting TrustedServers service into LookupPlugin
- Adding `server` and `isTrustedServer` fields to each lookup result
- Updating tests to reflect new structure

This ensures lookup results from trusted servers appear in internal
sharing while non-trusted servers are correctly filtered out.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
pull/56844/head
nfebe 2025-12-04 12:05:01 +07:00
parent 847ae2be3f
commit e7ce70744d
2 changed files with 37 additions and 10 deletions

@ -5,6 +5,7 @@
*/
namespace OC\Collaboration\Collaborators;
use OCA\Federation\TrustedServers;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
@ -25,6 +26,7 @@ class LookupPlugin implements ISearchPlugin {
IUserSession $userSession,
private ICloudIdManager $cloudIdManager,
private LoggerInterface $logger,
private ?TrustedServers $trustedServers,
) {
$currentUserCloudId = $userSession->getUser()->getCloudId();
$this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote();
@ -81,6 +83,8 @@ class LookupPlugin implements ISearchPlugin {
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => $isGlobalScaleEnabled,
'shareWith' => $lookup['federationId'],
'server' => $remote,
'isTrustedServer' => $this->trustedServers?->isTrustedServer($remote) ?? false,
],
'extra' => $lookup,
];

@ -56,6 +56,10 @@ class LookupPluginTest extends TestCase {
if ($cloudId === 'user@myNextcloud.net') {
return new CloudId('user@myNextcloud.net', 'user', 'myNextcloud.net');
}
if (str_contains($cloudId, '@enceladus.moon')) {
[$user, $remote] = explode('@', $cloudId, 2);
return new CloudId($cloudId, $user, $remote);
}
return new CloudId('user@someNextcloud.net', 'user', 'someNextcloud.net');
});
@ -65,7 +69,8 @@ class LookupPluginTest extends TestCase {
$this->clientService,
$this->userSession,
$this->cloudIdManager,
$this->logger
$this->logger,
null
);
}
@ -300,7 +305,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[0]
'shareWith' => $fedIDs[0],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[0]],
],
@ -309,7 +316,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[1]
'shareWith' => $fedIDs[1],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[1]],
],
@ -318,7 +327,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[2]
'shareWith' => $fedIDs[2],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[2]],
],
@ -342,7 +353,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[0]
'shareWith' => $fedIDs[0],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[0]],
],
@ -351,7 +364,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[1]
'shareWith' => $fedIDs[1],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[1]],
],
@ -360,7 +375,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[2]
'shareWith' => $fedIDs[2],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[2]],
],
@ -474,7 +491,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[0]
'shareWith' => $fedIDs[0],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[0]],
],
@ -483,7 +502,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[1]
'shareWith' => $fedIDs[1],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[1]],
],
@ -492,7 +513,9 @@ class LookupPluginTest extends TestCase {
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => true,
'shareWith' => $fedIDs[2]
'shareWith' => $fedIDs[2],
'server' => 'enceladus.moon',
'isTrustedServer' => false,
],
'extra' => ['federationId' => $fedIDs[2]],
],