Delete user and all associated entries

Hey guys,
I wanted to ask if you have had some experience or just happen to have some ideas how I might achieve the following:

Delete user > delete all associated entries

The deletion of a user should be followed by some sort of cascading deletion of the associated entries.

The real-life situation would be something like:
“Employee leaves company and wants his entries with personal information to be deleted”. Personal information could be an entry in an application like a phone list.

Do you think this is possible with some sort of XWQL, HQL, or SOLR Query for the “gathering docs/objects that contain information about the user” and some velocity or groovy for the deletion part?

Using “where doc.author = ‘XWiki.userName’” for example wouldn’t work because the user isn’t always the author.
Is there a way to crawl through all docs (and children) for the username?

I haven’t been able to find something specific around here, at https://snippets.xwiki.org/xwiki/bin/view/Main/ or freestyle searching with google.

Every hint helps. Thanks for reading. I’ll keep you posted about the progress.

Greetings,
Marc

1 Like

Very good question, as this is as far as I know a requirement that comes from European Legal General Data Protection Regulation GDPR (EU-DSGVO).

regards

Holger

Hi, when you delete a user his profile page is also removed. So all his personal info is also removed. That should cover the main cases.

Now if you have created custom and specific pages a bit everywhere on the wiki about this user, you’ll need to edit or delete these pages yourself. You can script this of course.

If you mean search for content containing the user name, then yes, it’s very easy. You can test this in the search. See https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module for how to script it.

You can also search https://snippets.xwiki.org/xwiki/bin/view/Main/ for code snippets. For example this one deletes all users in the wiki: https://snippets.xwiki.org/xwiki/bin/view/Extension/Delete%20all%20users%20in%20current%20wiki and you could adapt it to your needs.

IMPORTANT: If you remove a user and that user had set Programming Rights or Scripting Rights in a wiki page then delete the user will remove those rights and the page may fail to execute (if it contains scripts that requires these rights). For this you should transfer ownership, see https://extensions.xwiki.org/xwiki/bin/view/Extension/Change%20Content%20Author

1 Like

Thanks for your quality input. I’ll work on a solution and keep you guys posted with which tools I got it working. :slight_smile:

#set($hql = "where doc.creator='XWiki.TestTest'")
#set($results = $xwiki.searchDocuments($hql, 1000, 0))
#foreach ($item in $results)
 * $item
#end

That’s what I’m currently using to query pages and entries that are associated with the user. Seems to work and list everything in my test case.
Qb6806
Now I’ll just need a way to delete those pages (I’ll need something like this I guess https://snippets.xwiki.org/xwiki/bin/view/Extension/Delete%20page%20programatically/ )
//Edit: I’ll have to check which pages get deleted during the normal “delete user” though. Also I’m not sure if “where creator = user” wouldn’t also delete “useful information that the user created while he was working for the company”, I should check that too.

I’m not sure yet how to (programatically) delete the found entries in an application though. I’ll eventually get there, but I am open to ideas.

Have a good one guys.

Note that it depends what you’re after. If you want to remove everything authored by a given then I have something for you :wink: I have created an AntiSpam application and one feature it has is to delete all content authored by a given XWiki user. So imagine for example that you have a page and that author has contributed to it in revision N but there are now many more revisions. The Anti Spam app will just remove those revisions done by that author. Note that it’ll also remove the entries from the Event Stream. You don’t get that when you just delete a page.

I’m not sure that you’re interested to remove all content authored by a given user but if you are then this is for you!

The AntiSpam app is available at https://extensions.xwiki.org/xwiki/bin/view/Extension/AntiSpam%20Tool%20Application

The way to use it is to fill the “user” field with the full name for example: XWiki.MyUser.

Thanks for the reply.

I’m not sure that you’re interested to remove all content authored by a given user […]

You are completely right, I am not really after that. Just came to me while posting and I added it as edit. :roll_eyes:

I’ll have a look at the AntiSpam nonetheless. Maybe I can draw some inspiration from it.

So it depends what you’re after:

  • Remove all content authored by a given user
  • Only remove personal information about that user

It’s probably the later I’d say. And for that you’ll need to define what you mean by “personal information” and find a way to search for that. In any case, you wouldn’t want to delete a full page in this case but more to remove that content.

That’s doable and easy (if you can pinpoint exactly what you’re after). I’ve just created this snippet for you: https://snippets.xwiki.org/xwiki/bin/view/Extension/Replace%20content/

Have fun

1 Like