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:
Any help much appreciated.
Best
Stefan
@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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.