Search for users without an email address

Hi.

As an admin with a wiki working with Open ID Connect we try to make house keeping by email addresses. All users with an email not found in our azure ad will be spotted and manually deleted. But this ignores all users that do not have any email address. So I wrote a little velocity script:

#set ($users = $services.query.xwql('from doc.object(XWiki.XWikiUsers) as user').setWiki('xwiki').addFilter('unique').execute())
#foreach ($user in $users)
  #if(!$services.user.getProperties($user).email)
  1. [[$user>>doc:xwiki:$user]]
  #end
#end

The execution takes some time. Is there a smarter query to find those users?

Regards, Simpel

Yes, you need to indicate the condition “without an email address” directly in the DB query and not iterate as this will load user pages.

See examples at https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module#HQueryLanguageExamples

1 Like

For those who are curious about the solution:

#set ($users = $services.query.xwql("where doc.object(XWiki.XWikiUsers).email = ''").setWiki('xwiki').addFilter('unique').execute())
#foreach ($user in $users)
  1. [[$user>>doc:xwiki:$user]]
#end

That is fast.