diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-18 16:51:46 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-18 16:51:46 -0700 |
commit | 4993f83ad1a5ad78a0b076503ab8c0b8f1bbf073 (patch) | |
tree | c5e4ce57cca3aad35e1869f21faa99b930871d51 | |
parent | b88aa76538f8cebfa64d7f0d6b1cba8608432068 (diff) | |
download | trackermap-web-4993f83ad1a5ad78a0b076503ab8c0b8f1bbf073.tar.gz trackermap-web-4993f83ad1a5ad78a0b076503ab8c0b8f1bbf073.tar.bz2 trackermap-web-4993f83ad1a5ad78a0b076503ab8c0b8f1bbf073.zip |
Option to disable email change
-rw-r--r-- | modern/src/common/components/BottomMenu.js | 4 | ||||
-rw-r--r-- | modern/src/common/util/permissions.js | 14 | ||||
-rw-r--r-- | modern/src/main/StatusCard.js | 4 | ||||
-rw-r--r-- | modern/src/settings/ServerPage.js | 4 | ||||
-rw-r--r-- | modern/src/settings/UserPage.js | 9 | ||||
-rw-r--r-- | modern/src/settings/components/CollectionFab.js | 4 | ||||
-rw-r--r-- | modern/src/settings/components/SettingsMenu.js | 4 | ||||
-rw-r--r-- | web/l10n/en.json | 1 |
8 files changed, 28 insertions, 16 deletions
diff --git a/modern/src/common/components/BottomMenu.js b/modern/src/common/components/BottomMenu.js index 37bdcf10..504e642a 100644 --- a/modern/src/common/components/BottomMenu.js +++ b/modern/src/common/components/BottomMenu.js @@ -13,7 +13,7 @@ import ExitToAppIcon from '@mui/icons-material/ExitToApp'; import { sessionActions } from '../../store'; import { useTranslation } from './LocalizationProvider'; -import { useReadonly } from '../util/permissions'; +import { useRestriction } from '../util/permissions'; const BottomMenu = () => { const navigate = useNavigate(); @@ -21,7 +21,7 @@ const BottomMenu = () => { const dispatch = useDispatch(); const t = useTranslation(); - const readonly = useReadonly(); + const readonly = useRestriction('readonly'); const userId = useSelector((state) => state.session.user.id); const socket = useSelector((state) => state.session.socket); diff --git a/modern/src/common/util/permissions.js b/modern/src/common/util/permissions.js index c866c41e..76e0aa58 100644 --- a/modern/src/common/util/permissions.js +++ b/modern/src/common/util/permissions.js @@ -11,13 +11,6 @@ export const useManager = () => useSelector((state) => { return admin || manager; }); -export const useReadonly = () => useSelector((state) => { - const admin = state.session.user.administrator; - const serverReadonly = state.session.server.readonly; - const userReadonly = state.session.user.readonly; - return !admin && (serverReadonly || userReadonly); -}); - export const useDeviceReadonly = () => useSelector((state) => { const admin = state.session.user.administrator; const serverReadonly = state.session.server.readonly; @@ -26,3 +19,10 @@ export const useDeviceReadonly = () => useSelector((state) => { const userDeviceReadonly = state.session.user.deviceReadonly; return !admin && (serverReadonly || userReadonly || serverDeviceReadonly || userDeviceReadonly); }); + +export const useRestriction = (key) => useSelector((state) => { + const admin = state.session.user.administrator; + const serverValue = state.session.server[key]; + const userValue = state.session.user[key]; + return !admin && (serverValue || userValue); +}); diff --git a/modern/src/main/StatusCard.js b/modern/src/main/StatusCard.js index 4067ac1e..8847fcc6 100644 --- a/modern/src/main/StatusCard.js +++ b/modern/src/main/StatusCard.js @@ -26,7 +26,7 @@ import InfoIcon from '@mui/icons-material/Info'; import { useTranslation } from '../common/components/LocalizationProvider'; import RemoveDialog from '../common/components/RemoveDialog'; import PositionValue from '../common/components/PositionValue'; -import { useDeviceReadonly, useReadonly } from '../common/util/permissions'; +import { useDeviceReadonly, useRestriction } from '../common/util/permissions'; import usePersistedState from '../common/util/usePersistedState'; import usePositionAttributes from '../common/attributes/usePositionAttributes'; import { devicesActions } from '../store'; @@ -99,7 +99,7 @@ const StatusCard = ({ deviceId, onClose }) => { const dispatch = useDispatch(); const t = useTranslation(); - const readonly = useReadonly(); + const readonly = useRestriction('readonly'); const deviceReadonly = useDeviceReadonly(); const device = useSelector((state) => state.devices.items[deviceId]); diff --git a/modern/src/settings/ServerPage.js b/modern/src/settings/ServerPage.js index 22dd66af..e51c002c 100644 --- a/modern/src/settings/ServerPage.js +++ b/modern/src/settings/ServerPage.js @@ -238,6 +238,10 @@ const ServerPage = () => { control={<Checkbox checked={item.disableReports} onChange={(event) => setItem({ ...item, disableReports: event.target.checked })} />} label={t('userDisableReports')} /> + <FormControlLabel + control={<Checkbox checked={item.fixedEmail} onChange={(e) => setItem({ ...item, fixedEmail: e.target.checked })} />} + label={t('userFixedEmail')} + /> </FormGroup> </AccordionDetails> </Accordion> diff --git a/modern/src/settings/UserPage.js b/modern/src/settings/UserPage.js index 863bb0b7..61fdd412 100644 --- a/modern/src/settings/UserPage.js +++ b/modern/src/settings/UserPage.js @@ -33,7 +33,7 @@ import { sessionActions } from '../store'; import SelectField from '../common/components/SelectField'; import SettingsMenu from './components/SettingsMenu'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; -import { useAdministrator, useManager } from '../common/util/permissions'; +import { useAdministrator, useRestriction, useManager } from '../common/util/permissions'; import { prefixString } from '../common/util/stringUtils'; import useQuery from '../common/util/useQuery'; import { useCatch } from '../reactHelper'; @@ -55,6 +55,7 @@ const UserPage = () => { const admin = useAdministrator(); const manager = useManager(); + const fixedEmail = useRestriction('fixedEmail'); const currentUser = useSelector((state) => state.session.user); @@ -134,6 +135,7 @@ const UserPage = () => { value={item.email || ''} onChange={(event) => setItem({ ...item, email: event.target.value })} label={t('userEmail')} + disabled={fixedEmail} /> <TextField type="password" @@ -333,6 +335,11 @@ const UserPage = () => { label={t('userDisableReports')} disabled={!manager} /> + <FormControlLabel + control={<Checkbox checked={item.fixedEmail} onChange={(e) => setItem({ ...item, fixedEmail: e.target.checked })} />} + label={t('userFixedEmail')} + disabled={!manager} + /> </FormGroup> </AccordionDetails> </Accordion> diff --git a/modern/src/settings/components/CollectionFab.js b/modern/src/settings/components/CollectionFab.js index b1230733..3c1fa783 100644 --- a/modern/src/settings/components/CollectionFab.js +++ b/modern/src/settings/components/CollectionFab.js @@ -3,7 +3,7 @@ import { Fab } from '@mui/material'; import makeStyles from '@mui/styles/makeStyles'; import AddIcon from '@mui/icons-material/Add'; import { useNavigate } from 'react-router-dom'; -import { useReadonly } from '../../common/util/permissions'; +import { useRestriction } from '../../common/util/permissions'; const useStyles = makeStyles((theme) => ({ fab: { @@ -20,7 +20,7 @@ const CollectionFab = ({ editPath, disabled }) => { const classes = useStyles(); const navigate = useNavigate(); - const readonly = useReadonly(); + const readonly = useRestriction('readonly'); if (!readonly && !disabled) { return ( diff --git a/modern/src/settings/components/SettingsMenu.js b/modern/src/settings/components/SettingsMenu.js index 51d9b8fc..7a1bf1b3 100644 --- a/modern/src/settings/components/SettingsMenu.js +++ b/modern/src/settings/components/SettingsMenu.js @@ -15,7 +15,7 @@ import PublishIcon from '@mui/icons-material/Publish'; import { Link, useLocation } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { useTranslation } from '../../common/components/LocalizationProvider'; -import { useAdministrator, useManager, useReadonly } from '../../common/util/permissions'; +import { useAdministrator, useManager, useRestriction } from '../../common/util/permissions'; import useFeatures from '../../common/util/useFeatures'; const MenuItem = ({ @@ -31,7 +31,7 @@ const SettingsMenu = () => { const t = useTranslation(); const location = useLocation(); - const readonly = useReadonly(); + const readonly = useRestriction('readonly'); const admin = useAdministrator(); const manager = useManager(); const userId = useSelector((state) => state.session.user.id); diff --git a/web/l10n/en.json b/web/l10n/en.json index 603d9b36..21b7e40e 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -144,6 +144,7 @@ "userDeviceReadonly": "Device Readonly", "userLimitCommands": "Limit Commands", "userDisableReports": "Disable Reports", + "userFixedEmail": "No Email Change", "userToken": "Token", "userDeleteAccount": "Delete Account", "loginTitle": "Login", |