Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Config/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
class ConfigLexicon implements IConfigLexicon {
public const SHOW_FEDERATED_AS_INTERNAL = 'show_federated_shares_as_internal';
public const SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL = 'show_federated_shares_to_trusted_servers_as_internal';

public function getStrictness(): ConfigLexiconStrictness {
return ConfigLexiconStrictness::IGNORE;
Expand All @@ -30,6 +31,7 @@ public function getStrictness(): ConfigLexiconStrictness {
public function getAppConfigs(): array {
return [
new ConfigLexiconEntry(self::SHOW_FEDERATED_AS_INTERNAL, ValueType::BOOL, false, 'shows federated shares as internal shares', true),
new ConfigLexiconEntry(self::SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL, ValueType::BOOL, false, 'shows federated shares to trusted servers as internal shares', true),
];
}

Expand Down
31 changes: 31 additions & 0 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Exception;
use OC\Files\Storage\Wrapper\Wrapper;
use OCA\Circles\Api\v1\Circles;
use OCA\Deck\Sharing\ShareAPIHelper;
use OCA\Federation\TrustedServers;
use OCA\Files\Helper;
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
Expand Down Expand Up @@ -72,6 +74,7 @@
class ShareAPIController extends OCSController {

private ?Node $lockedNode = null;
private array $trustedServerCache = [];

/**
* Share20OCS constructor.
Expand All @@ -94,6 +97,8 @@ public function __construct(
private LoggerInterface $logger,
private IProviderFactory $factory,
private IMailer $mailer,
private ITagManager $tagManager,
private ?TrustedServers $trustedServers,
private ?string $userId = null,
) {
parent::__construct($appName, $request);
Expand Down Expand Up @@ -196,6 +201,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
$result['item_size'] = $node->getSize();
$result['item_mtime'] = $node->getMTime();

if ($this->trustedServers !== null && in_array($share->getShareType(), [IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP], true)) {
$result['is_trusted_server'] = false;
$sharedWith = $share->getSharedWith();
$remoteIdentifier = is_string($sharedWith) ? strrchr($sharedWith, '@') : false;
if ($remoteIdentifier !== false) {
$remote = substr($remoteIdentifier, 1);

if (isset($this->trustedServerCache[$remote])) {
$result['is_trusted_server'] = $this->trustedServerCache[$remote];
} else {
try {
$isTrusted = $this->trustedServers->isTrustedServer($remote);
$this->trustedServerCache[$remote] = $isTrusted;
$result['is_trusted_server'] = $isTrusted;
} catch (\Exception $e) {
// Server not found or other issue, we consider it not trusted
$this->trustedServerCache[$remote] = false;
$this->logger->error(
'Error checking if remote server is trusted (treating as untrusted): ' . $e->getMessage(),
['exception' => $e]
);
}
}
}
}

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$expiration->setTimezone($this->dateTimeZone->getTimeZone());
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/lib/Listener/LoadSidebarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function handle(Event $event): void {

$appConfig = Server::get(IAppConfig::class);
$this->initialState->provideInitialState('showFederatedSharesAsInternal', $appConfig->getValueBool('files_sharing', ConfigLexicon::SHOW_FEDERATED_AS_INTERNAL));
$this->initialState->provideInitialState('showFederatedSharesToTrustedServersAsInternal', $appConfig->getValueBool('files_sharing', ConfigLexicon::SHOW_FEDERATED_TO_TRUSTED_AS_INTERNAL));
Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');
}
}
1 change: 1 addition & 0 deletions apps/files_sharing/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* file_target: string,
* has_preview: bool,
* hide_download: 0|1,
* is_trusted_server?: bool,
* is-mount-root: bool,
* id: string,
* item_mtime: int,
Expand Down
3 changes: 3 additions & 0 deletions apps/files_sharing/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@
1
]
},
"is_trusted_server": {
"type": "boolean"
},
"is-mount-root": {
"type": "boolean"
},
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default {
title += ` (${t('files_sharing', 'group')})`
} else if (this.share.type === ShareType.Room) {
title += ` (${t('files_sharing', 'conversation')})`
} else if (this.share.type === ShareType.Remote) {
} else if (this.share.type === ShareType.Remote && !this.share.isTrustedServer) {
title += ` (${t('files_sharing', 'remote')})`
} else if (this.share.type === ShareType.RemoteGroup) {
} else if (this.share.type === ShareType.RemoteGroup && !this.share.isTrustedServer) {
title += ` (${t('files_sharing', 'remote group')})`
} else if (this.share.type === ShareType.Guest) {
title += ` (${t('files_sharing', 'guest')})`
Expand Down
40 changes: 27 additions & 13 deletions apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,39 @@ export default {
lookup = true
}

let shareType = []

const remoteTypes = [ShareType.Remote, ShareType.RemoteGroup]

if (this.isExternal && !this.config.showFederatedSharesAsInternal) {
shareType.push(...remoteTypes)
const shareType = []

const showFederatedAsInternal
= this.config.showFederatedSharesAsInternal
|| this.config.showFederatedSharesToTrustedServersAsInternal

const shouldAddRemoteTypes
// For internal users, add remote types if config says to show them as internal
= (!this.isExternal && showFederatedAsInternal)
// For external users, add them if config *doesn't* say to show them as internal
|| (this.isExternal && !showFederatedAsInternal)
// Edge case: federated-to-trusted is a separate "add" trigger for external users
|| (this.isExternal && this.config.showFederatedSharesToTrustedServersAsInternal)

if (this.isExternal) {
if (getCapabilities().files_sharing.public.enabled === true) {
shareType.push(ShareType.Email)
}
} else {
shareType = shareType.concat([
shareType.push(
ShareType.User,
ShareType.Group,
ShareType.Team,
ShareType.Room,
ShareType.Guest,
ShareType.Deck,
ShareType.ScienceMesh,
])

if (this.config.showFederatedSharesAsInternal) {
shareType.push(...remoteTypes)
}
)
}

if (getCapabilities().files_sharing.public.enabled === true && this.isExternal) {
shareType.push(ShareType.Email)
if (shouldAddRemoteTypes) {
shareType.push(...remoteTypes)
}

let request = null
Expand Down Expand Up @@ -366,6 +375,11 @@ export default {

// filter out existing mail shares
if (share.value.shareType === ShareType.Email) {
// When sharing internally, we don't want to suggest email addresses
// that the user previously created shares to
if (!this.isExternal) {
return arr
}
const emails = this.linkShares.map(elem => elem.shareWith)
if (emails.indexOf(share.value.shareWith.trim()) !== -1) {
return arr
Expand Down
7 changes: 7 additions & 0 deletions apps/files_sharing/src/models/Share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,11 @@ export default class Share {
return this._share.status
}

/**
* Is the share from a trusted server
*/
get isTrustedServer(): boolean {
return !!this._share.is_trusted_server
}

}
8 changes: 8 additions & 0 deletions apps/files_sharing/src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,12 @@ export default class Config {
return loadState('files_sharing', 'showFederatedSharesAsInternal', false)
}

/**
* Show federated shares to trusted servers as internal shares
* @return {boolean}
*/
get showFederatedSharesToTrustedServersAsInternal(): boolean {
return loadState('files_sharing', 'showFederatedSharesToTrustedServersAsInternal', false)
}

}
12 changes: 6 additions & 6 deletions apps/files_sharing/src/views/SharingLinkList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<ul v-if="canLinkShare"
:aria-label="t('files_sharing', 'Link shares')"
class="sharing-link-list">
<!-- If no link shares, show the add link default entry -->
<SharingEntryLink v-if="!hasLinkShares && canReshare"
:can-reshare="canReshare"
:file-info="fileInfo"
@add:share="addShare" />

<!-- Else we display the list -->
<template v-if="hasShares">
<!-- using shares[index] to work with .sync -->
Expand All @@ -27,6 +21,12 @@
@remove:share="removeShare"
@open-sharing-details="openSharingDetails(share)" />
</template>

<!-- If no link shares, show the add link default entry -->
<SharingEntryLink v-if="!hasLinkShares && canReshare"
:can-reshare="canReshare"
:file-info="fileInfo"
@add:share="addShare" />
</ul>
</template>

Expand Down
12 changes: 11 additions & 1 deletion apps/files_sharing/src/views/SharingTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,13 @@ export default {
if ([ShareType.Link, ShareType.Email].includes(share.type)) {
this.linkShares.push(share)
} else if ([ShareType.Remote, ShareType.RemoteGroup].includes(share.type)) {
if (this.config.showFederatedSharesAsInternal) {
if (this.config.showFederatedSharesToTrustedServersAsInternal) {
if (share.isTrustedServer) {
this.shares.push(share)
} else {
this.externalShares.push(share)
}
} else if (this.config.showFederatedSharesAsInternal) {
this.shares.push(share)
} else {
this.externalShares.push(share)
Expand Down Expand Up @@ -475,6 +481,10 @@ export default {
} else if ([ShareType.Remote, ShareType.RemoteGroup].includes(share.type)) {
if (this.config.showFederatedSharesAsInternal) {
this.shares.unshift(share)
} if (this.config.showFederatedSharesToTrustedServersAsInternal) {
if (share.isTrustedServer) {
this.shares.unshift(share)
}
} else {
this.externalShares.unshift(share)
}
Expand Down
6 changes: 6 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Files\Filesystem;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OCA\Federation\TrustedServers;
use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\App\IAppManager;
use OCP\AppFramework\OCS\OCSBadRequestException;
Expand All @@ -24,6 +25,7 @@
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\ITagManager;
use OCP\Mail\IMailer;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
Expand Down Expand Up @@ -106,6 +108,8 @@ private function createOCS($userId) {
$logger = $this->createMock(LoggerInterface::class);
$providerFactory = $this->createMock(IProviderFactory::class);
$mailer = $this->createMock(IMailer::class);
$tagManager = $this->createMock(ITagManager::class);
$trustedServers = $this->createMock(TrustedServers::class);
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));

return new ShareAPIController(
Expand All @@ -126,6 +130,8 @@ private function createOCS($userId) {
$logger,
$providerFactory,
$mailer,
$tagManager,
$trustedServers,
$userId,
);
}
Expand Down
Loading
Loading