fixed some group permission issues
This commit is contained in:
parent
6ee7aa95a9
commit
25de677106
7 changed files with 90 additions and 15 deletions
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -4549,7 +4549,7 @@
|
||||||
},
|
},
|
||||||
"node_modules/protobuf-ts": {
|
"node_modules/protobuf-ts": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#3317c70ecda93740f8552e656429a42f1b15f350",
|
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#0a0a2671905de63ec02ff13b4a060b2b7a895e37",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"protobufjs": "^6.8.8"
|
"protobufjs": "^6.8.8"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,12 @@ interface Props {
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
disableAddTag?: boolean;
|
disableAddTag?: boolean;
|
||||||
tags: pond.Tag[];
|
tags: pond.Tag[];
|
||||||
|
groupID?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DeviceOverview(props: Props) {
|
export default function DeviceOverview(props: Props) {
|
||||||
const [{ user, firmware }] = useGlobalState();
|
const [{ user, firmware }] = useGlobalState();
|
||||||
const { device, components, usage, loading, disableAddTag, tags } = props;
|
const { device, components, groupID, usage, loading, disableAddTag, tags } = props;
|
||||||
const prevComponents = usePrevious(components);
|
const prevComponents = usePrevious(components);
|
||||||
const { info } = useSnackbar();
|
const { info } = useSnackbar();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
@ -78,8 +79,7 @@ export default function DeviceOverview(props: Props) {
|
||||||
}, [components, prevComponents]);
|
}, [components, prevComponents]);
|
||||||
|
|
||||||
const pathToDevice = () => {
|
const pathToDevice = () => {
|
||||||
if (useParams().groupID) {
|
if (groupID) {
|
||||||
const groupID = parseInt(useParams().groupID ?? "0", 10);
|
|
||||||
const groupPath: string = groupID > 0 ? "/groups/" + groupID.toString() : "";
|
const groupPath: string = groupID > 0 ? "/groups/" + groupID.toString() : "";
|
||||||
const devicePath: string = "/devices/" + device.settings.deviceId.toString();
|
const devicePath: string = "/devices/" + device.settings.deviceId.toString();
|
||||||
return groupPath + devicePath;
|
return groupPath + devicePath;
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,7 @@ export default function GroupSettings(props: Props) {
|
||||||
//}, [groupDevices])
|
//}, [groupDevices])
|
||||||
|
|
||||||
const addDevice = (device: number) => {
|
const addDevice = (device: number) => {
|
||||||
|
console.log("adding device?????")
|
||||||
groupAPI.addDevice(group.id(), device).then(() => {
|
groupAPI.addDevice(group.id(), device).then(() => {
|
||||||
refreshCallback();
|
refreshCallback();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export default function DevicePage() {
|
||||||
const snackbar = useSnackbar()
|
const snackbar = useSnackbar()
|
||||||
const isMobile = useMobile()
|
const isMobile = useMobile()
|
||||||
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
||||||
|
const groupID = useParams<{ groupID: string }>()?.groupID ?? "";
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
const [{ as, team, user }] = useGlobalState()
|
const [{ as, team, user }] = useGlobalState()
|
||||||
const [device, setDevice] = useState<Device>(state?.device ? Device.create(state.device) : Device.create())
|
const [device, setDevice] = useState<Device>(state?.device ? Device.create(state.device) : Device.create())
|
||||||
|
|
@ -164,6 +165,7 @@ export default function DevicePage() {
|
||||||
usage={getUsage()}
|
usage={getUsage()}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
tags={tags}
|
tags={tags}
|
||||||
|
groupID={parseInt(groupID)}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { pond } from "protobuf-ts/pond";
|
||||||
import { useDeviceAPI, useGroupAPI } from "providers";
|
import { useDeviceAPI, useGroupAPI } from "providers";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import PageContainer from "./PageContainer";
|
import PageContainer from "./PageContainer";
|
||||||
import { useMobile } from "hooks";
|
import { useMobile, usePermissionAPI } from "hooks";
|
||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||||
import { getDeviceStateHelper } from "pbHelpers/DeviceState";
|
import { getDeviceStateHelper } from "pbHelpers/DeviceState";
|
||||||
|
|
@ -67,6 +67,7 @@ export default function Devices() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const groupAPI = useGroupAPI();
|
const groupAPI = useGroupAPI();
|
||||||
|
const permissionAPI = usePermissionAPI();
|
||||||
const [devicesLoading, setDevicesLoading] = useState(false)
|
const [devicesLoading, setDevicesLoading] = useState(false)
|
||||||
const [limit, setLimit] = useState(10);
|
const [limit, setLimit] = useState(10);
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
|
|
@ -88,9 +89,10 @@ export default function Devices() {
|
||||||
const [searchGroup, ] = useState("");
|
const [searchGroup, ] = useState("");
|
||||||
// const [totalGroups, setTotalGroups] = useState(0);
|
// const [totalGroups, setTotalGroups] = useState(0);
|
||||||
|
|
||||||
const updateGroups = (newGroups: Group[]) => {
|
const [groupPermissions, setGroupPermissions] = useState<pond.Permission[]>([])
|
||||||
setGroups(newGroups);
|
|
||||||
};
|
const groupID = useParams<{ groupID: string }>()?.groupID ?? "all";
|
||||||
|
const [tab, setTab] = useState(groupID==="all" ? groupID : groupID);
|
||||||
|
|
||||||
const [selectedGroup, setSelectedGroup] = useState<Group | undefined>(undefined);
|
const [selectedGroup, setSelectedGroup] = useState<Group | undefined>(undefined);
|
||||||
const [groupSettingsMode, setGroupSettingsMode] = useState<
|
const [groupSettingsMode, setGroupSettingsMode] = useState<
|
||||||
|
|
@ -98,8 +100,21 @@ export default function Devices() {
|
||||||
>(undefined);
|
>(undefined);
|
||||||
const [groupSettingsIsOpen, setGroupSettingsIsOpen] = useState<boolean>(false);
|
const [groupSettingsIsOpen, setGroupSettingsIsOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
const groupID = useParams<{ groupID: string }>()?.groupID ?? "all";
|
const updateGroups = (newGroups: Group[]) => {
|
||||||
const [tab, setTab] = useState(groupID==="all" ? groupID : groupID);
|
setGroups(newGroups);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setGroupPermissions([])
|
||||||
|
if (tab === "all") return
|
||||||
|
groupAPI.getGroupPermissions(parseInt(tab)).then(resp => {
|
||||||
|
setGroupPermissions(resp.data.permissions)
|
||||||
|
})
|
||||||
|
}, [tab])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(groupPermissions)
|
||||||
|
}, [groupPermissions])
|
||||||
|
|
||||||
const openProvisionDialog = () => {
|
const openProvisionDialog = () => {
|
||||||
setIsProvisionDialogOpen(true);
|
setIsProvisionDialogOpen(true);
|
||||||
|
|
@ -221,6 +236,10 @@ export default function Devices() {
|
||||||
loadGroups()
|
loadGroups()
|
||||||
}, [groupLimit, groupPage, orderGroup, orderGroupBy, searchGroup])
|
}, [groupLimit, groupPage, orderGroup, orderGroupBy, searchGroup])
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// permissionAPI.getPermissions
|
||||||
|
// }, [groupID])
|
||||||
|
|
||||||
const handleChange = (event: any) => {
|
const handleChange = (event: any) => {
|
||||||
setLimit(event.target.value);
|
setLimit(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
@ -377,7 +396,7 @@ export default function Devices() {
|
||||||
onRowClick={toDevice}
|
onRowClick={toDevice}
|
||||||
setSearchText={setSearch}
|
setSearchText={setSearch}
|
||||||
isLoading={devicesLoading}
|
isLoading={devicesLoading}
|
||||||
actions={getGroup() && <GroupActions group={getGroup()} permissions={[]} devices={devices} refreshCallback={loadGroups}/>}
|
actions={getGroup() && <GroupActions group={getGroup()} permissions={groupPermissions} devices={devices} refreshCallback={loadGroups}/>}
|
||||||
/>
|
/>
|
||||||
<ProvisionDevice
|
<ProvisionDevice
|
||||||
isOpen={isProvisionDialogOpen}
|
isOpen={isProvisionDialogOpen}
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,9 @@ export default function GroupPage() {
|
||||||
const [loadingDevices, setLoadingDevices] = useState(false)
|
const [loadingDevices, setLoadingDevices] = useState(false)
|
||||||
const [devices, setDevices] = useState<Device[]>([])
|
const [devices, setDevices] = useState<Device[]>([])
|
||||||
const [permissions, setPermissions] = useState<pond.Permission[]>([])
|
const [permissions, setPermissions] = useState<pond.Permission[]>([])
|
||||||
const [limit, setLimit] = useState(0)
|
const [limit, setLimit] = useState(10)
|
||||||
const [total, setTotal] = useState(0)
|
const [total, setTotal] = useState(0)
|
||||||
const [page, setPage] = useState(1)
|
const [page, setPage] = useState(0)
|
||||||
const [order, ] = useState<"asc" | "desc">("asc")
|
const [order, ] = useState<"asc" | "desc">("asc")
|
||||||
const [orderBy, ] = useState("")
|
const [orderBy, ] = useState("")
|
||||||
const [search, setSearch] = useState("")
|
const [search, setSearch] = useState("")
|
||||||
|
|
@ -103,7 +103,23 @@ export default function GroupPage() {
|
||||||
// }, [group, groupID])
|
// }, [group, groupID])
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const getKeys = () => {
|
||||||
|
let keys = getContextKeys()
|
||||||
|
keys.push(groupID.toString())
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTypes = () => {
|
||||||
|
let keys = getContextTypes()
|
||||||
|
keys.push("group")
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const loadDevices = () => {
|
const loadDevices = () => {
|
||||||
|
console.log(getContextKeys())
|
||||||
|
console.log(getContextTypes())
|
||||||
|
console.log(limit)
|
||||||
setLoadingDevices(true)
|
setLoadingDevices(true)
|
||||||
deviceAPI.list(
|
deviceAPI.list(
|
||||||
limit,
|
limit,
|
||||||
|
|
@ -117,9 +133,10 @@ export default function GroupPage() {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
getContextKeys(),
|
getKeys(),
|
||||||
getContextTypes()
|
getTypes()
|
||||||
).then(resp => {
|
).then(resp => {
|
||||||
|
console.log(resp.data)
|
||||||
let newDevices: Device[] = [];
|
let newDevices: Device[] = [];
|
||||||
resp.data.devices.forEach(device => {
|
resp.data.devices.forEach(device => {
|
||||||
newDevices.push(Device.create(device))
|
newDevices.push(Device.create(device))
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@ export interface IGroupAPIContext {
|
||||||
removeGroup: (id: number) => Promise<any>;
|
removeGroup: (id: number) => Promise<any>;
|
||||||
getGroup: (id: number) => Promise<any>;
|
getGroup: (id: number) => Promise<any>;
|
||||||
getGroupAndPermissions: (id: number) => Promise<AxiosResponse<pond.GetGroupAndPermissionsResponse>>;
|
getGroupAndPermissions: (id: number) => Promise<AxiosResponse<pond.GetGroupAndPermissionsResponse>>;
|
||||||
|
getGroupPermissions: (
|
||||||
|
id: number,
|
||||||
|
keys?: string[],
|
||||||
|
types?: string[],
|
||||||
|
) => Promise<AxiosResponse<pond.GetPermissionsResponse>>;
|
||||||
listGroups: (
|
listGroups: (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -100,6 +105,36 @@ export default function GroupProvider(props: PropsWithChildren<Props>) {
|
||||||
return get<pond.GetGroupAndPermissionsResponse>(pondURL(url));
|
return get<pond.GetGroupAndPermissionsResponse>(pondURL(url));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getGroupPermissions = (
|
||||||
|
id: number,
|
||||||
|
keys?: string[],
|
||||||
|
types?: string[],
|
||||||
|
) => {
|
||||||
|
keys = keys ? keys : getContextKeys();
|
||||||
|
types = types? types : getContextTypes();
|
||||||
|
let url = "/groupPermissions/" + id
|
||||||
|
if (as) {
|
||||||
|
url = url + "?as=" + as +
|
||||||
|
+
|
||||||
|
(keys ? "?keys=" + keys.toString() : "") +
|
||||||
|
(types ? "&types=" + types.toString() : "")
|
||||||
|
} else {
|
||||||
|
url = url +
|
||||||
|
(keys ? "?keys=" + keys.toString() : "") +
|
||||||
|
(types ? "&types=" + types.toString() : "")
|
||||||
|
}
|
||||||
|
return new Promise<AxiosResponse<pond.GetPermissionsResponse>>((resolve, reject) => {
|
||||||
|
get<pond.GetPermissionsResponse>(pondURL(url)).then(resp => {
|
||||||
|
console.log(resp.data)
|
||||||
|
resp.data = pond.GetPermissionsResponse.fromObject(resp.data)
|
||||||
|
return resolve(resp);
|
||||||
|
}).catch(err => {
|
||||||
|
return reject(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// return get<pond.GetPermissionsResponse>(pondURL(url));
|
||||||
|
};
|
||||||
|
|
||||||
const listGroups = (
|
const listGroups = (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -174,6 +209,7 @@ export default function GroupProvider(props: PropsWithChildren<Props>) {
|
||||||
updateGroup,
|
updateGroup,
|
||||||
removeGroup,
|
removeGroup,
|
||||||
getGroup,
|
getGroup,
|
||||||
|
getGroupPermissions,
|
||||||
getGroupAndPermissions,
|
getGroupAndPermissions,
|
||||||
listGroups,
|
listGroups,
|
||||||
listGroupDevices,
|
listGroupDevices,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue