Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
7.1 | 1 | {{groovy}} |
2 | import org.xwiki.model.reference.DocumentReference | ||
![]() |
1.1 | 3 | |
![]() |
8.1 | 4 | // References |
![]() |
7.1 | 5 | def groupDocRef = new DocumentReference("xwiki", "XWiki", "XWikiAllGroup") |
![]() |
10.1 | 6 | def groupClassName = "XWiki.XWikiGroups" // ⚠️ Must be a STRING |
![]() |
8.1 | 7 | |
8 | // Load or create the group page | ||
9 | def groupDocAPI = xwiki.getDocument(groupDocRef) | ||
10 | def groupDoc = groupDocAPI.getDocument() | ||
11 | |||
12 | if (groupDoc.isNew()) { | ||
![]() |
9.1 | 13 | xwiki.saveDocument(groupDocAPI, "Created XWikiAllGroup") |
14 | println "Created XWiki.XWikiAllGroup" | ||
![]() |
8.1 | 15 | } |
16 | |||
17 | // Add missing users to group | ||
18 | def allUsers = xwiki.searchDocuments("where doc.fullName like 'XWiki.%' and doc.fullName != 'XWiki.XWikiAllGroup'") | ||
19 | def added = [] | ||
20 | |||
21 | allUsers.each { userDocName -> | ||
![]() |
10.1 | 22 | def alreadyMember = groupDoc.getXObjects(groupClassName)?.any { |
![]() |
8.1 | 23 | it?.getStringValue("member") == userDocName |
24 | } | ||
25 | |||
26 | if (!alreadyMember) { | ||
![]() |
10.1 | 27 | def obj = groupDoc.newXObject(groupClassName) // ✅ String only |
![]() |
8.1 | 28 | obj.setStringValue("member", userDocName) |
29 | added << userDocName | ||
30 | } | ||
31 | } | ||
32 | |||
![]() |
10.1 | 33 | // Save the document |
![]() |
8.1 | 34 | if (added) { |
![]() |
10.1 | 35 | def wrappedDoc = xwiki.getDocument(groupDoc.documentReference) |
36 | xwiki.saveDocument(wrappedDoc, "Added users to group: ${added.join(', ')}") | ||
![]() |
9.1 | 37 | println "Added users: ${added.join(', ')}" |
![]() |
8.1 | 38 | } else { |
![]() |
9.1 | 39 | println "All users are already members of the main wiki." |
![]() |
7.1 | 40 | } |
41 | {{/groovy}} | ||
42 |