diff --git a/public/favicon.ico b/public/favicon.ico
index a11777c..7421c6d 100644
Binary files a/public/favicon.ico and b/public/favicon.ico differ
diff --git a/src/pages/Users.js b/src/pages/Users.js
index f1c5bb4..77ae4a6 100644
--- a/src/pages/Users.js
+++ b/src/pages/Users.js
@@ -1,22 +1,28 @@
import React, { useEffect, useRef, useState } from "react";
import { Route, Routes, useNavigate, useParams } from "react-router";
import ErrorBoundary from "../util/ErrorBoundary";
-import { get } from '../util/Util';
+import { get, post } from '../util/Util';
import '../css/pages/Users.css';
import { Table, TableListEntry } from "../components/Table";
-const Permission = ({name, value}) => {
+const Permission = ({ name, value, chain, updatePerms }) => {
+ const inputRef = useRef();
+ const onChange = () => {
+ const val = inputRef.current.value;
+ updatePerms(chain, val);
+ };
+
return
-
+
;
};
-const PermissionGroup = ({ name, value }) => {
+const PermissionGroup = ({ name, value, chain, updatePerms }) => {
const elements = [];
for (const [perm, val] of Object.entries(value)) {
- const props = { key: perm, name: perm, value: val };
+ const props = { key: perm, name: perm, value: val, updatePerms, chain: `${chain}:${perm}` };
if(typeof val ==='object') elements.push();
else elements.push();
}
@@ -30,12 +36,12 @@ const PermissionGroup = ({ name, value }) => {
;
};
-const Permissions = ({ perms }) => {
+const Permissions = ({ perms, updatePerms }) => {
const elements = [];
const keys = Object.keys(perms);
for (const perm of keys) {
- const props = { key: perm, name: perm, value: perms[perm] };
+ const props = { key: perm, name: perm, value: perms[perm], chain: perm, updatePerms };
let Elem = null;
switch (typeof perms[perm]) {
case 'number':
@@ -96,6 +102,7 @@ const User = ({ user }) => {
const navigate = useNavigate();
const [apps, updateApps] = useState([]);
+ const perms = {...user.permissions};
useEffect(() => {
(async () => {
@@ -104,6 +111,22 @@ const User = ({ user }) => {
})();
}, []);
+ const updatePerms = (chain, value) => {
+ value = parseInt(value);
+ if (isNaN(value)) return;
+
+ let selected = perms;
+ const keys = chain.split(':');
+ for (const key of keys) {
+ if (key === keys[keys.length - 1]) selected[key] = value;
+ else selected = selected[key];
+ }
+ };
+
+ const commitPerms = async () => {
+ await post(`/api/users/${user.id}/permissions`, perms);
+ };
+
const ApplicationWrapper = () => {
const { appid } = useParams();
const app = apps.find(a => a.id === appid);
@@ -130,17 +153,12 @@ const User = ({ user }) => {
2FA: {user.twoFactor.toString()}
Disabled: {user.disabled.toString()}
-
-
+
+
-
+
-
-
Applications
} />
@@ -150,7 +168,8 @@ const User = ({ user }) => {