Skip to content
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

Can't remove users's roles from user dialog #4143

Open
kainio opened this issue Jul 12, 2024 · 1 comment
Open

Can't remove users's roles from user dialog #4143

kainio opened this issue Jul 12, 2024 · 1 comment

Comments

@kainio
Copy link

kainio commented Jul 12, 2024

Describe the bug
In the user dialog, when trying to delete a role or more from a user, the change didn't apply.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Users view in the Security perspective
  2. Click on Edit user
  3. A User dialog will popup, try editing the roles of the user by removing (a) role(s)
  4. Click on save

Expected behavior
The unselected roles should be removed from the user's roles

Desktop:

  • OS: Windows
  • Browser chrome
  • Version 126

Additional context
Using dirigible 10.6.13

@kainio kainio changed the title Can't change user roles from dropdown list on user dialog Can't remove users's roles from user dialog Jul 12, 2024
@kainio
Copy link
Author

kainio commented Jul 12, 2024

I think the way it is implemented doesn't take into account to remove unselected roles:

   /**
     * Updates the user.
     *
     * @param id the id of the user
     * @param userParameter the user parameter
     * @return the response entity
     * @throws URISyntaxException the URI syntax exception
     */
    @PutMapping("{id}")
    public ResponseEntity<URI> updateUser(@PathVariable("id") String id, @Valid @RequestBody UserParameter userParameter)
            throws URISyntaxException {
        User user = userService.updateUser(id, userParameter.getUsername(), userParameter.getPassword(), userParameter.getTenant());
        userService.assignUserRolesByIds(user, userParameter.getRoles());
        return ResponseEntity.created(new URI(BaseEndpoint.PREFIX_ENDPOINT_SECURITY + "users/" + user.getId()))
                             .build();
    }
   public void assignUserRolesByIds(User user, Long[] roleIds) {
        for (Long roleId : roleIds) {
            Role role = roleService.findById(roleId);
            UserRoleAssignment assignment = new UserRoleAssignment();
            assignment.setUser(user);
            assignment.setRole(role);
            if (!assignmentRepository.findByUserAndRole(user, role)
                                     .isPresent()) {
                assignmentRepository.save(assignment);
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant