... |
... |
@@ -1,20 +1,67 @@ |
1 |
1 |
{{groovy}} |
2 |
2 |
import org.xwiki.model.reference.DocumentReference |
3 |
3 |
|
|
4 |
+// References |
4 |
4 |
def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup") |
5 |
5 |
def groupClassRef = new DocumentReference("xwiki", "XWiki", "XWikiGroups") |
6 |
|
-def mainGroupDoc = xwiki.getDocument(groupDocRef).getDocument() |
7 |
7 |
|
|
8 |
+// Load or create the group page |
|
9 |
+def groupDocAPI = xwiki.getDocument(groupDocRef) |
|
10 |
+def groupDoc = groupDocAPI.getDocument() |
|
11 |
+ |
|
12 |
+if (groupDoc.isNew()) { |
|
13 |
+ xwiki.saveDocument(groupDocAPI, "🆕 Created XWikiAllGroup") |
|
14 |
+ println "🆕 Created XWiki.XWikiAllGroup" |
|
15 |
+} |
|
16 |
+ |
|
17 |
+// Add missing users to group |
8 |
8 |
def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'") |
9 |
9 |
def added = [] |
10 |
10 |
|
11 |
11 |
allUsers.each { userDocName -> |
12 |
|
- def alreadyMember = mainGroupDoc.getXObjects(groupClassRef)?.any { |
|
22 |
+ def alreadyMember = groupDoc.getXObjects(groupClassRef)?.any { |
13 |
13 |
it?.getStringValue("member") == userDocName |
14 |
14 |
} |
15 |
15 |
|
16 |
16 |
if (!alreadyMember) { |
17 |
|
- def newObj = mainGroupDoc.newXObject(groupClassRef) |
|
27 |
+ def obj = groupDoc.newXObject(groupClassRef) |
|
28 |
+ obj.setStringValue("member", userDocName) |
|
29 |
+ added << userDocName |
|
30 |
+ } |
|
31 |
+} |
|
32 |
+ |
|
33 |
+// Save if needed |
|
34 |
+if (added) { |
|
35 |
+ def wrapper = xwiki.getDocument(groupDoc.documentReference) |
|
36 |
+ xwiki.saveDocument(wrapper, "✅ Added users to group: ${added.join(', ')}") |
|
37 |
+ println "✅ Added: ${added.join(', ')}" |
|
38 |
+} else { |
|
39 |
+ println "✅ All users already |
|
40 |
+ |
|
41 |
+def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup") |
|
42 |
+def groupClassName = "XWiki.XWikiGroups" |
|
43 |
+ |
|
44 |
+// 1. Ensure the group document exists |
|
45 |
+def groupDocAPI = xwiki.getDocument(groupDocRef) |
|
46 |
+def groupDoc = groupDocAPI.getDocument() |
|
47 |
+ |
|
48 |
+if (groupDoc.isNew()) { |
|
49 |
+ def apiDoc = xwiki.getDocument(groupDoc.documentReference) |
|
50 |
+ xwiki.saveDocument(apiDoc, "Created XWikiAllGroup page") |
|
51 |
+ println "🆕 Created XWiki.XWikiAllGroup page" |
|
52 |
+} |
|
53 |
+ |
|
54 |
+// 2. Proceed as before |
|
55 |
+def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'") |
|
56 |
+def added = [] |
|
57 |
+ |
|
58 |
+allUsers.each { userDocName -> |
|
59 |
+ def alreadyMember = groupDoc.getXObjects(groupClassName)?.any { |
|
60 |
+ it?.getStringValue("member") == userDocName |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ if (!alreadyMember) { |
|
64 |
+ def newObj = groupDoc.newXObject(groupClassName) |
18 |
18 |
newObj.setStringValue("member", userDocName) |
19 |
19 |
added << userDocName |
20 |
20 |
} |
... |
... |
@@ -21,8 +21,8 @@ |
21 |
21 |
} |
22 |
22 |
|
23 |
23 |
if (added) { |
24 |
|
- def mainGroupWrapped = xwiki.getDocument(mainGroupDoc.documentReference) |
25 |
|
- xwiki.saveDocument(mainGroupWrapped, "Added missing users to XWikiAllGroup: ${added.join(', ')}") |
|
71 |
+ def wrappedDoc = xwiki.getDocument(groupDoc.documentReference) |
|
72 |
+ xwiki.saveDocument(wrappedDoc, "✅ Added users to XWikiAllGroup: ${added.join(', ')}") |
26 |
26 |
println "✅ Added users to main wiki: ${added.join(', ')}" |
27 |
27 |
} else { |
28 |
28 |
println "✅ All users are already members of the main wiki." |