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