diff options
Diffstat (limited to 'apps/files_sharing/src/services')
-rw-r--r-- | apps/files_sharing/src/services/ConfigService.ts | 24 | ||||
-rw-r--r-- | apps/files_sharing/src/services/GuestNameValidity.ts | 45 | ||||
-rw-r--r-- | apps/files_sharing/src/services/SharingService.spec.ts | 7 | ||||
-rw-r--r-- | apps/files_sharing/src/services/SharingService.ts | 15 | ||||
-rw-r--r-- | apps/files_sharing/src/services/TabSections.js | 8 | ||||
-rw-r--r-- | apps/files_sharing/src/services/WebdavClient.ts | 18 |
6 files changed, 98 insertions, 19 deletions
diff --git a/apps/files_sharing/src/services/ConfigService.ts b/apps/files_sharing/src/services/ConfigService.ts index 09fdca13598..547038f362d 100644 --- a/apps/files_sharing/src/services/ConfigService.ts +++ b/apps/files_sharing/src/services/ConfigService.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { getCapabilities } from '@nextcloud/capabilities' +import { loadState } from '@nextcloud/initial-state' type PasswordPolicyCapabilities = { enforceNonCommonPassword: boolean @@ -212,6 +213,13 @@ export default class Config { } /** + * Is federation enabled ? + */ + get isFederationEnabled(): boolean { + return this._capabilities?.files_sharing?.federation?.outgoing === true + } + + /** * Is public sharing enabled ? */ get isPublicShareAllowed(): boolean { @@ -306,4 +314,20 @@ export default class Config { return this._capabilities?.files_sharing?.public?.custom_tokens } + /** + * Show federated shares as internal shares + * @return {boolean} + */ + get showFederatedSharesAsInternal(): boolean { + 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) + } + } diff --git a/apps/files_sharing/src/services/GuestNameValidity.ts b/apps/files_sharing/src/services/GuestNameValidity.ts new file mode 100644 index 00000000000..0557c5253ca --- /dev/null +++ b/apps/files_sharing/src/services/GuestNameValidity.ts @@ -0,0 +1,45 @@ +/*! + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { InvalidFilenameError, InvalidFilenameErrorReason, validateFilename } from '@nextcloud/files' +import { t } from '@nextcloud/l10n' + +/** + * Get the validity of a filename (empty if valid). + * This can be used for `setCustomValidity` on input elements + * @param name The filename + * @param escape Escape the matched string in the error (only set when used in HTML) + */ +export function getGuestNameValidity(name: string, escape = false): string { + if (name.trim() === '') { + return t('files', 'Names must not be empty.') + } + + if (name.startsWith('.')) { + return t('files', 'Names must not start with a dot.') + } + + try { + validateFilename(name) + return '' + } catch (error) { + if (!(error instanceof InvalidFilenameError)) { + throw error + } + + switch (error.reason) { + case InvalidFilenameErrorReason.Character: + return t('files', '"{char}" is not allowed inside a name.', { char: error.segment }, undefined, { escape }) + case InvalidFilenameErrorReason.ReservedName: + return t('files', '"{segment}" is a reserved name and not allowed.', { segment: error.segment }, undefined, { escape: false }) + case InvalidFilenameErrorReason.Extension: + if (error.segment.match(/\.[a-z]/i)) { + return t('files', '"{extension}" is not an allowed name.', { extension: error.segment }, undefined, { escape: false }) + } + return t('files', 'Names must not end with "{extension}".', { extension: error.segment }, undefined, { escape: false }) + default: + return t('files', 'Invalid name.') + } + } +} diff --git a/apps/files_sharing/src/services/SharingService.spec.ts b/apps/files_sharing/src/services/SharingService.spec.ts index 2224a1d3967..936c1afafc4 100644 --- a/apps/files_sharing/src/services/SharingService.spec.ts +++ b/apps/files_sharing/src/services/SharingService.spec.ts @@ -355,6 +355,13 @@ describe('SharingService share to Node mapping', () => { expect(file.root).toBe('/files/test') expect(file.attributes).toBeInstanceOf(Object) expect(file.attributes['has-preview']).toBe(true) + expect(file.attributes.sharees).toEqual({ + sharee: { + id: 'user00', + 'display-name': 'User00', + type: 0, + }, + }) expect(file.attributes.favorite).toBe(0) }) diff --git a/apps/files_sharing/src/services/SharingService.ts b/apps/files_sharing/src/services/SharingService.ts index 01a92cfff87..41c20f9aa73 100644 --- a/apps/files_sharing/src/services/SharingService.ts +++ b/apps/files_sharing/src/services/SharingService.ts @@ -71,6 +71,17 @@ const ocsEntryToNode = async function(ocsEntry: any): Promise<Folder | File | nu mtime = new Date((ocsEntry.stime) * 1000) } + let sharees: { sharee: object } | undefined + if ('share_with' in ocsEntry) { + sharees = { + sharee: { + id: ocsEntry.share_with, + 'display-name': ocsEntry.share_with_displayname || ocsEntry.share_with, + type: ocsEntry.share_type, + }, + } + } + return new Node({ id: fileid, source, @@ -83,12 +94,14 @@ const ocsEntryToNode = async function(ocsEntry: any): Promise<Folder | File | nu attributes: { ...ocsEntry, 'has-preview': hasPreview, + 'hide-download': ocsEntry?.hide_download === 1, // Also check the sharingStatusAction.ts code 'owner-id': ocsEntry?.uid_owner, 'owner-display-name': ocsEntry?.displayname_owner, 'share-types': ocsEntry?.share_type, 'share-attributes': ocsEntry?.attributes || '[]', - favorite: ocsEntry?.tags?.includes((window.OC as Nextcloud.v29.OC & { TAG_FAVORITE: string }).TAG_FAVORITE) ? 1 : 0, + sharees, + favorite: ocsEntry?.tags?.includes((window.OC as { TAG_FAVORITE: string }).TAG_FAVORITE) ? 1 : 0, }, }) } catch (error) { diff --git a/apps/files_sharing/src/services/TabSections.js b/apps/files_sharing/src/services/TabSections.js index 8578f8f08d5..ab1237e7044 100644 --- a/apps/files_sharing/src/services/TabSections.js +++ b/apps/files_sharing/src/services/TabSections.js @@ -3,6 +3,14 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +/** + * Callback to render a section in the sharing tab. + * + * @callback registerSectionCallback + * @param {undefined} el - Deprecated and will always be undefined (formerly the root element) + * @param {object} fileInfo - File info object + */ + export default class TabSections { _sections diff --git a/apps/files_sharing/src/services/WebdavClient.ts b/apps/files_sharing/src/services/WebdavClient.ts deleted file mode 100644 index cd33147b03f..00000000000 --- a/apps/files_sharing/src/services/WebdavClient.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files' -import type { FileStat, ResponseDataDetailed } from 'webdav' -import type { Node } from '@nextcloud/files' - -export const client = davGetClient() - -export const fetchNode = async (node: Node): Promise<Node> => { - const propfindPayload = davGetDefaultPropfind() - const result = await client.stat(`${davRootPath}${node.path}`, { - details: true, - data: propfindPayload, - }) as ResponseDataDetailed<FileStat> - return davResultToNode(result.data) -} |