permission check
parent
1029e6ebd6
commit
2b199cd15c
|
@ -254,7 +254,7 @@ export default function AppRoutes() {
|
|||
|
||||
{hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.VIEW
|
||||
) && (
|
||||
<Route
|
||||
path={Constants.ROUTE_PATHS.ROBOTICS_ROBOTS}
|
||||
|
|
|
@ -153,7 +153,7 @@ export default function SideMenu({
|
|||
if (
|
||||
hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.VIEW
|
||||
)
|
||||
) {
|
||||
let roboticsGroup = {
|
||||
|
|
|
@ -15,6 +15,8 @@ import { useEffect, useRef, useState } from "react";
|
|||
import {
|
||||
Constants,
|
||||
FormatDatetime,
|
||||
hasOnePermission,
|
||||
hasPermission,
|
||||
myFetch,
|
||||
myFetchContentType,
|
||||
} from "../../../utils";
|
||||
|
@ -26,6 +28,7 @@ import {
|
|||
PlusOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { MyCopyIcon, MyShowHiddenIcon } from "../../../Components/MyIcon";
|
||||
import { useAppContext } from "../../../Contexts/AppContext";
|
||||
|
||||
const ReceivedSSECommands = {
|
||||
UpdateRobotStatus: 1,
|
||||
|
@ -52,6 +55,7 @@ function getRobotTypeString(type) {
|
|||
|
||||
export default function Robots() {
|
||||
const { t } = useTranslation();
|
||||
const appContext = useAppContext();
|
||||
const [notificationApi, notificationContextHolder] =
|
||||
notification.useNotification();
|
||||
|
||||
|
@ -162,7 +166,15 @@ export default function Robots() {
|
|||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
];
|
||||
|
||||
if (
|
||||
hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.VIEW_ROBOTS_ADDRESSES
|
||||
)
|
||||
) {
|
||||
items.push({
|
||||
title: t("robotics.robots.column.address"),
|
||||
dataIndex: "address",
|
||||
key: "address",
|
||||
|
@ -178,7 +190,10 @@ export default function Robots() {
|
|||
<MyCopyIcon notificationApi={notificationApi} text={text} />
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
items.push(
|
||||
{
|
||||
title: t("robotics.robots.column.connectedAt"),
|
||||
dataIndex: "connectedAt",
|
||||
|
@ -193,88 +208,107 @@ export default function Robots() {
|
|||
title: t("robotics.robots.column.createdAt"),
|
||||
dataIndex: "createdAt",
|
||||
key: "createdAt",
|
||||
},
|
||||
{
|
||||
}
|
||||
);
|
||||
|
||||
if (
|
||||
hasOnePermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.EDIT_ROBOT_NAME,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.DISCONNECT_ROBOT
|
||||
)
|
||||
) {
|
||||
items.push({
|
||||
title: t("robotics.robots.column.actions"),
|
||||
dataIndex: "actions",
|
||||
key: "actions",
|
||||
render: (_, record) => (
|
||||
<Space size="middle">
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title={t("robotics.robots.popconfirmEdit.title")}
|
||||
description={
|
||||
<Input
|
||||
placeholder="Name"
|
||||
value={selectedRobotName}
|
||||
onChange={(e) => setSelectedRobotName(e.target.value)}
|
||||
maxLength={Constants.GLOBALS.MAX_ROBOTICS_ROBOT_NAME_LENGTH}
|
||||
/>
|
||||
}
|
||||
okButtonProps={{
|
||||
disabled:
|
||||
selectedRobotName.length <
|
||||
Constants.GLOBALS.MIN_ROBOTICS_ROBOT_NAME_LENGTH ||
|
||||
selectedRobotName.length >
|
||||
Constants.GLOBALS.MAX_ROBOTICS_ROBOT_NAME_LENGTH,
|
||||
}}
|
||||
okText={t("common.button.confirm")}
|
||||
cancelText={t("common.button.cancel")}
|
||||
onConfirm={() =>
|
||||
myFetch(
|
||||
`/robot`,
|
||||
"PATCH",
|
||||
{
|
||||
robotId: record.id,
|
||||
robotName: selectedRobotName,
|
||||
},
|
||||
{},
|
||||
myFetchContentType.JSON,
|
||||
Constants.ROBOTICS_API_ADDRESS
|
||||
).catch((err) => {
|
||||
if (err === 422) {
|
||||
notificationApi["error"]({
|
||||
message: t(
|
||||
"robotics.robots.popconfirmEdit.errorNotification.message"
|
||||
),
|
||||
description: t(
|
||||
"robotics.robots.popconfirmEdit.errorNotification.description"
|
||||
),
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
>
|
||||
<Link to="#" onClick={() => setSelectedRobotName(record.name)}>
|
||||
{t("common.text.edit")}
|
||||
</Link>
|
||||
</Popconfirm>
|
||||
{hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.EDIT_ROBOT_NAME
|
||||
) && (
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title={t("robotics.robots.popconfirmEdit.title")}
|
||||
description={
|
||||
<Input
|
||||
placeholder="Name"
|
||||
value={selectedRobotName}
|
||||
onChange={(e) => setSelectedRobotName(e.target.value)}
|
||||
maxLength={Constants.GLOBALS.MAX_ROBOTICS_ROBOT_NAME_LENGTH}
|
||||
/>
|
||||
}
|
||||
okButtonProps={{
|
||||
disabled:
|
||||
selectedRobotName.length <
|
||||
Constants.GLOBALS.MIN_ROBOTICS_ROBOT_NAME_LENGTH ||
|
||||
selectedRobotName.length >
|
||||
Constants.GLOBALS.MAX_ROBOTICS_ROBOT_NAME_LENGTH,
|
||||
}}
|
||||
okText={t("common.button.confirm")}
|
||||
cancelText={t("common.button.cancel")}
|
||||
onConfirm={() =>
|
||||
myFetch(
|
||||
`/robot`,
|
||||
"PATCH",
|
||||
{
|
||||
robotId: record.id,
|
||||
robotName: selectedRobotName,
|
||||
},
|
||||
{},
|
||||
myFetchContentType.JSON,
|
||||
Constants.ROBOTICS_API_ADDRESS
|
||||
).catch((err) => {
|
||||
if (err === 422) {
|
||||
notificationApi["error"]({
|
||||
message: t(
|
||||
"robotics.robots.popconfirmEdit.errorNotification.message"
|
||||
),
|
||||
description: t(
|
||||
"robotics.robots.popconfirmEdit.errorNotification.description"
|
||||
),
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
>
|
||||
<Link to="#" onClick={() => setSelectedRobotName(record.name)}>
|
||||
{t("common.text.edit")}
|
||||
</Link>
|
||||
</Popconfirm>
|
||||
)}
|
||||
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title={t("robotics.robots.popconfirmDisconnect.title")}
|
||||
description={t(
|
||||
"robotics.robots.popconfirmDisconnect.description"
|
||||
)}
|
||||
okText={t("common.button.confirm")}
|
||||
cancelText={t("common.button.cancel")}
|
||||
onConfirm={() =>
|
||||
myFetch(
|
||||
`/robot/${record.id}`,
|
||||
"DELETE",
|
||||
null,
|
||||
{},
|
||||
myFetchContentType.JSON,
|
||||
Constants.ROBOTICS_API_ADDRESS
|
||||
)
|
||||
}
|
||||
>
|
||||
<Link to="#">{t("common.text.disconnect")}</Link>
|
||||
</Popconfirm>
|
||||
{hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.DISCONNECT_ROBOT
|
||||
) && (
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title={t("robotics.robots.popconfirmDisconnect.title")}
|
||||
description={t(
|
||||
"robotics.robots.popconfirmDisconnect.description"
|
||||
)}
|
||||
okText={t("common.button.confirm")}
|
||||
cancelText={t("common.button.cancel")}
|
||||
onConfirm={() =>
|
||||
myFetch(
|
||||
`/robot/${record.id}`,
|
||||
"DELETE",
|
||||
null,
|
||||
{},
|
||||
myFetchContentType.JSON,
|
||||
Constants.ROBOTICS_API_ADDRESS
|
||||
)
|
||||
}
|
||||
>
|
||||
<Link to="#">{t("common.text.disconnect")}</Link>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
@ -335,7 +369,15 @@ export default function Robots() {
|
|||
dataIndex: "firmwareVersion",
|
||||
key: "firmwareVersion",
|
||||
},
|
||||
{
|
||||
];
|
||||
|
||||
if (
|
||||
hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.AUTHORIZE_DENY_UNAUTHORIZED_ROBOTS
|
||||
)
|
||||
) {
|
||||
items.push({
|
||||
title: t("robotics.robots.column.actions"),
|
||||
dataIndex: "actions",
|
||||
key: "actions",
|
||||
|
@ -386,8 +428,8 @@ export default function Robots() {
|
|||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
@ -689,6 +731,12 @@ export default function Robots() {
|
|||
</Typography.Title>
|
||||
|
||||
<Button
|
||||
disabled={
|
||||
!hasPermission(
|
||||
appContext.userPermissions,
|
||||
Constants.PERMISSIONS.ROBOTICS.ROBOTS.ENABLE_PERMIT_JOIN
|
||||
)
|
||||
}
|
||||
onClick={() => {
|
||||
console.log("click");
|
||||
myFetch(
|
||||
|
|
10
src/utils.js
10
src/utils.js
|
@ -179,7 +179,15 @@ export const Constants = {
|
|||
VIEW: "consoles.view",
|
||||
},
|
||||
ROBOTICS: {
|
||||
ROBOTS: "robotics.view",
|
||||
ROBOTS: {
|
||||
VIEW: "robotics.robots.view",
|
||||
VIEW_ROBOTS_ADDRESSES: "robotics.robots.view_robots_addresses",
|
||||
EDIT_ROBOT_NAME: "robotics.robots.edit_robot_name",
|
||||
DISCONNECT_ROBOT: "robotics.robots.disconnect_robot",
|
||||
ENABLE_PERMIT_JOIN: "robotics.robots.enable_permit_join",
|
||||
AUTHORIZE_DENY_UNAUTHORIZED_ROBOTS:
|
||||
"robotics.robots.authorize_deny_unauthorized_robots",
|
||||
},
|
||||
},
|
||||
},
|
||||
SYSTEM_LOG_TYPE: {
|
||||
|
|
Loading…
Reference in New Issue