Skip to content

Commit 6c75239

Browse files
authored
Display only directly assigned roles in user modal (#1251)
* Display only directly assigned roles in user modal Not only assigned but also derived roles were display in the "Roles" tab of the user modal. * Fix 'any' type and remove leftover comment * Also fix the user roles in the create user dialogue As with the user details view, we also need to provide the assignedRoles attribute in the New User dialogue. * Only define the necessary attributes for the user handleSubmit. Reduce the attributes of handleSubmit when updating or creating a user.
1 parent 0ef62f4 commit 6c75239

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/components/shared/wizard/SelectContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ const SelectContainer = ({
264264
onChange={(e) => handleChangeRemove(e)}
265265
value={markedForRemoval}
266266
>
267-
{/* @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type. */}
267+
{/* @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type. */}
268268
{selectedItems.map((item, key) => (
269269
<option key={key} value={item.name}>
270270
{item.name}

src/components/users/partials/modal/UserDetails.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { useAppDispatch, useAppSelector } from "../../../../store";
1010
import { UpdateUser, updateUserDetails } from "../../../../slices/userDetailsSlice";
1111
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
1212
import { ParseKeys } from "i18next";
13+
import { UserRole } from "../../../../slices/userSlice";
14+
import { SerializedError } from "@reduxjs/toolkit";
1315

1416
/**
1517
* This component manages the pages of the user details
@@ -24,9 +26,11 @@ const UserDetails: React.FC<{
2426
const [page, setPage] = useState(0);
2527

2628
const userDetails = useAppSelector(state => getUserDetails(state));
29+
const assignedRoles = userDetails.roles.filter(role => role.type === "GROUP" || role.type === "INTERNAL");
2730

2831
const initialValues = {
2932
...userDetails,
33+
assignedRoles,
3034
password: "",
3135
passwordConfirmation: "",
3236
};
@@ -58,8 +62,23 @@ const UserDetails: React.FC<{
5862
setPage(tabNr);
5963
};
6064

61-
const handleSubmit = (values: UpdateUser) => {
62-
dispatch(updateUserDetails({values: values, username: userDetails.username}));
65+
const handleSubmit = (values: {
66+
username: string,
67+
name?: string,
68+
email?: string,
69+
password?: string,
70+
roles?: UserRole[],
71+
assignedRoles?: UserRole[],
72+
}) => {
73+
const newValues: UpdateUser = {
74+
username: values.username,
75+
name: values.name,
76+
email: values.email,
77+
password: values.password,
78+
roles: values.assignedRoles,
79+
};
80+
81+
dispatch(updateUserDetails({values: newValues, username: userDetails.username}));
6382
close();
6483
};
6584

src/components/users/partials/wizard/NewUserWizard.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import UserRolesTab from "./UserRolesTab";
77
import { initialFormValuesNewUser } from "../../../../configs/modalConfig";
88
import { getUsernames } from "../../../../selectors/userSelectors";
99
import { NewUserSchema } from "../../../../utils/validate";
10-
import { NewUser, postNewUser } from "../../../../slices/userSlice";
10+
import { NewUser, postNewUser, UserRole } from "../../../../slices/userSlice";
1111
import { useAppDispatch, useAppSelector } from "../../../../store";
1212
import ButtonLikeAnchor from "../../../shared/ButtonLikeAnchor";
1313
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
14+
import { Role } from "../../../../slices/aclSlice";
1415

1516
/**
1617
* This component renders the new user wizard
@@ -37,8 +38,22 @@ const NewUserWizard = ({
3738
setTab(tabNr);
3839
};
3940

40-
const handleSubmit = (values: NewUser) => {
41-
const response = dispatch(postNewUser(values));
41+
const handleSubmit = (values: {
42+
username: string,
43+
name: string,
44+
email: string,
45+
password: string,
46+
roles: Role[],
47+
assignedRoles: UserRole[],
48+
}) => {
49+
const newValues: NewUser = {
50+
username: values.username,
51+
name: values.name,
52+
email: values.email,
53+
password: values.password,
54+
roles: values.assignedRoles,
55+
}
56+
const response = dispatch(postNewUser(newValues));
4257
console.info(response);
4358
close();
4459
};

src/components/users/partials/wizard/UserRolesTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const UserRolesTab = <T extends RequiredFormProps>({
5454
label: "USERS.USERS.DETAILS.ROLES",
5555
items: roles,
5656
}}
57-
formikField="roles"
57+
formikField="assignedRoles"
5858
manageable={formik.values.manageable}
5959
/>
6060
)}

src/configs/modalConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initArray } from "../utils/utils";
66
import { EditedEvents, Event, UploadAssetsTrack } from "../slices/eventSlice";
77
import { Role } from "../slices/aclSlice";
88
import { ParseKeys } from "i18next";
9+
import { UserRole } from "../slices/userSlice";
910

1011
// Context for notifications shown in modals
1112
export const NOTIFICATION_CONTEXT = "modal-form";
@@ -182,6 +183,7 @@ export const initialFormValuesNewUser: {
182183
password: string,
183184
passwordConfirmation: string,
184185
roles: Role[],
186+
assignedRoles: UserRole[],
185187
manageable: boolean,
186188
} = {
187189
username: "",
@@ -190,6 +192,7 @@ export const initialFormValuesNewUser: {
190192
password: "",
191193
passwordConfirmation: "",
192194
roles: [],
195+
assignedRoles: [],
193196
manageable: true,
194197
};
195198

0 commit comments

Comments
 (0)