admin/fs: allow to set permission value even if it's the same as-parent
Massimo Melina committed
Dec 14, 2023 at 00:13 UTC
cefef5abb15637c7af93ade91df13610dcfc4006
2 files changed
+4
-16
admin/src/FileForm.ts
+4
-7
@@ -22,14 +22,13 @@ interface Account { username: string }
22
23
interface FileFormProps {
24
file: VfsNode
25
- anyMask?: boolean
25
addToBar?: ReactNode
26
statusApi: UseApi
27
}
28
29
const ACCEPT_LINK = "https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept"
30
32
-export default function FileForm({ file, anyMask, addToBar, statusApi }: FileFormProps) {
31
+export default function FileForm({ file, addToBar, statusApi }: FileFormProps) {
32
const { parent, children, isRoot, byMasks, ...rest } = file
33
const [values, setValues] = useState(rest)
34
useEffect(() => {
@@ -168,7 +167,6 @@ export default function FileForm({ file, anyMask, addToBar, statusApi }: FileFor
167
comp: WhoField,
168
k: perm, lg: 6, xl: 4,
169
parent, accounts, helperText, isDir,
171
- showInherited: anyMask, // with masks, you may need to set a permission to override the mask
170
otherPerms: others.map(x => ({ value: x, label: "As " +perm2word(x) })),
171
label: "Who can " + perm2word(perm),
172
inherit: file.inherited?.[perm] ?? defaultPerms[perm],
@@ -192,7 +190,7 @@ interface WhoFieldProps extends FieldProps<Who | undefined> {
190
isDir: boolean
191
contentText?: string
192
}
195
-function WhoField({ value, onChange, parent, inherit, accounts, helperText, showInherited, otherPerms, byMasks,
193
+function WhoField({ value, onChange, parent, inherit, accounts, helperText, otherPerms, byMasks,
194
hideValues, isChildren, isDir, contentText="folder content", setApi, ...rest }: WhoFieldProps): ReactElement {
195
const defaultLabel = (byMasks !== undefined ? "As per mask: " : parent !== undefined ? "As parent: " : "Default: " )
196
+ who2desc(byMasks ?? inherit)
@@ -207,8 +205,7 @@ function WhoField({ value, onChange, parent, inherit, accounts, helperText, show
205
{ value: '*' },
206
...otherPerms,
207
{ value: [], label: "Select accounts" },
210
- // don't offer inherited value twice, unless it was already selected, or it is forced
211
- ].map(x => !hideValues?.includes(x.value) && (x.value === thisValue || showInherited || x.value !== inherit)
208
+ ].map(x => !hideValues?.includes(x.value)
209
&& { label: _.capitalize(who2desc(x.value)), ...x })), // default label
210
[inherit, parent, thisValue])
211
@@ -243,7 +240,7 @@ function WhoField({ value, onChange, parent, inherit, accounts, helperText, show
240
!isChildren && h(Collapse, { in: objectMode, timeout },
241
h(WhoField, {
242
label: "Permission for " + contentText,
246
- parent, inherit, accounts, showInherited, otherPerms, isDir,
243
+ parent, inherit, accounts, otherPerms, isDir,
244
value: objectMode && value?.children,
245
isChildren: true,
246
hideValues: [thisValue ?? inherit, thisValue],
admin/src/VfsPage.ts
-9
@@ -21,14 +21,6 @@ export default function VfsPage() {
21
const { vfs, selectedFiles, movingFile } = useSnapState()
22
const { data, reload, element } = useApiEx('get_vfs')
23
useMemo(() => vfs || reload(), [vfs, reload])
24
- const anyMask = useMemo(() => {
25
- let f = selectedFiles[0]
26
- while (f)
27
- if (_.isEmpty(f.masks))
28
- f = f.parent as any
29
- else
30
- return true
31
- }, [selectedFiles])
24
const sideBreakpoint = 'md'
25
const isSideBreakpoint = useBreakpoint(sideBreakpoint)
26
const statusApi = useApiEx('get_status')
@@ -51,7 +43,6 @@ export default function VfsPage() {
43
vfsNodeIcon(selectedFiles[0] as VfsNode),
44
h(IconBtn, { icon: Close, title: "Close", onClick: selectNone })
45
],
54
- anyMask,
46
statusApi,
47
file: selectedFiles[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way
48
})