How to get inactive users of group and remove them from group with Scriptrunner for Confluence?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 28, 2023

Hi Community,

I´m implementing an automatic cleanup for user groups. This worked pretty fine for Jira but unfortunately Confluence seems really challenging.

Does anyone know why there are so many confusing (at least from my perspective) classes, why nearly same classes work so differently or have different/little methods? furhtermore the returned types are kinda frustrating.

so in Jira I got the following lines working like a charm:

 

def inactiveUsersInGroup = groupManager.getUsersInGroup(userGroup)?.findAll { it.active == false }

Groups.getByName(userGroup).remove(user)

 

For Confluence:

  • There is no method "getUsersInGroup"
  • furthermore there is no direct property "active" within the user
  • Furthermore what are the differences between "ConfluenceUser" and "User" ? Is there any possibility to get list of Users I can then access and filter?

 

Any help much appreciated.

Best
Stefan

 

 

1 answer

1 accepted

0 votes
Answer accepted
Sayed Bares _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 28, 2023

@Stefan Salzl You can look into https://library.adaptavist.com/entity/check-active-user-count-remove-oldest-listener?tab=dataCenter as an example.

You can use getMembers method to get members and then isDeactivated to check if they are active.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 29, 2023

Hi @Sayed Bares _ServiceRocket_ 

Thanks for your input. The annoying thing is I can´t filter/find inactive users from a group immediately:

This doesn´t work:

def inactiveUsersInGroup = userAccessor.getMembers(groupManager.getGroup(userGroup)).findAll { it.isDeactivated == true }

as the .getMembers() results 

Iterable<ConfluenceUser>

So is there no propper solution to get a list of users?

 

Furthermore some of my questions still open:

The UserAccessor (mostly) delivers "ConcluenceUser" (class: ConfluenceUserImpl) which then has the following property:

backingUser:EmbeddedCrowdUser{name='xxx', displayName='xxx', directoryId=nnnn}

 

The method "isDeactivated()" doesn´t work on a User resulting from UserAccessor.getUser()

 

When I use CrowdService.getUser() it results a User of class class com.atlassian.confluence.impl.user.crowd.Cached

It also delivers a property "active". 

I wanted to use the CrowdService to collect all users (in some earlier steps I need to collect all users that come from a dedicated AD-directory, so the "directory" property is needed too). But I struggled with the findUsers() and the query :(

 

So there is no way to do such an easy way like in Jira to do a search for users that can be filterd with .findAll{} and results in a "useful" list of users?

 

Thanks in Advance

Best
Stefan

Sayed Bares _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 29, 2023

To check the if the user is active you would need to use userAccessor.isDeactivated(user)

import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.user.GroupManager

 

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

def confluence_user = groupManager.getGroup("confluence-users")
def users = userAccessor.getMembers(confluence_user).each{it -> log.warn(userAccessor.isDeactivated(it))}
Like Stefan Salzl likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events