@samitouri / QOSami-HFS / commits / 7274c032

admin/accounts: allow files to be entered in the "redirect" field

Massimo Melina committed Feb 3, 2024 at 17:48 UTC 7274c0328de0a2381dead46903b32eb50a95b5a7
3 files changed +14 -9
admin/src/AccountForm.ts
+2 -2
@@ -84,8 +84,8 @@ export default function AccountForm({ account, done, groups, addToBar, reload }:
84 helperText: "When expired, login won't be allowed" },
85 { k: 'days_to_live', xs: 12, sm: 6, comp: NumberField, disabled: expired, step: 'any', min: 1/1000, // 10 minutes
86 helperText: "Used to set expiration on first login" + (expired ? " (already expired)" : '') },
87 - { k: 'redirect', comp: VfsPathField,
88 - helperText: "If you want this account to be redirected to a specific folder/address at login time" },
87 + { k: 'redirect', comp: VfsPathField, onlyFolders: false,
88 + helperText: "If you want this account to be redirected to a specific folder/address (or even file) at login time" },
89 ],
90 onError: alertDialog,
91 save: {
admin/src/VfsPathField.ts
+9 -4
@@ -1,13 +1,18 @@
1 import { dirname } from './misc'
2 import { useApiList } from './api'
3 import { createElement as h, useMemo } from 'react'
4 -import { Autocomplete, TextField } from '@mui/material'
4 +import { Autocomplete, AutocompleteProps, TextField } from '@mui/material'
5 +import { FieldProps } from '@hfs/mui-grid-form'
6
6 -export default function VfsPathField({ value='', onChange, helperText, setApi, autocompleteProps, ...props }: any) {
7 +interface VfsPathFieldProps extends FieldProps<string> {
8 + autocompleteProps: Partial<AutocompleteProps<string, false, true, undefined>>
9 +}
10 +
11 +export default function VfsPathField({ value='', onChange, helperText, setApi, autocompleteProps, onlyFolders=true, ...props }: VfsPathFieldProps) {
12 const uri = dirname(value)
8 - const { list, loading } = useApiList('get_file_list', { uri, admin: true, onlyFolders: true })
13 + const { list, loading } = useApiList('get_file_list', { uri, admin: true, onlyFolders })
14 const options = useMemo(() => [uri + '/'].concat(list.map(x => value + x.n)), [list, uri])
10 - return h(Autocomplete, {
15 + return h(Autocomplete<string, false, true, undefined>, {
16 value,
17 options,
18 isOptionEqualToValue: (o,v) => o === v || o === v + '/',
admin/src/api.ts
+3 -3
@@ -1,8 +1,8 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { createElement as h, useEffect, useMemo, useRef, useState } from 'react'
4 -import { Dict, err2msg, Falsy, LIST, useStateMounted, wantArray, xlate,
5 - HTTP_FORBIDDEN, HTTP_UNAUTHORIZED,} from './misc'
4 +import { Dict, err2msg, Falsy, LIST, useStateMounted, wantArray, xlate, objSameKeys,
5 + HTTP_FORBIDDEN, HTTP_UNAUTHORIZED } from './misc'
6 import { IconBtn, spinner } from './mui'
7 import { Alert } from '@mui/material'
8 import _ from 'lodash'
@@ -63,7 +63,7 @@ export function useApiList<T=any, S=T>(cmd:string|Falsy, params: Dict={}, { map,
63 setConnecting(true)
64 setInitializing(true)
65 setList([])
66 - const src = apiEvents(cmd, params, (type, data) => {
66 + const src = apiEvents(cmd, objSameKeys(params, x => x === false ? undefined : x), (type, data) => {
67 switch (type) {
68 case 'connected':
69 setConnecting(false)