Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how can I edit the email adress of a confluence user?

Deleted user June 10, 2012

I need to modifiy email adresses of confluence users. It is possible via soap api and it is possible in confluence itself so I guess it should be possible within a confluence plugin.

My first Approach was to utilize the UserDetailsManager which sets other properties but there is no property key for the email adress.fter digging in the apidoc I stumbled over the PersonalInformationManager. I've tried to set the email adress with the following code but it does absolutely nothing:

PersonalInformation oldInfo = personalInformationManager.getPersonalInformation(user);
            PersonalInformation newInfo = new PersonalInformation();
            newInfo.setUsername(user.getName());
            newInfo.setEmail("bla@blub.com");
            newInfo.setFullName(oldInfo.getFullName());
            personalInformationManager.savePersonalInformation(newInfo, oldInfo);

Any ideas?

Thanks in advance,

Lars

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2012

Hi Lars,

It's a bit confusing - you need to update the email address in two places. You need to update the PersonalInformation object and also the User object, since the email address is persisted against both. Updating the user object is also depend on whether or not the user is stored in an internal directory or an external directory (and if that external directory is read-only or allows writing).

If you have access to the Confluence source code (if not, a $10 starter licence will give you access to the source and, if you are doing any serious development on Confluence, I highly recommend this), have a look at com.atlassian.confluence.user.actions.EditMyProfileAction to see how Confluence does it. They key method are the updateUser method:

private void updateUser()
{
    DefaultUser userTemplate = new DefaultUser(getUser());
    userTemplate.setFullName(fullName);
    userTemplate.setEmail(email);

    userAccessor.saveUser(userTemplate);
}

and this snippet that updates the Personal Information object:

personalInformationManager.savePersonalInformation(getUser(), getPersonalInformation(), fullName);

Please let me know if I can clarify anything further :-)

Deleted user June 11, 2012

Tanke you! Now I can modify the email address. But I am really a bit confused now. I was expecting the same Exception as I get when I try to deactivate a user iwth the UserAccessor [See nested exception: com.atlassian.confluence.core.InsufficientPrivilegeException: User [Anonymous] does not have the required privileges.]

Why is it not thrown here?

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 12, 2012

I'm not sure I understand - the exception you have shown here would happen if you try to edit user details while logged in anonymously - you need to log in with an administrative account to maintain users.

Deleted user June 12, 2012

The code is executed in a triggered job module. I guess that is the reason for the anonymous user.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2012

Ah, OK. that makes sense. If you're calling some admin-protected code from within a scheduled task, you can just set the identify of the job to be an admin user by calling AuthenticatedUserThreadLocal.setUser

TAGS
AUG Leaders

Atlassian Community Events