Skip to content

Commit f0485e4

Browse files
authored
Merge pull request #53661 from nextcloud/feat/52635/toggle-for-trusted-server-sharing
feat(files_sharing): Toggle display for trusted server shares
2 parents 0c568ff + 21b273d commit f0485e4

28 files changed

+267
-39
lines changed

apps/files_sharing/lib/Config/ConfigLexicon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
class ConfigLexicon implements ILexicon {
2424
public const SHOW_FEDERATED_AS_INTERNAL = 'show_federated_shares_as_internal';
25+
public const SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL = 'show_federated_shares_to_trusted_servers_as_internal';
2526

2627
public function getStrictness(): Strictness {
2728
return Strictness::IGNORE;
@@ -30,6 +31,7 @@ public function getStrictness(): Strictness {
3031
public function getAppConfigs(): array {
3132
return [
3233
new Entry(self::SHOW_FEDERATED_AS_INTERNAL, ValueType::BOOL, false, 'shows federated shares as internal shares', true),
34+
new Entry(self::SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL, ValueType::BOOL, false, 'shows federated shares to trusted servers as internal shares', true),
3335
];
3436
}
3537

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OC\Files\Storage\Wrapper\Wrapper;
1616
use OCA\Circles\Api\v1\Circles;
1717
use OCA\Deck\Sharing\ShareAPIHelper;
18+
use OCA\Federation\TrustedServers;
1819
use OCA\Files\Helper;
1920
use OCA\Files_Sharing\Exceptions\SharingRightsException;
2021
use OCA\Files_Sharing\External\Storage;
@@ -76,6 +77,7 @@
7677
class ShareAPIController extends OCSController {
7778

7879
private ?Node $lockedNode = null;
80+
private array $trustedServerCache = [];
7981

8082
/**
8183
* Share20OCS constructor.
@@ -100,6 +102,7 @@ public function __construct(
100102
private IProviderFactory $factory,
101103
private IMailer $mailer,
102104
private ITagManager $tagManager,
105+
private ?TrustedServers $trustedServers,
103106
private ?string $userId = null,
104107
) {
105108
parent::__construct($appName, $request);
@@ -202,6 +205,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
202205
$result['item_size'] = $node->getSize();
203206
$result['item_mtime'] = $node->getMTime();
204207

208+
if ($this->trustedServers !== null && in_array($share->getShareType(), [IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP], true)) {
209+
$result['is_trusted_server'] = false;
210+
$sharedWith = $share->getSharedWith();
211+
$remoteIdentifier = is_string($sharedWith) ? strrchr($sharedWith, '@') : false;
212+
if ($remoteIdentifier !== false) {
213+
$remote = substr($remoteIdentifier, 1);
214+
215+
if (isset($this->trustedServerCache[$remote])) {
216+
$result['is_trusted_server'] = $this->trustedServerCache[$remote];
217+
} else {
218+
try {
219+
$isTrusted = $this->trustedServers->isTrustedServer($remote);
220+
$this->trustedServerCache[$remote] = $isTrusted;
221+
$result['is_trusted_server'] = $isTrusted;
222+
} catch (\Exception $e) {
223+
// Server not found or other issue, we consider it not trusted
224+
$this->trustedServerCache[$remote] = false;
225+
$this->logger->error(
226+
'Error checking if remote server is trusted (treating as untrusted): ' . $e->getMessage(),
227+
['exception' => $e]
228+
);
229+
}
230+
}
231+
}
232+
}
233+
205234
$expiration = $share->getExpirationDate();
206235
if ($expiration !== null) {
207236
$expiration->setTimezone($this->dateTimeZone->getTimeZone());

apps/files_sharing/lib/Listener/LoadSidebarListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function handle(Event $event): void {
3838

3939
$appConfig = Server::get(IAppConfig::class);
4040
$this->initialState->provideInitialState('showFederatedSharesAsInternal', $appConfig->getValueBool('files_sharing', ConfigLexicon::SHOW_FEDERATED_AS_INTERNAL));
41+
$this->initialState->provideInitialState('showFederatedSharesToTrustedServersAsInternal', $appConfig->getValueBool('files_sharing', ConfigLexicon::SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL));
4142
Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');
4243
}
4344
}

apps/files_sharing/lib/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* file_target: string,
2323
* has_preview: bool,
2424
* hide_download: 0|1,
25+
* is_trusted_server?: bool,
2526
* is-mount-root: bool,
2627
* id: string,
2728
* item_mtime: int,

apps/files_sharing/openapi.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@
548548
1
549549
]
550550
},
551+
"is_trusted_server": {
552+
"type": "boolean"
553+
},
551554
"is-mount-root": {
552555
"type": "boolean"
553556
},

apps/files_sharing/src/components/SharingEntry.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export default {
7777
title += ` (${t('files_sharing', 'group')})`
7878
} else if (this.share.type === ShareType.Room) {
7979
title += ` (${t('files_sharing', 'conversation')})`
80-
} else if (this.share.type === ShareType.Remote) {
80+
} else if (this.share.type === ShareType.Remote && !this.share.isTrustedServer) {
8181
title += ` (${t('files_sharing', 'remote')})`
82-
} else if (this.share.type === ShareType.RemoteGroup) {
82+
} else if (this.share.type === ShareType.RemoteGroup && !this.share.isTrustedServer) {
8383
title += ` (${t('files_sharing', 'remote group')})`
8484
} else if (this.share.type === ShareType.Guest) {
8585
title += ` (${t('files_sharing', 'guest')})`

apps/files_sharing/src/components/SharingInput.vue

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,39 @@ export default {
192192
lookup = true
193193
}
194194
195-
let shareType = []
196-
197195
const remoteTypes = [ShareType.Remote, ShareType.RemoteGroup]
198-
199-
if (this.isExternal && !this.config.showFederatedSharesAsInternal) {
200-
shareType.push(...remoteTypes)
196+
const shareType = []
197+
198+
const showFederatedAsInternal
199+
= this.config.showFederatedSharesAsInternal
200+
|| this.config.showFederatedSharesToTrustedServersAsInternal
201+
202+
const shouldAddRemoteTypes
203+
// For internal users, add remote types if config says to show them as internal
204+
= (!this.isExternal && showFederatedAsInternal)
205+
// For external users, add them if config *doesn't* say to show them as internal
206+
|| (this.isExternal && !showFederatedAsInternal)
207+
// Edge case: federated-to-trusted is a separate "add" trigger for external users
208+
|| (this.isExternal && this.config.showFederatedSharesToTrustedServersAsInternal)
209+
210+
if (this.isExternal) {
211+
if (getCapabilities().files_sharing.public.enabled === true) {
212+
shareType.push(ShareType.Email)
213+
}
201214
} else {
202-
shareType = shareType.concat([
215+
shareType.push(
203216
ShareType.User,
204217
ShareType.Group,
205218
ShareType.Team,
206219
ShareType.Room,
207220
ShareType.Guest,
208221
ShareType.Deck,
209222
ShareType.ScienceMesh,
210-
])
211-
212-
if (this.config.showFederatedSharesAsInternal) {
213-
shareType.push(...remoteTypes)
214-
}
223+
)
215224
}
216225
217-
if (getCapabilities().files_sharing.public.enabled === true && this.isExternal) {
218-
shareType.push(ShareType.Email)
226+
if (shouldAddRemoteTypes) {
227+
shareType.push(...remoteTypes)
219228
}
220229
221230
let request = null
@@ -366,6 +375,11 @@ export default {
366375
367376
// filter out existing mail shares
368377
if (share.value.shareType === ShareType.Email) {
378+
// When sharing internally, we don't want to suggest email addresses
379+
// that the user previously created shares to
380+
if (!this.isExternal) {
381+
return arr
382+
}
369383
const emails = this.linkShares.map(elem => elem.shareWith)
370384
if (emails.indexOf(share.value.shareWith.trim()) !== -1) {
371385
return arr

apps/files_sharing/src/models/Share.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,11 @@ export default class Share {
486486
return this._share.status
487487
}
488488

489+
/**
490+
* Is the share from a trusted server
491+
*/
492+
get isTrustedServer(): boolean {
493+
return !!this._share.is_trusted_server
494+
}
495+
489496
}

apps/files_sharing/src/services/ConfigService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,12 @@ export default class Config {
315315
return loadState('files_sharing', 'showFederatedSharesAsInternal', false)
316316
}
317317

318+
/**
319+
* Show federated shares to trusted servers as internal shares
320+
* @return {boolean}
321+
*/
322+
get showFederatedSharesToTrustedServersAsInternal(): boolean {
323+
return loadState('files_sharing', 'showFederatedSharesToTrustedServersAsInternal', false)
324+
}
325+
318326
}

apps/files_sharing/src/views/SharingLinkList.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
<ul v-if="canLinkShare"
88
:aria-label="t('files_sharing', 'Link shares')"
99
class="sharing-link-list">
10-
<!-- If no link shares, show the add link default entry -->
11-
<SharingEntryLink v-if="!hasLinkShares && canReshare"
12-
:can-reshare="canReshare"
13-
:file-info="fileInfo"
14-
@add:share="addShare" />
15-
1610
<!-- Else we display the list -->
1711
<template v-if="hasShares">
1812
<!-- using shares[index] to work with .sync -->
@@ -27,6 +21,12 @@
2721
@remove:share="removeShare"
2822
@open-sharing-details="openSharingDetails(share)" />
2923
</template>
24+
25+
<!-- If no link shares, show the add link default entry -->
26+
<SharingEntryLink v-if="!hasLinkShares && canReshare"
27+
:can-reshare="canReshare"
28+
:file-info="fileInfo"
29+
@add:share="addShare" />
3030
</ul>
3131
</template>
3232

0 commit comments

Comments
 (0)