Updating jira server/dc user from plugin

Hi,

It is possible to create a jira user from within jira plugin, similar to what is being done in the below

 ApplicationUser loggedInUser = authenticationContext.getLoggedInUser();
        UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest.withUserDetails(loggedInUser, "serviceUser", password, "support@example.com", "Jira Server Plugin");
        UserService.CreateUserValidationResult validationResult = userService.validateCreateUser(createUserRequest);
        Collection<String> errorMessages = validationResult.getErrorCollection().getErrorMessages();
        for (String errorMessage : errorMessages) {
            log.error("validation error creating user: " + errorMessage);
        }

because the permissions check can be supressed, with -

createUserRequest = createUserRequest.performPermissionCheck(false);

It doesn’t look as though a user can be updated from within plugin at all though, as i’m not seeing any such method for stopping the permissions check when updating a user…

e.g. updating a user

updatedUser = UserService.newUserBuilder(appUser).active(true).emailAddress(cEmail).build();
        log.debug("validating UpdateUserValidationResult - " + updatedUser);
        UpdateUserValidationResult result = userService.validateUpdateUser(updatedUser);

        if (result.isValid()) {
            log.debug("Re-activating user: " + appUser.getName());
            userService.updateUser(result);

When attempting to update a user, I recieve a permissions error, ‘Error in validation of CreateUserRequest : You do not have the permission to update users.’

Is anyone aware of any way around this? Its a bit strange that it exists when creating a user, but not on updating.

Thanks

1 Like

I’m also looking for a solution to this.

I’m implementing a ScriptRunner REST endpoint that allows a user to be updated, and running into updateUserValidation failure for the same reason as OP (“You do not have permission to update users.”)

Anyone else run into this and came up with a solution/workaround?

Thanks,
Kamran