Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): disable Unshare until proper fix #43152

Merged
merged 2 commits into from
Jan 27, 2024
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
29 changes: 15 additions & 14 deletions apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ describe('Delete action conditions tests', () => {
permissions: Permission.ALL,
})

const file2 = new File({
id: 1,
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
owner: 'admin',
mime: 'text/plain',
permissions: Permission.ALL,
})
// const file2 = new File({
// id: 1,
// source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
// owner: 'admin',
// mime: 'text/plain',
// permissions: Permission.ALL,
// })

test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
Expand All @@ -71,14 +71,15 @@ describe('Delete action conditions tests', () => {
expect(action.displayName([file], trashbinView)).toBe('Delete permanently')
})

test('Shared node values', () => {
jest.spyOn(auth, 'getCurrentUser').mockReturnValue(null)
expect(action.displayName([file2], view)).toBe('Unshare')
})
// TODO: Fix this test
// test('Shared node values', () => {
// jest.spyOn(auth, 'getCurrentUser').mockReturnValue(null)
// expect(action.displayName([file2], view)).toBe('Unshare')
// })

test('Shared and owned nodes values', () => {
expect(action.displayName([file, file2], view)).toBe('Delete and unshare')
})
// test('Shared and owned nodes values', () => {
// expect(action.displayName([file, file2], view)).toBe('Delete and unshare')
// })
})

describe('Delete action enabled tests', () => {
Expand Down
25 changes: 1 addition & 24 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,17 @@ import { Permission, Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'
import CloseSvg from '@mdi/svg/svg/close.svg?raw'

import logger from '../logger.js'
import { getCurrentUser } from '@nextcloud/auth'

const isAllUnshare = (nodes: Node[]) => {
return !nodes.some(node => node.owner === getCurrentUser()?.uid)
}

const isMixedUnshareAndDelete = (nodes: Node[]) => {
const hasUnshareItems = nodes.some(node => node.owner !== getCurrentUser()?.uid)
const hasDeleteItems = nodes.some(node => node.owner === getCurrentUser()?.uid)
return hasUnshareItems && hasDeleteItems
}

export const action = new FileAction({
id: 'delete',
displayName(nodes: Node[], view: View) {
if (isMixedUnshareAndDelete(nodes)) {
return t('files', 'Delete and unshare')
}

if (isAllUnshare(nodes)) {
return t('files', 'Unshare')
}

return view.id === 'trashbin'
? t('files', 'Delete permanently')
: t('files', 'Delete')
},
iconSvgInline: (nodes: Node[]) => {
if (isAllUnshare(nodes)) {
return CloseSvg
}
iconSvgInline: () => {
return TrashCanSvg
},

Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

Loading