Skip to content
Open
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
46 changes: 46 additions & 0 deletions apps/files_sharing/src/files_actions/sharingStatusAction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*!
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { IFolder, IView } from '@nextcloud/files'

import AccountGroupSvg from '@mdi/svg/svg/account-group-outline.svg?raw'
import LinkSvg from '@mdi/svg/svg/link.svg?raw'
import { Folder, Permission } from '@nextcloud/files'
import { ShareType } from '@nextcloud/sharing'
import { describe, expect, test, vi } from 'vitest'
import { action } from './sharingStatusAction.ts'

vi.mock('@nextcloud/auth', () => ({
getCurrentUser: () => ({ uid: 'alice' }),
}))

const view = { id: 'files', name: 'Files' } as IView

function getIcon(owner: string, shareTypes: ShareType[]): string {
const node = new Folder({
id: 1,
source: 'https://cloud.example.com/remote.php/dav/files/alice/Shared',
owner,
root: '/files/alice',
permissions: Permission.ALL,
attributes: { 'share-types': { 'share-type': shareTypes } },
})
return action.iconSvgInline({ nodes: [node], view, folder: {} as IFolder, contents: [] })
}

describe('Sharing status action icon', () => {
test('a folder shared with the user shows the owner avatar', () => {
expect(getIcon('bob', [])).toContain('/avatar/bob/32')
})

test('a folder shared with the user through a group still shows the owner avatar', () => {
expect(getIcon('bob', [ShareType.Group])).toContain('/avatar/bob/32')
})

test('a folder shared by the user shows the share type', () => {
expect(getIcon('alice', [ShareType.Group])).toBe(AccountGroupSvg)
expect(getIcon('alice', [ShareType.Link])).toBe(LinkSvg)
})
})
9 changes: 5 additions & 4 deletions apps/files_sharing/src/files_actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const action: IFileAction = {

iconSvgInline({ nodes }) {
const node = nodes[0]!
// Shared by someone else, like the title. The share types also hold the received share in some responses
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return generateAvatarSvg(node.owner, isExternal(node))
}

const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[]

// Mixed share types
Expand All @@ -98,10 +103,6 @@ export const action: IFileAction = {
return CircleSvg
}

if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return generateAvatarSvg(node.owner, isExternal(node))
}

return AccountPlusSvg
},

Expand Down
Loading