permission handling

main
alex 2023-06-24 22:01:40 +02:00
parent 7300a0e107
commit cc743395f3
5 changed files with 86 additions and 67 deletions

View File

@ -370,32 +370,34 @@ function Role({ treeData, role, webSocketContext, notificationApi }) {
{hasPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.ADMIN_AREA.ROLES.DELETE_ROLE
) ? (
role.Master || getUsersInRole().length > 0 ? (
<DeleteOutlined
style={{
color: "rgba(0, 0, 0, 0.25)",
cursor: "not-allowed",
}}
/>
) : (
<Popconfirm
title="Delete role"
description="Are you sure to delete this role?"
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
onConfirm={() => onDeleteClick()}
>
<Tooltip title="Delete">
<DeleteOutlined />
</Tooltip>
</Popconfirm>
)
) : null}
) && (
<>
{role.Master || getUsersInRole().length > 0 ? (
<DeleteOutlined
style={{
color: "rgba(0, 0, 0, 0.25)",
cursor: "not-allowed",
}}
/>
) : (
<Popconfirm
title="Delete role"
description="Are you sure to delete this role?"
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
onConfirm={() => onDeleteClick()}
>
<Tooltip title="Delete">
<DeleteOutlined />
</Tooltip>
</Popconfirm>
)}
</>
)}
{hasPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.ADMIN_AREA.ROLES.MOVE_ROLE_UP_DOWN
) ? (
) && (
<>
{role.SortingOrder === 0 ? (
<ArrowUpOutlined
@ -422,7 +424,7 @@ function Role({ treeData, role, webSocketContext, notificationApi }) {
</Tooltip>
)}
</>
) : null}
)}
{hasPermission(
webSocketContext.User.Permissions,
@ -432,6 +434,7 @@ function Role({ treeData, role, webSocketContext, notificationApi }) {
<SaveOutlined onClick={() => onSaveClick()} />
</Tooltip>
)}
<Tooltip title="Close">
<CloseOutlined onClick={() => onCloseClick()} />
</Tooltip>

View File

@ -113,7 +113,9 @@ export default function AllUsers() {
let items = [];
webSocketContext.AllUsers.sort(
(a, b) => b.ConnectionStatus - a.ConnectionStatus
(a, b) =>
webSocketContext.AllRoles.find((r) => r.Id === a.RoleId).SortingOrder -
webSocketContext.AllRoles.find((r) => r.Id === b.RoleId).SortingOrder
);
webSocketContext.AllUsers.forEach((user) => {

View File

@ -156,49 +156,49 @@ export default function GroupTaskTableList({
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYNewTask,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYReloadGroupConfig
) && (
<div
style={{
marginBottom: 16,
display: "flex",
justifyContent: hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYNewTask,
categoryGroup.category
)
? "space-between"
: "right",
}}
>
{hasXYPermission(
<div
style={{
marginBottom: 16,
display: "flex",
justifyContent: hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYNewTask,
categoryGroup.category
) && (
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => showGroupTypeSelectionModal(categoryGroup)}
>
New task
</Button>
)}
)
? "space-between"
: "right",
}}
>
{hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYNewTask,
categoryGroup.category
) && (
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => showGroupTypeSelectionModal(categoryGroup)}
>
New task
</Button>
)}
{hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYReloadGroupConfig,
categoryGroup.category
) && (
<Popconfirm
placement="left"
title="Are you sure you want to reload the group configs?"
okText="Yes"
onConfirm={() => handleOnConfirm(categoryGroup.category)}
>
<Button icon={<ReloadOutlined />}>Reload</Button>
</Popconfirm>
)}
</div>
)}
{hasXYPermission(
webSocketContext.User.Permissions,
Constants.PERMISSIONS.GROUP_TASKS.OVERVIEW.XYReloadGroupConfig,
categoryGroup.category
) && (
<Popconfirm
placement="left"
title="Are you sure you want to reload the group configs?"
okText="Yes"
onConfirm={() => handleOnConfirm(categoryGroup.category)}
>
<Button icon={<ReloadOutlined />}>Reload</Button>
</Popconfirm>
)}
</div>
)}
<Table columns={columns} dataSource={getTableItems()} />
</>

View File

@ -41,6 +41,17 @@ export default function GroupTasks({ isGroupTasksViewModalOpen }) {
}
});
if (items.length === 0) {
items.push(
<Result
key="result"
status="403"
title="You were not assigned to any group tasks"
subTitle="Please contact an administrator"
/>
);
}
return items;
};

View File

@ -172,6 +172,7 @@ const ReceivedMessagesCommands = {
AdminAreaRoleDeleted: 22,
UserRoleUpdated: 23,
RolePermissionsUpdated: 24,
ErrorNoPermissions: 25,
};
// commands sent to the backend server
@ -736,8 +737,6 @@ export function WebSocketProvider({
setUser((user) => {
const updatedUser = { ...user };
console.log("before update", updatedUser.Permissions);
if (body.AddedPermissions !== undefined) {
updatedUser.Permissions = updatedUser.Permissions.concat(
body.AddedPermissions
@ -750,12 +749,16 @@ export function WebSocketProvider({
);
}
console.log("updatedUser", updatedUser.Permissions);
return updatedUser;
});
}
break;
case ReceivedMessagesCommands.ErrorNoPermissions:
notificationApi["error"]({
message: `No permissions`,
description: `Please contact the administrator`,
});
break;
default:
console.error("unknown command", cmd);