Add users with specific email to group

Andre September 20, 2019

Hi guys,

I'm searching for a solution that gives me the opportunity to add users with a certain e-mail adress to an additional group.

At the moment every logged in user is added to an internal confluence group. Some users with a specific e-mail "@abc.de" should be added to an additional group.

The only option i found at the moment would be a groovy script which would do that after the user is created. Or is there an easier way to do that?

I checked all groovy scripts for confluence i could and tried to add them to my needs. Actually it would only need a check for all users with the defined email adress.

import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.GroupManager
import com.atlassian.user.UserManager

def groupManager = ComponentLocator.getComponent(GroupManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)

def specialGroup = groupManager.getGroup("special") ?: groupManager.createGroup("special")

def users = userManager.users

def usersToMove = ["anuser", "u100"]

usersToMove.each { username ->

def user = userAccessor.getUserByName(username)

if (user) {
log.info "Add user ${user.name} to the group: 'Special Group'"
groupManager.addMembership(specialGroup, user)
}

 

1 answer

0 votes
Rafael Pinto Sperafico
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 20, 2019

Hi @Andre ,

Groovy script you have suggested seems a valid option based on your needs, if not the only one without modifying data from the database directly.

I would invite you to comment on https://jira.atlassian.com/browse/CONFSERVER-56205 - Provide REST API methods to manage users and groups, as this could bring different ways manipulating users and groups without the need of a 3rd party plugin.

Kind regards,
Rafael

Andre September 24, 2019

i finalized the groovy script and defined a event listener so that the script starts when a new user is created.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events