Skip to content

Commit e0e5f66

Browse files
committed
feat(files_sharing): Toggle display for trusted server shares
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 384ad00 commit e0e5f66

File tree

14 files changed

+269
-26
lines changed

14 files changed

+269
-26
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 IConfigLexicon {
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(): ConfigLexiconStrictness {
2728
return ConfigLexiconStrictness::IGNORE;
@@ -30,6 +31,7 @@ public function getStrictness(): ConfigLexiconStrictness {
3031
public function getAppConfigs(): array {
3132
return [
3233
new ConfigLexiconEntry(self::SHOW_FEDERATED_AS_INTERNAL, ValueType::BOOL, false, 'shows federated shares as internal shares', true),
34+
new ConfigLexiconEntry(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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Exception;
1313
use OC\Files\Storage\Wrapper\Wrapper;
1414
use OCA\Circles\Api\v1\Circles;
15+
use OCA\Deck\Sharing\ShareAPIHelper;
16+
use OCA\Federation\TrustedServers;
1517
use OCA\Files\Helper;
1618
use OCA\Files_Sharing\Exceptions\SharingRightsException;
1719
use OCA\Files_Sharing\External\Storage;
@@ -72,6 +74,7 @@
7274
class ShareAPIController extends OCSController {
7375

7476
private ?Node $lockedNode = null;
77+
private array $trustedServerCache = [];
7578

7679
/**
7780
* Share20OCS constructor.
@@ -94,6 +97,8 @@ public function __construct(
9497
private LoggerInterface $logger,
9598
private IProviderFactory $factory,
9699
private IMailer $mailer,
100+
private ITagManager $tagManager,
101+
private ?TrustedServers $trustedServers,
97102
private ?string $userId = null,
98103
) {
99104
parent::__construct($appName, $request);
@@ -196,6 +201,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
196201
$result['item_size'] = $node->getSize();
197202
$result['item_mtime'] = $node->getMTime();
198203

204+
if ($this->trustedServers !== null && in_array($share->getShareType(), [IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP], true)) {
205+
$result['is_trusted_server'] = false;
206+
$sharedWith = $share->getSharedWith();
207+
$remoteIdentifier = is_string($sharedWith) ? strrchr($sharedWith, '@') : false;
208+
if ($remoteIdentifier !== false) {
209+
$remote = substr($remoteIdentifier, 1);
210+
211+
if (isset($this->trustedServerCache[$remote])) {
212+
$result['is_trusted_server'] = $this->trustedServerCache[$remote];
213+
} else {
214+
try {
215+
$isTrusted = $this->trustedServers->isTrustedServer($remote);
216+
$this->trustedServerCache[$remote] = $isTrusted;
217+
$result['is_trusted_server'] = $isTrusted;
218+
} catch (\Exception $e) {
219+
// Server not found or other issue, we consider it not trusted
220+
$this->trustedServerCache[$remote] = false;
221+
$this->logger->error(
222+
'Error checking if remote server is trusted (treating as untrusted): ' . $e->getMessage(),
223+
['exception' => $e]
224+
);
225+
}
226+
}
227+
}
228+
}
229+
199230
$expiration = $share->getExpirationDate();
200231
if ($expiration !== null) {
201232
$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
@@ -74,9 +74,9 @@ export default {
7474
title += ` (${t('files_sharing', 'group')})`
7575
} else if (this.share.type === ShareType.Room) {
7676
title += ` (${t('files_sharing', 'conversation')})`
77-
} else if (this.share.type === ShareType.Remote) {
77+
} else if (this.share.type === ShareType.Remote && !this.share.isTrustedServer) {
7878
title += ` (${t('files_sharing', 'remote')})`
79-
} else if (this.share.type === ShareType.RemoteGroup) {
79+
} else if (this.share.type === ShareType.RemoteGroup && !this.share.isTrustedServer) {
8080
title += ` (${t('files_sharing', 'remote group')})`
8181
} else if (this.share.type === ShareType.Guest) {
8282
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)