updated get permissions to take in the keys and types to get the correct permissions using the context chain

This commit is contained in:
csawatzky 2026-03-18 14:38:25 -06:00
parent 2c28588861
commit d3a5c24741
2 changed files with 16 additions and 17 deletions

View file

@ -3,7 +3,7 @@ import { Gate as IGate } from "models/Gate";
//import { Redirect, useHistory, useRouteMatch } from "react-router";
import React, { useCallback, useEffect, useState } from "react";
import PageContainer from "./PageContainer";
import { useGlobalState, useGateAPI, useUserAPI } from "providers";
import { useGlobalState, useGateAPI } from "providers";
import {
Box,
ButtonBase,
@ -20,7 +20,7 @@ import {
} from "@mui/material";
import { pond } from "protobuf-ts/pond";
import DeviceLinkDrawer from "common/DeviceLinkDrawer";
import { Component, Device, Scope } from "models";
import { Component, Device } from "models";
import GateActions from "gate/GateActions";
import GateDevice from "gate/GateDevice";
import ObjectControls from "common/ObjectControls";
@ -28,7 +28,7 @@ import { Link } from "@mui/icons-material";
import Chat from "chat/Chat";
import PlaneIcon from "products/AviationIcons/PlaneIcon";
import NotesIcon from "@mui/icons-material/Notes";
import { useMobile, useSnackbar, useThemeType } from "hooks";
import { useMobile, usePermissionAPI, useSnackbar, useThemeType } from "hooks";
import { clone } from "lodash";
import { useNavigate, useParams } from "react-router-dom";
import { makeStyles } from "@mui/styles";
@ -90,7 +90,7 @@ export default function Gate(props: Props) {
const gateID = gateKey ?? useParams<{ gateKey: string }>()?.gateKey ?? "";
const classes = useStyles();
const gateAPI = useGateAPI();
const userAPI = useUserAPI();
const permissionAPI = usePermissionAPI();
const [gate, setGate] = useState<IGate>(IGate.create());
const [devices, setDevices] = useState<Map<string, pond.ComprehensiveDevice>>(
new Map<string, pond.ComprehensiveDevice>()
@ -115,16 +115,10 @@ export default function Gate(props: Props) {
};
useEffect(() => {
let key = gateID;
let kind = "gate";
if (as) {
key = as;
kind = "team";
}
userAPI.getUser(user.id(), { key: key, kind: kind } as Scope).then(resp => {
setPermissions(resp.permissions);
});
}, [as, gateID, userAPI, user]);
permissionAPI.getPermissions(user.id(), [gateID], ["gate"]).then(resp => {
setPermissions(pond.EvaluatePermissionsResponse.fromObject(resp.data).permissions)
})
}, [as, gateID, permissionAPI, user]);
const loadGate = useCallback(() => {
let id = gateID;