From fac5197486107559669b39c34fbd1330277e8847 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Wed, 20 Sep 2023 00:12:20 +0200 Subject: feat(files): add files_sharing indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .../src/actions/sharingStatusAction.scss | 35 ++++++ .../src/actions/sharingStatusAction.ts | 117 +++++++++++++++++++++ apps/files_sharing/src/files_sharing.ts | 30 ------ apps/files_sharing/src/init.ts | 31 ++++++ 4 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 apps/files_sharing/src/actions/sharingStatusAction.scss create mode 100644 apps/files_sharing/src/actions/sharingStatusAction.ts delete mode 100644 apps/files_sharing/src/files_sharing.ts create mode 100644 apps/files_sharing/src/init.ts (limited to 'apps/files_sharing/src') diff --git a/apps/files_sharing/src/actions/sharingStatusAction.scss b/apps/files_sharing/src/actions/sharingStatusAction.scss new file mode 100644 index 00000000000..fd37732d47c --- /dev/null +++ b/apps/files_sharing/src/actions/sharingStatusAction.scss @@ -0,0 +1,35 @@ +/** + * @copyright Copyright (c) 2023 John Molakvoæ + * + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + // Only when rendered inline, when not enough space, this is put in the menu +.action-items > .files-list__row-action-sharing-status { + // put icon at the end of the button + direction: rtl; + // align icons with textless inline actions + padding-right: 0 !important; +} + +svg.sharing-status__avatar { + height: 32px !important; + width: 32px !important; + border-radius: 32px; + overflow: hidden; +} \ No newline at end of file diff --git a/apps/files_sharing/src/actions/sharingStatusAction.ts b/apps/files_sharing/src/actions/sharingStatusAction.ts new file mode 100644 index 00000000000..054d6617ac9 --- /dev/null +++ b/apps/files_sharing/src/actions/sharingStatusAction.ts @@ -0,0 +1,117 @@ +/** + * @copyright Copyright (c) 2023 John Molakvoæ + * + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +import { Node, View, registerFileAction, FileAction, Permission } from '@nextcloud/files' +import { translate as t } from '@nextcloud/l10n' +import { Type } from '@nextcloud/sharing' + +import AccountGroupSvg from '@mdi/svg/svg/account-group.svg?raw' +import AccountPlusSvg from '@mdi/svg/svg/account-plus.svg?raw' +import LinkSvg from '@mdi/svg/svg/link.svg?raw' +import CircleSvg from '../../../../core/img/apps/circles.svg?raw' + +import { action as sidebarAction } from '../../../files/src/actions/sidebarAction' +import { generateUrl } from '@nextcloud/router' +import { getCurrentUser } from '@nextcloud/auth' + +import './sharingStatusAction.scss' + +const generateAvatarSvg = (userId: string) => { + const avatarUrl = generateUrl('/avatar/{userId}/32', { userId }) + return `` +} + +export const action = new FileAction({ + id: 'sharing-status', + displayName(nodes: Node[]) { + const node = nodes[0] + const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[] + if (shareTypes.length > 0) { + return t('files_sharing', 'Shared') + } + + const ownerId = node?.attributes?.['owner-id'] + if (ownerId && ownerId !== getCurrentUser()?.uid) { + return t('files_sharing', 'Shared') + } + + return '' + }, + iconSvgInline(nodes: Node[]) { + const node = nodes[0] + const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[] + + // Link shares + if (shareTypes.includes(Type.SHARE_TYPE_LINK) + || shareTypes.includes(Type.SHARE_TYPE_EMAIL)) { + return LinkSvg + } + + // Group shares + if (shareTypes.includes(Type.SHARE_TYPE_GROUP) + || shareTypes.includes(Type.SHARE_TYPE_REMOTE_GROUP)) { + return AccountGroupSvg + } + + // Circle shares + if (shareTypes.includes(Type.SHARE_TYPE_CIRCLE)) { + return CircleSvg + } + + const ownerId = node?.attributes?.['owner-id'] + if (ownerId && ownerId !== getCurrentUser()?.uid) { + return generateAvatarSvg(ownerId) + } + + return AccountPlusSvg + }, + + enabled(nodes: Node[]) { + if (nodes.length !== 1) { + return false + } + + const node = nodes[0] + const ownerId = node?.attributes?.['owner-id'] + if (ownerId && ownerId !== getCurrentUser()?.uid) { + return true + } + + return (node.permissions & Permission.SHARE) !== 0 + }, + + async exec(node: Node, view: View, dir: string) { + // You need read permissions to see the sidebar + if ((node.permissions & Permission.READ) !== 0) { + window.OCA?.Files?.Sidebar?.setActiveTab?.('sharing') + return sidebarAction.exec(node, view, dir) + } + return null + }, + + inline: () => true, + +}) + +registerFileAction(action) diff --git a/apps/files_sharing/src/files_sharing.ts b/apps/files_sharing/src/files_sharing.ts deleted file mode 100644 index 939cc91905d..00000000000 --- a/apps/files_sharing/src/files_sharing.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @copyright Copyright (c) 2019 John Molakvoæ - * - * @author John Molakvoæ - * @author Julius Härtl - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ -import registerSharingViews from './views/shares' - -import './actions/acceptShareAction' -import './actions/openInFilesAction' -import './actions/rejectShareAction' -import './actions/restoreShareAction' - -registerSharingViews() diff --git a/apps/files_sharing/src/init.ts b/apps/files_sharing/src/init.ts new file mode 100644 index 00000000000..734f888cb7d --- /dev/null +++ b/apps/files_sharing/src/init.ts @@ -0,0 +1,31 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ + * + * @author John Molakvoæ + * @author Julius Härtl + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +import registerSharingViews from './views/shares' + +import './actions/acceptShareAction' +import './actions/openInFilesAction' +import './actions/rejectShareAction' +import './actions/restoreShareAction' +import './actions/sharingStatusAction' + +registerSharingViews() -- cgit v1.2.3