... |
... |
@@ -1,30 +1,18 @@ |
1 |
1 |
{{groovy}} |
2 |
|
-import org.xwiki.model.reference.DocumentReference |
3 |
|
- |
4 |
|
-def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup") |
|
2 |
+def groupDocRef = "XWiki.XWikiAllGroup" |
5 |
5 |
def groupClassName = "XWiki.XWikiGroups" |
6 |
6 |
|
7 |
|
-// 1. Ensure the group document exists |
8 |
|
-def groupDocAPI = xwiki.getDocument(groupDocRef) |
9 |
|
-def groupDoc = groupDocAPI.getDocument() |
10 |
|
- |
11 |
|
-if (groupDoc.isNew()) { |
12 |
|
- def apiDoc = xwiki.getDocument(groupDoc.documentReference) |
13 |
|
- xwiki.saveDocument(apiDoc, "Created XWikiAllGroup page") |
14 |
|
- println "🆕 Created XWiki.XWikiAllGroup page" |
15 |
|
-} |
16 |
|
- |
17 |
|
-// 2. Proceed as before |
|
5 |
+def mainGroupDoc = xwiki.getDocument(groupDocRef).getDocument() |
18 |
18 |
def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'") |
19 |
19 |
def added = [] |
20 |
20 |
|
21 |
21 |
allUsers.each { userDocName -> |
22 |
|
- def alreadyMember = groupDoc.getXObjects(groupClassName)?.any { |
|
10 |
+ def alreadyMember = mainGroupDoc.getXObjects(groupClassName)?.any { |
23 |
23 |
it?.getStringValue("member") == userDocName |
24 |
24 |
} |
25 |
25 |
|
26 |
26 |
if (!alreadyMember) { |
27 |
|
- def newObj = groupDoc.newXObject(groupClassName) |
|
15 |
+ def newObj = mainGroupDoc.newXObject(groupClassName) |
28 |
28 |
newObj.setStringValue("member", userDocName) |
29 |
29 |
added << userDocName |
30 |
30 |
} |
... |
... |
@@ -31,7 +31,7 @@ |
31 |
31 |
} |
32 |
32 |
|
33 |
33 |
if (added) { |
34 |
|
- def wrappedDoc = xwiki.getDocument(groupDoc.documentReference) |
|
22 |
+ def wrappedDoc = xwiki.getDocument(mainGroupDoc.documentReference) |
35 |
35 |
xwiki.saveDocument(wrappedDoc, "✅ Added users to XWikiAllGroup: ${added.join(', ')}") |
36 |
36 |
println "✅ Added users to main wiki: ${added.join(', ')}" |
37 |
37 |
} else { |