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

View File

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

View File

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