... |
... |
@@ -1,18 +1,20 @@ |
1 |
1 |
{{groovy}} |
2 |
|
-def mainGroupDoc = xwiki.getDocument("XWiki.XWikiAllGroup") |
3 |
|
-def groupClassRef = "XWiki.XWikiGroups" |
|
2 |
+import org.xwiki.model.reference.DocumentReference |
4 |
4 |
|
|
4 |
+def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup") |
|
5 |
+def groupClassRef = new DocumentReference("xwiki", "XWiki", "XWikiGroups") |
|
6 |
+def mainGroupDoc = xwiki.getDocument(groupDocRef).getDocument() |
|
7 |
+ |
5 |
5 |
def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'") |
6 |
6 |
def added = [] |
7 |
7 |
|
8 |
8 |
allUsers.each { userDocName -> |
9 |
|
- def userDoc = xwiki.getDocument(userDocName) |
10 |
|
- def alreadyMember = mainGroupDoc.xObjects(groupClassRef)?.any { |
|
12 |
+ def alreadyMember = mainGroupDoc.getXObjects(groupClassRef)?.any { |
11 |
11 |
it?.getStringValue("member") == userDocName |
12 |
12 |
} |
13 |
13 |
|
14 |
14 |
if (!alreadyMember) { |
15 |
|
- def newObj = mainGroupDoc.newObject(groupClassRef) |
|
17 |
+ def newObj = mainGroupDoc.newXObject(groupClassRef) |
16 |
16 |
newObj.setStringValue("member", userDocName) |
17 |
17 |
added << userDocName |
18 |
18 |
} |
... |
... |
@@ -19,7 +19,8 @@ |
19 |
19 |
} |
20 |
20 |
|
21 |
21 |
if (added) { |
22 |
|
- xwiki.saveDocument(mainGroupDoc, "Added missing users to XWikiAllGroup: ${added.join(', ')}") |
|
24 |
+ def mainGroupWrapped = xwiki.getDocument(mainGroupDoc.documentReference) |
|
25 |
+ xwiki.saveDocument(mainGroupWrapped, "Added missing users to XWikiAllGroup: ${added.join(', ')}") |
23 |
23 |
println "✅ Added users to main wiki: ${added.join(', ')}" |
24 |
24 |
} else { |
25 |
25 |
println "✅ All users are already members of the main wiki." |