admin/fs: allow "can see" field to select a subset of "can download" accounts

Massimo Melina committed Feb 11, 2023 at 16:25 UTC 414cbee270724d0f9d4d06c52b1724fe237ac0e7
1 file changed +5 -4
admin/src/FileForm.ts
+5 -4
@@ -36,14 +36,14 @@ export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNo
36 }
37 return _.defaults(ret, defaultPerms)
38 }, [parent])
39 - const showCanSee = (values.can_read ?? inheritedPerms.can_read) === true
39 const showTimestamps = hasSource && Boolean(values.ctime)
40 const barColors = useDialogBarColors()
41
42 const { data, element } = useApiEx<{ list: Account[] }>('get_accounts')
43 if (element || !data)
44 return element
46 - const accounts = data.list
45 + const allAccounts = data.list
46 + const can_read = (values.can_read ?? inheritedPerms.can_read)
47
48 return h(Form, {
49 values,
@@ -84,7 +84,8 @@ export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNo
84 placeholder: "Not on disk, this is a virtual folder",
85 },
86 perm('can_read', "Who can download", "Note: who can't download won't see it in the list"),
87 - showCanSee && perm('can_see', "Who can see", "You can hide and keep it downloadable if you have a direct link"),
87 + can_read && perm('can_see', "Who can see", "You can hide and keep it downloadable if you have a direct link",
88 + { accounts: Array.isArray(can_read) ? allAccounts.filter(x => can_read.includes(x.username)) : undefined }),
89 isDir && perm('can_upload', "Who can upload", hasSource ? '' : "Works only on folders with source"),
90 hasSource && !realFolder && { k: 'size', comp: DisplayField, lg: 4, toField: formatBytes },
91 showTimestamps && { k: 'ctime', comp: DisplayField, md: 6, lg: 4, label: 'Created', toField: formatTimestamp },
@@ -100,7 +101,7 @@ export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNo
101 ]
102 })
103
103 - function perm(perm: keyof typeof inheritedPerms, label: string, helperText='', props={}) {
104 + function perm(perm: keyof typeof inheritedPerms, label: string, helperText='', { accounts=allAccounts, ...props }={}) {
105 return { k: perm, lg: 6, comp: WhoField, parent, accounts, label, inherit: inheritedPerms[perm], helperText, ...props }
106 }
107 }