fix: file-menu showing 'download' for folders that can't zip
Massimo Melina committed
Dec 30, 2023 at 14:04 UTC
a984ae3c587b696ec66ecfbbd7f1ae578f2e8c8f
3 files changed
+9
-4
frontend/src/Breadcrumbs.ts
+4
-2
@@ -3,7 +3,7 @@
3
import { Link } from 'react-router-dom'
4
import { createElement as h, Fragment, ReactElement } from 'react'
5
import { getPrefixUrl, hIcon } from './misc'
6
-import { DirEntry, state } from './state'
6
+import { DirEntry, state, useSnapState } from './state'
7
import { usePath, reloadList } from './useFetchList'
8
import { useI18N } from './i18n'
9
import { openFileMenu } from './fileMenu'
@@ -33,6 +33,8 @@ function Breadcrumb({ path, label, current }:{ current?: boolean, path: string,
33
if (typeof label === 'string' && label.length < 3)
34
label = PAD + label + PAD
35
const {t} = useI18N()
36
+ const { props } = useSnapState()
37
+ const p = props?.can_archive ? '' : 'a'
38
return h(Link, {
39
className: 'breadcrumb',
40
to: path || '/',
@@ -40,7 +42,7 @@ function Breadcrumb({ path, label, current }:{ current?: boolean, path: string,
42
if (!current) return
43
if (typeof label !== 'string')
44
return reload()
43
- openFileMenu(new DirEntry(decodeURIComponent(path)), ev, [
45
+ openFileMenu(new DirEntry(decodeURIComponent(path), { p }), ev, [
46
{
47
id: 'reload',
48
label: t`Reload`,
frontend/src/fileMenu.ts
+3
-1
@@ -23,7 +23,9 @@ interface FileMenuEntry {
23
24
export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMenuEntry | 'open' | 'delete' | 'show')[]) {
25
const { uri, isFolder, s } = entry
26
- const cantDownload = entry.cantOpen || isFolder && entry.p?.includes('r') // folders needs both list and read
26
+ const canRead = !entry.p?.includes('r')
27
+ const canArchive = entry.p?.includes('A') || state.props?.can_archive && !entry.p?.includes('a')
28
+ const cantDownload = entry.cantOpen || isFolder && !(canRead && canArchive) // folders needs list+read+archive
29
const menu = [
30
!cantDownload && { id: 'download', label: t`Download`, href: uri + (isFolder ? '?get=zip' : '?dl'), icon: 'download' },
31
state.props?.can_comment && { id: 'comment', label: t`Comment`, icon: 'comment', onClick: () => editComment(entry) },
src/api.get_file_list.ts
+2
-1
@@ -121,12 +121,13 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
121
: !hasPermission(node, 'can_read', ctx) ? 'R'
122
: ''
123
const pd = !can_delete && hasPermission(node, 'can_delete', ctx) ? 'd' : ''
124
+ const pa = node.isFolder && Boolean(can_archive) === hasPermission(node, 'can_archive', ctx) ? '' : can_archive ? 'a' : 'A'
125
return {
126
n: name + (folder ? '/' : ''),
127
c: ctime,
128
m: Math.abs(+mtime-+ctime) < 1000 ? undefined : mtime,
129
s: folder ? undefined : st.size,
129
- p: (pr + pl + pd) || undefined,
130
+ p: (pr + pl + pd + pa) || undefined,
131
comment: await getCommentFor(source),
132
}
133
}