Last modified by Eduard Moraru on 2022/02/28 00:29

From version 11.1
edited by Eduard Moraru
on 2018/07/12 14:26
Change comment: Upload new image "listDeletedDocumentUsers-result.png", version 1.1
To version 12.1
edited by Eduard Moraru
on 2018/07/12 14:34
Change comment: There is no comment for this version

Summary

Details

ExtensionCode.ExtensionClass[0]
Description
... ... @@ -1,13 +1,17 @@
1 -There can be a problem with deleted users that are still set as content authors for certain documents that contain scripts. The Script and Programming rights work by checking the content author of a document, so if the content author user no longer exists, the script will not be able (i.e. will fail) to execute.
1 +There can be a problem with deleted users that are still assigned to documents (as author, contentAuthor and even creator). The Script and Programming rights work by checking the content author of a document, so if the content author user no longer exists, the script will not be able (i.e. will fail) to execute. The same logic affects special object such as wiki macros, UIX or translations that check the document's last author's rights in order for them to be registered. Deleting the user that was last author has the effect of unregistering these objects and, for example, parts of the UI might start to fail or disappear.
2 2  
3 -This installable snippet list all such problematic users so they can be fixed.
3 +This installable snippet list all such problematic users and the documents that are still using them so they can be fixed.
4 4  
5 -Note: To fix these problematic cases, you can use the [[Change Content Author>>extensions:Extension.Change Content Author]] application.
5 +Note: To fix these problematic cases, you can use the [[Change Document User>>extensions:Extension.Change Content Author]] application.
6 6  
7 7  Requires Programming Rights.
8 8  
9 -{{image reference='listDeletedContentAuthorUsers.png' /}}
9 +Step1:
10 +{{image reference="listDeletedDocumentUsers.png"/}}
10 10  
12 +Step2:
13 +{{image reference="listDeletedDocumentUsers.png-result"/}}
14 +
11 11  == Source ==
12 12  
13 13  Below is the source to copy/paste in a new document in your XWiki instance, in case you can/will not use Extension Manager or direct XAR import to install it.
... ... @@ -14,17 +14,78 @@
14 14  
15 15  {{code language="velocity"}}
16 16  {{velocity}}
17 -#set ($allUsersQuery = "FROM doc.object(XWiki.XWikiUsers) AS userObj")
18 -#set ($allUsers = $services.query.xwql($allUsersQuery).execute())
19 -## Consider "system" users as well.
20 -#set ($discard = $allUsers.addAll(["XWiki.XWikiGuest", "XWiki.superadmin"]))
21 +#if ($request.list)
22 + #set ($fields = $request.getParameterValues('field'))
23 + #set ($fields = $fields.subList(0, $fields.size()))
24 + ##
25 + #set ($allUsersQuery = "FROM doc.object(XWiki.XWikiUsers) AS userObj")
26 + #set ($allUsers = $services.query.xwql($allUsersQuery).execute())
27 + ## Consider "system" users as well.
28 + #set ($discard = $allUsers.addAll(["XWiki.XWikiGuest", "XWiki.superadmin"]))
29 + ##
30 + #set ($deletedUsersQuery = "SELECT doc.fullName, doc.author, doc.contentAuthor, doc.creator FROM Document doc WHERE ")
31 + #foreach ($field in $fields)
32 + #if ($foreach.count > 1)
33 + #set ($deletedUsersQuery = "${deletedUsersQuery} OR ")
34 + #end
35 + #set ($deletedUsersQuery = "${deletedUsersQuery} doc.${field} NOT IN (:allUsers)")
36 + #end
37 + #set ($deletedUsers = $services.query.xwql($deletedUsersQuery).bindValue("allUsers", $allUsers).execute())
21 21  
22 -#set ($deletedContentAuthorUsersQuery = "SELECT DISTINCT doc.contentAuthor FROM Document doc WHERE doc.contentAuthor NOT IN (:allUsers)")
23 -#set ($deletedContentAuthorUsers = $services.query.xwql($deletedContentAuthorUsersQuery).bindValue("allUsers", $allUsers).execute())
39 + #macro (buildMaps $user $document $field)
40 + #if (!$allUsers.contains($user) && $fields.contains($field))
41 + #set ($docs = $userToDocsMap.get($user))
42 + #if ("$!docs" == '')
43 + #set ($docs = $collectionstool.set)
44 + #set ($discard = $userToDocsMap.put($user, $docs))
45 + #end
46 + #set ($discard = $docs.add($document))
47 + #set ($userDocKey = "${user},${document}")
48 + #set ($matchedFields = $userDocToMatchedFieldsMap.get($userDocKey))
49 + #if ("$!matchedFields" == '')
50 + #set ($matchedFields = [])
51 + #set ($discard = $userDocToMatchedFieldsMap.put($userDocKey, $matchedFields))
52 + #end
53 + #set ($discard = $matchedFields.add($field))
54 + #end
55 + #end
24 24  
25 -Deleted users ($deletedContentAuthorUsers.size() total) that are still set as content authors on existing documents of this wiki:
26 -#foreach ($deletedContentAuthorUser in $deletedContentAuthorUsers)
27 - * $deletedContentAuthorUser
57 + #set ($userToDocsMap = {})
58 + #set ($userDocToMatchedFieldsMap = {})
59 + #foreach ($deletedUser in $deletedUsers)
60 + #buildMaps($deletedUser[1], $deletedUser[0], 'author')
61 + #buildMaps($deletedUser[2], $deletedUser[0], 'contentAuthor')
62 + #buildMaps($deletedUser[3], $deletedUser[0], 'creator')
63 + #end
64 +
65 + Deleted users ($userToDocsMap.keySet().size() total) that are still used on existing documents of this wiki:
66 + #foreach ($deletedUser in $sorttool.sort($userToDocsMap.keySet()))
67 + 1. $deletedUser (((
68 + #foreach ($document in $sorttool.sort($userToDocsMap.get($deletedUser)))
69 + * [[$document]] ($document) fields $!{userDocToMatchedFieldsMap.get("$deletedUser,$document")}
70 + #end
71 + )))
72 + #end
73 +#else
74 + Lists the deleted users that are still being assigned to existing documents on the current wiki.
75 +
76 + Those documents could be negatively affected by lacking Programming or Scripting rights, or even having some of their objects (wiki macros, wiki components, UIX, translations) not properly registered due to the lack of rights caused by the user being deleted.
77 +
78 + {{html}}
79 + <form class='xform'>
80 + <dl>
81 + <dt><label>Fields to check</label></dt>
82 + <dd>
83 + <label><input type='checkbox' name='field' value='author' checked="checked" />author</label><br/>
84 + <label><input type='checkbox' name='field' value='contentAuthor' checked="checked" />contentAuthor</label><br/>
85 + <label><input type='checkbox' name='field' value='creator' checked="checked" />creator</label>
86 + </dd>
87 + </dl>
88 + <div>
89 + <input type='submit' name='list' class='button' value='List' />
90 + </div>
91 + </form>
92 + {{/html}}
28 28  #end
29 29  {{/velocity}}
30 30  {{/code}}
Name
... ... @@ -1,1 +1,1 @@
1 -List Deleted Content Author Users
1 +List Deleted Document Users
Summary
... ... @@ -1,1 +1,1 @@
1 -Lists deleted users that are still set as content authors on existing documents of this wiki
1 +Lists the deleted users that are still being assigned to existing documents on the current wiki.

Get Connected