aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-04 18:02:01 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-04 18:02:01 -0700
commit05623d59c14896da5ac1b2527e93d4af50ec87b6 (patch)
tree6e9dfb5d6f969b3b46b2725ca8bb264a86685111 /modern/src/common
parent53fd7f27b8a84b49ef7e4dafbc9e8ac985d7f3af (diff)
downloadtrackermap-web-05623d59c14896da5ac1b2527e93d4af50ec87b6.tar.gz
trackermap-web-05623d59c14896da5ac1b2527e93d4af50ec87b6.tar.bz2
trackermap-web-05623d59c14896da5ac1b2527e93d4af50ec87b6.zip
Handle user permissions
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/permissions.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/modern/src/common/permissions.js b/modern/src/common/permissions.js
new file mode 100644
index 00000000..72ca0b08
--- /dev/null
+++ b/modern/src/common/permissions.js
@@ -0,0 +1,11 @@
+import { useSelector } from 'react-redux';
+
+export const useAdministrator = () => useSelector((state) => state.session.user?.administrator);
+
+export const useReadonly = () => useSelector((state) => state.session.server?.readonly || state.session.user?.readonly);
+
+export const useDeviceReadonly = () => useSelector((state) => state.session.server?.readonly || state.session.user?.readonly
+ || state.session.server?.deviceReadonly || state.session.user?.deviceReadonly);
+
+export const useEditable = () => useSelector((state) => state.session.user?.administrator
+ || (!state.session.server?.readonly && !state.session.user?.readonly));