Skip to content

Display only directly assigned roles in user modal #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/shared/wizard/SelectContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const SelectContainer = ({
onChange={(e) => handleChangeRemove(e)}
value={markedForRemoval}
>
{/* @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type. */}
{/* @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type. */}
{selectedItems.map((item, key) => (
<option key={key} value={item.name}>
{item.name}
Expand Down
23 changes: 21 additions & 2 deletions src/components/users/partials/modal/UserDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useAppDispatch, useAppSelector } from "../../../../store";
import { UpdateUser, updateUserDetails } from "../../../../slices/userDetailsSlice";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
import { ParseKeys } from "i18next";
import { UserRole } from "../../../../slices/userSlice";
import { SerializedError } from "@reduxjs/toolkit";

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

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

const initialValues = {
...userDetails,
assignedRoles,
password: "",
passwordConfirmation: "",
};
Expand Down Expand Up @@ -58,8 +62,23 @@ const UserDetails: React.FC<{
setPage(tabNr);
};

const handleSubmit = (values: UpdateUser) => {
dispatch(updateUserDetails({values: values, username: userDetails.username}));
const handleSubmit = (values: {
username: string,
name?: string,
email?: string,
password?: string,
roles?: UserRole[],
assignedRoles?: UserRole[],
}) => {
const newValues: UpdateUser = {
username: values.username,
name: values.name,
email: values.email,
password: values.password,
roles: values.assignedRoles,
};

dispatch(updateUserDetails({values: newValues, username: userDetails.username}));
close();
};

Expand Down
21 changes: 18 additions & 3 deletions src/components/users/partials/wizard/NewUserWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import UserRolesTab from "./UserRolesTab";
import { initialFormValuesNewUser } from "../../../../configs/modalConfig";
import { getUsernames } from "../../../../selectors/userSelectors";
import { NewUserSchema } from "../../../../utils/validate";
import { NewUser, postNewUser } from "../../../../slices/userSlice";
import { NewUser, postNewUser, UserRole } from "../../../../slices/userSlice";
import { useAppDispatch, useAppSelector } from "../../../../store";
import ButtonLikeAnchor from "../../../shared/ButtonLikeAnchor";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
import { Role } from "../../../../slices/aclSlice";

/**
* This component renders the new user wizard
Expand All @@ -37,8 +38,22 @@ const NewUserWizard = ({
setTab(tabNr);
};

const handleSubmit = (values: NewUser) => {
const response = dispatch(postNewUser(values));
const handleSubmit = (values: {
username: string,
name: string,
email: string,
password: string,
roles: Role[],
assignedRoles: UserRole[],
}) => {
const newValues: NewUser = {
username: values.username,
name: values.name,
email: values.email,
password: values.password,
roles: values.assignedRoles,
}
const response = dispatch(postNewUser(newValues));
console.info(response);
close();
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/users/partials/wizard/UserRolesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const UserRolesTab = <T extends RequiredFormProps>({
label: "USERS.USERS.DETAILS.ROLES",
items: roles,
}}
formikField="roles"
formikField="assignedRoles"
manageable={formik.values.manageable}
/>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/configs/modalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initArray } from "../utils/utils";
import { EditedEvents, Event, UploadAssetsTrack } from "../slices/eventSlice";
import { Role } from "../slices/aclSlice";
import { ParseKeys } from "i18next";
import { UserRole } from "../slices/userSlice";

// Context for notifications shown in modals
export const NOTIFICATION_CONTEXT = "modal-form";
Expand Down Expand Up @@ -182,6 +183,7 @@ export const initialFormValuesNewUser: {
password: string,
passwordConfirmation: string,
roles: Role[],
assignedRoles: UserRole[],
manageable: boolean,
} = {
username: "",
Expand All @@ -190,6 +192,7 @@ export const initialFormValuesNewUser: {
password: "",
passwordConfirmation: "",
roles: [],
assignedRoles: [],
manageable: true,
};

Expand Down
Loading