Skip to content

Commit 1c29e9c

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

File tree

9 files changed

+208
-9
lines changed

9 files changed

+208
-9
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Exception;
1313
use OC\Files\Storage\Wrapper\Wrapper;
1414
use OCA\Circles\Api\v1\Circles;
15+
use OCA\Federation\TrustedServers;
1516
use OCA\Files\Helper;
1617
use OCA\Files_Sharing\Exceptions\SharingRightsException;
1718
use OCA\Files_Sharing\External\Storage;
@@ -95,6 +96,7 @@ public function __construct(
9596
private IProviderFactory $factory,
9697
private IMailer $mailer,
9798
private ITagManager $tagManager,
99+
private ?TrustedServers $trustedServers,
98100
private ?string $userId = null,
99101
) {
100102
parent::__construct($appName, $request);
@@ -197,6 +199,22 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
197199
$result['item_size'] = $node->getSize();
198200
$result['item_mtime'] = $node->getMTime();
199201

202+
if ($this->trustedServers !== null && in_array($share->getShareType(), [IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP])) {
203+
$result['is_trusted_server'] = false;
204+
$sharedWith = $share->getSharedWith();
205+
$remoteIdentifier = is_string($sharedWith) ? strrchr($sharedWith, '@') : false;
206+
if ($remoteIdentifier !== false) {
207+
$remote = substr($remoteIdentifier, 1);
208+
try {
209+
if ($this->trustedServers->isTrustedServer($remote)) {
210+
$result['is_trusted_server'] = true;
211+
}
212+
} catch (\Exception $e) {
213+
// Server not found or other issue, we consider it not trusted
214+
}
215+
}
216+
}
217+
200218
$expiration = $share->getExpirationDate();
201219
if ($expiration !== null) {
202220
$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/src/components/SharingInput.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,34 @@ export default {
193193
}
194194
195195
let shareType = []
196-
197196
const remoteTypes = [ShareType.Remote, ShareType.RemoteGroup]
197+
const showFederatedAsInternal = this.config.showFederatedSharesAsInternal
198+
|| this.config.showFederatedSharesToTrustedServersAsInternal
198199
199-
if (this.isExternal && !this.config.showFederatedSharesAsInternal) {
200-
shareType.push(...remoteTypes)
200+
if (this.isExternal) {
201+
if (!showFederatedAsInternal) {
202+
shareType.push(...remoteTypes)
203+
}
201204
} else {
202-
shareType = shareType.concat([
205+
shareType = [
203206
ShareType.User,
204207
ShareType.Group,
205208
ShareType.Team,
206209
ShareType.Room,
207210
ShareType.Guest,
208211
ShareType.Deck,
209212
ShareType.ScienceMesh,
210-
])
211-
212-
if (this.config.showFederatedSharesAsInternal) {
213+
]
214+
if (showFederatedAsInternal) {
213215
shareType.push(...remoteTypes)
214216
}
215217
}
216218
217219
if (getCapabilities().files_sharing.public.enabled === true && this.isExternal) {
218220
shareType.push(ShareType.Email)
221+
if (this.config.showFederatedSharesToTrustedServersAsInternal) {
222+
shareType.push(...remoteTypes)
223+
}
219224
}
220225
221226
let request = null

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/SharingTab.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,13 @@ export default {
402402
if ([ShareType.Link, ShareType.Email].includes(share.type)) {
403403
this.linkShares.push(share)
404404
} else if ([ShareType.Remote, ShareType.RemoteGroup].includes(share.type)) {
405-
if (this.config.showFederatedSharesAsInternal) {
405+
if (this.config.showFederatedSharesToTrustedServersAsInternal) {
406+
if (share.isTrustedServer) {
407+
this.shares.push(share)
408+
} else {
409+
this.externalShares.push(share)
410+
}
411+
} else if (this.config.showFederatedSharesAsInternal) {
406412
this.shares.push(share)
407413
} else {
408414
this.externalShares.push(share)

apps/files_sharing/tests/ApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\Share\IProviderFactory;
3535
use OCP\Share\IShare;
3636
use OCP\UserStatus\IManager as IUserStatusManager;
37+
use OCA\Federation\TrustedServers;
3738
use Psr\Container\ContainerInterface;
3839
use Psr\Log\LoggerInterface;
3940

@@ -113,6 +114,7 @@ private function createOCS($userId) {
113114
$providerFactory = $this->createMock(IProviderFactory::class);
114115
$mailer = $this->createMock(IMailer::class);
115116
$tagManager = $this->createMock(ITagManager::class);
117+
$trustedServers = $this->createMock(TrustedServers::class);
116118
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));
117119

118120
return new ShareAPIController(
@@ -134,6 +136,7 @@ private function createOCS($userId) {
134136
$providerFactory,
135137
$mailer,
136138
$tagManager,
139+
$trustedServers,
137140
$userId,
138141
);
139142
}

0 commit comments

Comments
 (0)