Views Bulk Operations allows user accounts to be deleted via the normal entity delete action, but in Drupal 7 that's not the same as user cancellation (in which the administrator can choose multiple different ways to "cancel" the account).

Here's a patch that adds a basic action to perform user cancellation via VBO. It's missing some of the features that exist in the core user operation (on the standard admin/people page), such as protection against deleting admin accounts and the option to send e-mail confirmation... But it should be a good start.

Comments

David_Rothstein’s picture

Status: Active » Needs review
StatusFileSize
new1.67 KB

Here's the patch.

imp7’s picture

Thanks David_Rothstein works great, I added some permission checks in my patch. I imagine there is a better way to throw errors in vbo?

imp7’s picture

Why doesn't d.org let me edit a typo in the attachment.

bojanz’s picture

@imp7
I think an action is the wrong place to add your custom permission checks.

@David_Rothstein
The problem with the current code is that user_cancel() sets a status message per each processed user.
100 blocked users == 100 messages (+ 1 from VBO), which is quite bad usability wise.

Perhaps we want to implement our own user_cancel() that adds a final step to the batch that does drupal_get_messages('status', TRUE) to remove the set messages? (Doing it right after user_cancel() is invoked doesn't work, it needs to happen after the batch as far as I can see)

petednz’s picture

hi nice to see some work on this - i am guessing that this will be a necessary option for us if we want to use VBO to cancel accounts and in doing so report them to Mollom.

loze’s picture

The patch in #1 works for me. Thanks.

David_Rothstein’s picture

@David_Rothstein
The problem with the current code is that user_cancel() sets a status message per each processed user.
100 blocked users == 100 messages (+ 1 from VBO), which is quite bad usability wise.

This is true, although the standard admin/people page in Drupal core also results in one message for each processed user, so at least it's not really a regression compared to that.

xurizaemon’s picture

Without the permissions checks in the action.

I kind of want to add the perm check to action info, but (1) it won't cover the "administerusersbyrole" module in previous patch, (2) it looks like other actions like user_role don't include a 'permissions' attribute for their actions so I'm going to follow that here. (So ... in VBO-land, sites typically implement permissions checks at the View layer? That wouldn't have been my expectation.)

EDIT: Ugh, this isn't right, will post a replacement shortly.

xurizaemon’s picture

Updated. --author="drothstein <drothstein@124982.no-reply.drupal.org>" please as he's the original author.

And ... I see the patch in #1 is basically identical, except = is replaced with += in #9 in views_bulk_operations_user_cancel_action_form

+  $form['user_cancel_method'] += user_cancel_methods();
roam2345’s picture

StatusFileSize
new2.5 KB

wrong patch.. plz ignore this one.

roam2345’s picture

Fix all out standing issues with patch.

roam2345’s picture

Follow what bojanz said and implement our own user_cancel.

geerlingguy’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This patch works great, and allows me to cancel accounts in much the same way as Drupal 7's built-in 'People' page. Once the operation completes (if it's not enqueued), it displays a bunch of messages like "The update has been performed.", then "username has been deleted.".

Not a big deal, but when you cancel more than a few hundred users, this list is quite long!

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Rewrote views_bulk_operations_user_cancel_action() to prevent the double batching that #12 had, and to prevent the message-per-user that all patches had. Also added the ability for admin to check whether notifications will be sent.
Also added code that prevents the user from cancelling himself.

http://drupalcode.org/project/views_bulk_operations.git/commitdiff/256f8...

The original code had a cache clear for each cancellation, I removed it for performance reasons, we might want to readd a cache clear at the end of the complete process.

Test and let me know if you find any issues.

geerlingguy’s picture

I was about to come back here and post the exact points you just mentioned... but I think that about takes care of it. We were batching 14,000 user cancellations with #12, and cancelled it after an hour or so. Patch #14 fixes this and makes the operation take a lot less time.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.