fix: admin/account: inconsistent admin value communicated (false should not be used, for the sake of inheritance)
Massimo Melina committed
Mar 8, 2022 at 10:08 UTC
1d8dfb350ddabbb4bb8bfaeb4bda1937ae90bc3f
2 files changed
+9
-5
admin/src/AccountsPage.ts
+5
-3
@@ -3,10 +3,10 @@
3
import { isValidElement, createElement as h, useState, useEffect, Fragment } from "react"
4
import { apiCall, useApi, useApiComp } from './api'
5
import { Box, Button, Card, CardContent, Grid, List, ListItem, ListItemText, Typography } from '@mui/material'
6
-import { Delete, Group, Person, PersonAdd, Refresh } from '@mui/icons-material'
6
+import { Delete, Group, MilitaryTech, Person, PersonAdd, Refresh } from '@mui/icons-material'
7
import { BoolField, Form, MultiSelectField, SelectField, StringField } from './Form'
8
import { alertDialog, confirmDialog } from './dialog'
9
-import { isEqualLax, onlyTruthy } from './misc'
9
+import { iconTooltip, isEqualLax, onlyTruthy } from './misc'
10
import { TreeItem, TreeView } from '@mui/lab'
11
import { makeStyles } from '@mui/styles'
12
import { createVerifierAndSalt, SRPParameters, SRPRoutines } from 'tssrp6a'
@@ -23,6 +23,7 @@ const useStyles = makeStyles({
23
interface Account {
24
username: string
25
hasPassword?: boolean
26
+ adminActualAccess?: boolean
27
ignore_limits?: boolean
28
redirect?: string
29
belongs?: string[]
@@ -93,6 +94,7 @@ export default function AccountsPage() {
94
nodeId: ac.username,
95
label: h('div', { className: styles.label },
96
account2icon(ac),
97
+ ac.adminActualAccess && iconTooltip(MilitaryTech, "Can login into Admin"),
98
ac.username,
99
Boolean(ac.belongs?.length) && h(Box, { sx: { color: 'text.secondary', fontSize: 'small' } },
100
'(', ac.belongs?.join(', '), ')')
@@ -157,7 +159,7 @@ function AccountForm({ account, done, groups, config }: { account: Account, grou
159
!group && { k: 'password2', comp: StringField, md: 6, type: 'password', autoComplete: 'off', label: 'Repeat password' },
160
{ k: 'ignore_limits', comp: BoolField,
161
helperText: values.ignore_limits ? "Speed limits don't apply to this account" : "Speed limits apply to this account" },
160
- { k: 'admin', comp: BoolField, label: "Permission to access Admin interface",
162
+ { k: 'admin', comp: BoolField, fromField: (v:boolean) => v||null, label: "Permission to access Admin interface",
163
helperText: "It's THIS interface you are using right now."
164
+ (config.admin_login ? '' : " You are currently giving free access without login. You can force login in Configuration page.")
165
},
server/src/api.accounts.ts
+4
-2
@@ -36,8 +36,10 @@ const apis: ApiHandlers = {
36
37
set_account({ username, changes }) {
38
const { admin } = changes
39
- if (typeof admin !== 'boolean' && typeof admin !== 'undefined')
40
- return new ApiError(400, "admin must be boolean")
39
+ if (admin === null)
40
+ changes.admin = undefined
41
+ else if (typeof admin !== 'boolean')
42
+ return new ApiError(400, "invalid admin")
43
if (getConfig('admin_login') && admin === false && !anyOtherAccessibleAccountWithAdmin())
44
return new ApiError(403, "you can't disable admin because this is the last account with such permission")
45
return setAccount(username, changes) ? {} : new ApiError(400)