Jira plugin change user permission programmatically

549 Views Asked by At

How can I change (update, edit) user permission. For example sign up and create user1, after this user1 have a jira-user permission. I need update permission, and set for example jira-administrator for user1. Is there any class which response for this, or I have to update CWD_USER table in jira DB.

1

There are 1 best solutions below

0
On

You can move user from one group to another by using Jira SDK API

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.Group

public void addUserToGroup(String userName, String groupName) {
    UserManager userManager = ComponentAccessor.getUserManager();
    ApplicationUser user = userManager.getUserByName(userName);
    Group group = userManager.getGroup(groupName);
    UserUtil userUtil = ComponentAccessor.getUserUtil();
    userUtil.addUserToGroup(group, user.getDirectoryUser());
}

Verified by Jira 6.3.10