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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

snoesberger
Copy link
Contributor

fix #1239

This fix ensures that only directly assigned roles are displayed in the roles tab of the user modal.

@snoesberger snoesberger added the type:usability Improves the UX label May 13, 2025
Copy link
Contributor

Use docker or podman to test this pull request locally.

Run test server using develop.opencast.org as backend:

podman run --rm -it -p 127.0.0.1:3000:3000 ghcr.io/opencast/opencast-admin-interface:pr-1251

Specify a different backend like stable.opencast.org:

podman run --rm -it -p 127.0.0.1:3000:3000 -e PROXY_TARGET=https://stable.opencast.org ghcr.io/opencast/opencast-admin-interface:pr-1251

It may take a few seconds for the interface to spin up.
It will then be available at http://127.0.0.1:3000.
For more options you can pass on to the proxy, take a look at the README.md.

Copy link
Contributor

github-actions bot commented May 13, 2025

This pull request is deployed at test.admin-interface.opencast.org/1251/2025-05-15_09-02-05/ .
It might take a few minutes for it to become available.

@Arnei Arnei self-requested a review May 14, 2025 08:38
Copy link
Member

@Arnei Arnei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, but I would like to see the filtering happen outside the SelectContainer component. Imo it is the task of the calling components to provide the correct data.

Did you test this with users with many roles (upwards of a thousand)? Is it performant?

@snoesberger snoesberger force-pushed the 1239-fix-user-roles-effectiveRoles branch from adbe9a9 to ef618cc Compare May 14, 2025 13:32
Not only assigned but also derived roles were display in the "Roles" tab
of the user modal.
@snoesberger snoesberger force-pushed the 1239-fix-user-roles-effectiveRoles branch from ef618cc to 8c2c112 Compare May 14, 2025 13:35
@snoesberger
Copy link
Contributor Author

Thanks for the review @Arnei. I did address your suggestions and did move the filtering to the UserDetails component. Code is ready for an other review.

@snoesberger snoesberger requested a review from Arnei May 14, 2025 13:55
Copy link
Member

@Arnei Arnei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I click on "Add user" and click on the "Roles" tab in the "Create new user" modal, the ui breaks (white screen).

@@ -58,8 +60,16 @@ const UserDetails: React.FC<{
setPage(tabNr);
};

const handleSubmit = (values: UpdateUser) => {
dispatch(updateUserDetails({values: values, username: userDetails.username}));
const handleSubmit = (values: any) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!any! Please specify a type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added type for values in my most recent commits.

As with the user details view, we also need to provide the assignedRoles
attribute in the New User dialogue.
@snoesberger
Copy link
Contributor Author

If I click on "Add user" and click on the "Roles" tab in the "Create new user" modal, the ui breaks (white screen).

Since the new user dialog also uses the SelectContainer, I had to add the assignedRoles attribute to the NewUserWizard as well. Now, creating a new user and assigning roles simultaneously is working again.

@snoesberger snoesberger requested a review from Arnei May 15, 2025 09:09
Comment on lines +65 to +77
const handleSubmit = (values: {
status?: 'uninitialized' | 'loading' | 'succeeded' | 'failed',
error?: SerializedError | null,
provider?: string,
roles?: UserRole[],
name?: string,
username: string,
email?: string,
manageable?: boolean,
assignedRoles?: UserRole[],
password?: string,
passwordConfirmation?: string,
}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are specifying way more properties than handleSubmit is using. You only need to specify the properties that are actually used (in this case email, name, username, assignedRoles, password). Specifying more properties may confuse future developers that try figure out what is going on.

Same in NewUserWizard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure about that. I took all the attributes that are part of the initialValues. I thought it is possible to get all these attributes when submitting.
How can I find out which attributes I get from onSubmit then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not important which values handleSubmit could get from onSubmit, it is important which values it actually makes use of. As a general rule, a function should not define taking a value if that value is never used.

How can I find out which attributes I get from onSubmit then?

You cannot, not really, because Formik is not that keen on type safety. I find it to be good practice to define a complete initial state, so that you can reasonably assume to get an object with the same values in onSubmit.

@Arnei
Copy link
Member

Arnei commented May 15, 2025

Everything else is looking fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:usability Improves the UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In the user modal, the "Roles" and "Effective Roles" tabs display the same information.
2 participants