user_deleteLists the deleted users that are still being assigned to existing documents on the current wiki.
TypeXAR
CategoryApplication
Developed by

Eduard Moraru

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1
Installable with the Extension Manager

Description

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.

This installable snippet list all such problematic users and the documents that are still using them so they can be fixed.

Note: To fix these problematic cases, you can use the Change Document User application.

Requires Programming Rights.

Step1:
listDeletedDocumentUsers.png

Step2:
listDeletedDocumentUsers-result.png

Source

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.

{{velocity}}
#if ($request.list)
 #set ($fields = $request.getParameterValues('field'))
 #set ($fields = $fields.subList(0, $fields.size()))
 ##
 #set ($allUsersQuery = "FROM doc.object(XWiki.XWikiUsers) AS userObj")
 #set ($allUsers = $services.query.xwql($allUsersQuery).execute())
 ## Consider "system" users as well.
 #set ($discard = $allUsers.addAll(["XWiki.XWikiGuest", "XWiki.superadmin"]))
 ##
 #set ($deletedUsersQuery = "SELECT doc.fullName, doc.author, doc.contentAuthor, doc.creator FROM Document doc WHERE ")
 #foreach ($field in $fields)
   #if ($foreach.count > 1)
     #set ($deletedUsersQuery = "${deletedUsersQuery} OR ")
   #end
   #set ($deletedUsersQuery = "${deletedUsersQuery} doc.${field} NOT IN (:allUsers)")
 #end
 #set ($deletedUsers = $services.query.xwql($deletedUsersQuery).bindValue("allUsers", $allUsers).execute())

 #macro (buildMaps $user $document $field)
   #if (!$allUsers.contains($user) && $fields.contains($field))
     #set ($docs = $userToDocsMap.get($user))
     #if ("$!docs" == '')
       #set ($docs = $collectionstool.set)
       #set ($discard = $userToDocsMap.put($user, $docs))
     #end
     #set ($discard = $docs.add($document))
     #set ($userDocKey = "${user},${document}")
     #set ($matchedFields = $userDocToMatchedFieldsMap.get($userDocKey))
     #if ("$!matchedFields" == '')
       #set ($matchedFields = [])
       #set ($discard = $userDocToMatchedFieldsMap.put($userDocKey, $matchedFields))
     #end
     #set ($discard = $matchedFields.add($field))
   #end
 #end

 #set ($userToDocsMap = {})
 #set ($userDocToMatchedFieldsMap = {})
 #foreach ($deletedUser in $deletedUsers)
   #buildMaps($deletedUser[1], $deletedUser[0], 'author')
   #buildMaps($deletedUser[2], $deletedUser[0], 'contentAuthor')
   #buildMaps($deletedUser[3], $deletedUser[0], 'creator')
 #end

  Deleted users ($userToDocsMap.keySet().size() total) that are still used on existing documents of this wiki:
 #foreach ($deletedUser in $sorttool.sort($userToDocsMap.keySet()))
    1. $deletedUser (((
   #foreach ($document in $sorttool.sort($userToDocsMap.get($deletedUser)))
      * [[$document]] ($document) fields $!{userDocToMatchedFieldsMap.get("$deletedUser,$document")}
   #end
    )))
 #end
#else
  Lists the deleted users that are still being assigned to existing documents on the current wiki.

  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.

 {{html}}
  <form class='xform'>
    <dl>
      <dt><label>Fields to check</label></dt>
      <dd>
        <label><input type='checkbox' name='field' value='author' checked="checked" />author</label><br/>
        <label><input type='checkbox' name='field' value='contentAuthor' checked="checked" />contentAuthor</label><br/>
        <label><input type='checkbox' name='field' value='creator' checked="checked" />creator</label>
      </dd>
    </dl>
    <div>
      <input type='submit' name='list' class='button' value='List' />
    </div>
  </form>
 {{/html}}
#end
{{/velocity}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v2.0

  • Major refactoring
    • Added fields selector and updated the query
    • Updated the results page to show the fields matched on each document
    • Renamed page
Tags:
Created by Eduard Moraru on 2015/10/12 15:37
    

Get Connected