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?
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.
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
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.
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.
Note that it depends what you’re after. If you want to remove everything authored by a given then I have something for you 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!
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.