admin/fs: smarter displaying of permissions, in case you use masks
Massimo Melina committed
Feb 20, 2023 at 18:17 UTC
f185e961ab139c4809b4077a42a3cfa6b03f70c8
2 files changed
+13
-4
admin/src/FileForm.ts
+6
-4
@@ -16,7 +16,7 @@ import { Delete } from '@mui/icons-material'
16
17
interface Account { username: string }
18
19
-export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNode, defaultPerms: VfsPerms, addToBar?: ReactNode }) {
19
+export default function FileForm({ file, anyMask, defaultPerms, addToBar }: { file: VfsNode, anyMask?: boolean, defaultPerms: VfsPerms, addToBar?: ReactNode }) {
20
const { parent, children, isRoot, ...rest } = file
21
const [values, setValues] = useState(rest)
22
useEffect(() => {
@@ -104,7 +104,8 @@ export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNo
104
})
105
106
function perm(perm: keyof typeof inheritedPerms, label: string, helperText='', { accounts=allAccounts, ...props }={}) {
107
- return { k: perm, lg: 6, comp: WhoField, parent, accounts, label, inherit: inheritedPerms[perm], helperText, ...props }
107
+ return { showInherited: anyMask, // with masks, you may need to set a permission to override the mask
108
+ k: perm, lg: 6, comp: WhoField, parent, accounts, label, inherit: inheritedPerms[perm], helperText, ...props }
109
}
110
}
111
@@ -113,7 +114,7 @@ function formatTimestamp(x: string) {
114
}
115
116
interface WhoFieldProps extends FieldProps<Who> { accounts: Account[] }
116
-function WhoField({ value, onChange, parent, inherit, accounts, helperText, ...rest }: WhoFieldProps) {
117
+function WhoField({ value, onChange, parent, inherit, accounts, helperText, showInherited, ...rest }: WhoFieldProps) {
118
const options = useMemo(() =>
119
onlyTruthy([
120
{ value: null, label: (parent ? "Same as parent: " : "Default: " ) + who2desc(inherit) },
@@ -121,7 +122,8 @@ function WhoField({ value, onChange, parent, inherit, accounts, helperText, ...r
122
{ value: false },
123
{ value: '*' },
124
{ value: [], label: "Select accounts" },
124
- ].map(x => (x.value === value || x.value !== inherit) // don't offer inherited value twice, unless it was already selected
125
+ // don't offer inherited value twice, unless it was already selected, or it is forced
126
+ ].map(x => (x.value === value || showInherited || x.value !== inherit)
127
&& { label: _.capitalize(who2desc(x.value)), ...x })), // default label
128
[inherit, parent, value])
129
admin/src/VfsPage.ts
+7
@@ -30,6 +30,12 @@ export default function VfsPage() {
30
const { vfs, selectedFiles } = useSnapState()
31
const { data, reload, element } = useApiEx('get_vfs')
32
useMemo(() => vfs || reload(), [vfs, reload])
33
+ const anyMask = useMemo(() => {
34
+ return recur(vfs)
35
+ function recur(node: typeof vfs) {
36
+ return !_.isEmpty(node?.masks) || node?.children?.some(recur)
37
+ }
38
+ }, [vfs])
39
const sideBreakpoint = 'md'
40
const isSideBreakpoint = useBreakpoint(sideBreakpoint)
41
@@ -45,6 +51,7 @@ export default function VfsPage() {
51
onClick: close
52
}),
53
defaultPerms: data?.defaultPerms as VfsPerms,
54
+ anyMask,
55
file: selectedFiles[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way
56
})
57
: h(Fragment, {},