List all global users not in XWikiAllGroup

Hi.

I do have brain fog today. It could be a oneliner I guess but I won‘t get it.

How to list all global users that are not in XWikiAllGroup?

Thanks and regards, Simpel

Hi Simpel,

Here’s the example, which is performed an opposite
Get the members of some group:

{{velocity}}
# Get all the members by resolving sub-groups
#set($allGroupsInAllWikis = $services.user.group.getMembers('xwiki:XWiki.MyGroup'))

# Get only the direct members
#set($allGroupsInUserWiki = $services.user.group.getMembers('xwiki:XWiki.MyGroup', false))
{{/velocity}}

Hope, that’ll help you.

Thank you for your code. Next I have to get all global users to compare.

If I’m inside the main wiki this code is working:

#set($allUser = $services.query.xwql('from doc.object("XWiki.XWikiUsers") as user').addFilter('unique').execute())

It’s listing all global users. No results on sub wiki which seems ok as we have no local users. But how to get from inside a sub wiki all users of main wiki?

That isn’t working:

#set($allUser = $services.query.xwql('from doc.object("xwiki:XWiki.XWikiUsers") as user').addFilter('unique').execute())

You can use #setWiki to force the query to be executed on a specific wiki. See Query Module (XWiki.org) for some examples.

1 Like

The first one you execute from the main database, whereas the last one is from sub-wiki, which has its database and schema.

Thank you. This is my final solution:

{{velocity}}
## retrieve global group XWikiAllGroup
#set ($allGroupDoc = $xwiki.getDocument('xwiki:XWiki.XWikiAllGroup'))
## retrieve all global user
#set($allUser = $services.query.xwql('from doc.object("XWiki.XWikiUsers") as user order by doc.name').setWiki('xwiki').addFilter('unique').execute())

## list all user not in global XWikiAllGroup
#foreach ($user in $allUser)
  #if (!$allGroupDoc.getObject('XWiki.XWikiGroups', 'member', $user))
    * [[xwiki:$user>>xwiki:$user||queryString="category=groups"]]
  #end
#end
{{/velocity}}