0 Votes

Changes for page Script

Last modified by Ryan C on 2025/05/13 16:08

From version 3.1
edited by Ryan C
on 2025/05/12 21:10
Change comment: There is no comment for this version
To version 6.1
edited by Ryan C
on 2025/05/12 23:40
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,28 +1,9 @@
1 -{{groovy}}
2 -def mainGroupDoc = xwiki.getDocument("XWiki.XWikiAllGroup").getDocument()
3 -def groupClassRef = "XWiki.XWikiGroups"
1 +{{velocity}}
2 +#set($doc = $xwiki.getDocument("XWiki.XWikiGroups"))
3 +#set($class = $doc.xWikiClass)
4 +* Fields in XWikiGroups:
5 +#foreach ($field in $class.properties.entrySet())
6 + - **$field.key** (type: $field.value.class.simpleName)
7 +#end
8 +{{/velocity}}
4 4  
5 -def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'")
6 -def added = []
7 -
8 -allUsers.each { userDocName ->
9 - def userDoc = xwiki.getDocument(userDocName)
10 - def alreadyMember = mainGroupDoc.getXObjects(groupClassRef)?.any {
11 - it?.getStringValue("member") == userDocName
12 - }
13 -
14 - if (!alreadyMember) {
15 - def newObj = mainGroupDoc.newXObject(groupClassRef)
16 - newObj.setStringValue("member", userDocName)
17 - added << userDocName
18 - }
19 -}
20 -
21 -if (added) {
22 - xwiki.saveDocument(mainGroupDoc.newDocument(), "Added missing users to XWikiAllGroup: ${added.join(', ')}")
23 - println "✅ Added users to main wiki: ${added.join(', ')}"
24 -} else {
25 - println "✅ All users are already members of the main wiki."
26 -}
27 -{{/groovy}}
28 -