WIth current HEAD, you can't delete a user. If you click 'delete' it just goes back to the admin/user page instead of prompting to delete the user. Also, after you edit a user it takes you back to the admin/user instead of letting you see the changes you made (like the rest of the Drupal).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m3avrck’s picture

Status: Active » Needs review
FileSize
1.25 KB

The attached patch fixes this problem and also makes editing users act the same way as editing a node (e.g., after you save an edit, you goto the view tab). Works like it should now!

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community
chx’s picture

Dunno, really dunno. What happens with orphaned nodes ?

m3avrck’s picture

Status: Reviewed & tested by the community » Needs work

Maybe you can't delete a user if they are attached to a node? Or maybe that author becomes 'unknown' or it deletes all associated posts with that user (like forum does).

Or, there shouldn't be a 'delete' button at all.

What to do?

Dries’s picture

I don't think I can reproduce this. I just managed to delete user #1 (without this patch).

m3avrck’s picture

Right that is *very* bad, this patch prevents that special case from happening: http://drupal.org/node/36701 ... but otherwise, I can't seem to delete *any* user, even 1, right now with current HEAD.

naudefj’s picture

+1 for committing m3avrck's patch - see http://drupal.org/node/41996

m3avrck’s picture

FileSize
2.66 KB

Ok here is a new patch updated against HEAD. This patch incorporates the uid=1 issues I brought up here: http://drupal.org/node/36701

This patch does a few things:

1. Restores deleting of users so it works again

2. Prevents deletion of uid=1 (you shouldn't be able to delete uid=1, what if you gave a lesser role ability to manage user accounts? they could easily delete this role)

3. Prevents people frome editing uid=1 too, again for reasons above

m3avrck’s picture

FileSize
3.16 KB

Ok here's a new patch which adds a watchdog warning when you delete a user.

m3avrck’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
6.04 KB

Ok here's a new patch which says 'page not found' when trying to access something like this: http://drupal.org/user/2462462 ... this also removes the tabs from being displayed in this case, which when clicking on, can cause all sorts of weird problems.

m3avrck’s picture

Status: Reviewed & tested by the community » Needs review

oops needs some review first ;-)

Souvent22’s picture

Status: Needs review » Reviewed & tested by the community

Tried it on my test bed to get to user 39082398797324, and worked well for me. I'd say ready to go.

Dries’s picture

Does that new user_load() add sql queries to each page request?

m3avrck’s picture

Dries, you're right, I meant to check that as well. Just ran the test, this does add 1 query to each page, this query:

SELECT u.* FROM users u WHERE u.uid = 0 AND LOWER(u.status) = LOWER('1') AND u.status < 3 LIMIT 0, 1

Or similiar as uid changes, it is running roughly 0.7ms long, which is fairly negligble.

However, I did discover another issue ... right now when you delete a user account that has created content, the user is merely deleted from Drupal, but their content remains. However, this content isn't accessible anymore, but still lives in the database. Should perhaps another issue/patch be created that addresses this issue, in the sense that admins have a few options when deleting users: remove *everything* tied to their account, leave content and change author to 'unknown' (or fill in the blank setting here), or maybe even some other setting. I would think this would be very popular, especially with different privacy laws (US vs EU for example), since right now, Drupal, really doesn't do much for the stricter EU laws since data is still in the database.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

It would be nice if that query wasn't necessary. The overhead of that query depends on the number of users in the database. BTW, a single query that takes 1ms costs drupal.org ~20 hour of processing time a year. :)

Why do we lower integers? "LOWER(u.status) = LOWER('1')". Also, why do we check whether u.status < 3 when status has to be LOWER('1')? :P

Also, don't introduce special cases and remove:

+  // Don't allow anyone to edit uid = 1 unless logged in as uid = 1
+  if (!($account->uid == 1 && $user->uid != 1)) {
+    $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 30);
+  }
+  // Don't allow the deletion of uid = 1
+  if (user_access('administer users') && $account->uid != 1) {
m3avrck’s picture

Right I'll see what I can do about that query. As for why is the query handled that way, well that is the way user_load() is currently code, I had my doubts too about that, but wasn't sure exactly why it was needed either.

Now what is so wrong about the special case of uid=1? That is always a special case in core and it seems to me that, that account shouldn't be able to be deleted and if someone needs to delete it, then I'm sure they are more than capable enough to do that in the database. Right?

m3avrck’s picture

Status: Needs work » Needs review
FileSize
5.92 KB

Ok here's a new patch, a lot better.

First off, this patch has already went in that cleaned up the query LOWER(u.status) = LOWER('1') : http://drupal.org/node/42115

Second off, this new patch introduces *no new* queries. I reworked the logic, so no queries are added to any page. No performance hit at all now.

Third, all special cases have been removed per Dries request.

So what this patch fixes is deleting users, along with trying to access a user account that doesn't exist. Fully tested, I'd say this is RTC, but someone else please review.

Souvent22’s picture

A few offsets when patching, but not errors, and patched perfectly fine. The module also works as predicted. attemted to delete some users, and got the expected results with this patch. i'd say, RTC.

merlinofchaos’s picture

I disagree about not special-casing uid 1. That account should not be deletable. The recovery of that error is painful, and someone asleep at the wheel can do it.

If the system completely removed the dependency on uid 1 I'd be more agreeable, but since uid 1 is already special-cased, I don't see why we can arbitrarily say not to special-case it here.

simon rawson’s picture

FileSize
5.29 KB

Tested patch and I can confirm that it does what it says on the tin. No offsets when I patched against HEAD.

However, we have lost the potential for adding a "destinations" to the delete or edit operation. I could never see how this would be useful myself, but presumably it must have been thought useful at some point.

So, using the same method that node.module uses to do this (unsetting the $_REQUEST['destination']) I've taken the liberty of adding a couple of lines to this patch. I hope nobody minds.

Simon

m3avrck’s picture

@simon, not a bad call, i'll allow it ;-)

someone please set to commit if they like!

Dries’s picture

I don't like the change to user_view(). Passing the $account and doing a check is not very clean. I'd rather have duplicate queries and caching in user_load(). Plus, the extra query should only happen in case the URL is of the format "user/num/*". The original patch did that query for all page views, which does not appear to be necessary.

m3avrck’s picture

FileSize
4.41 KB

@Dries, ok my first thought was you would dislike the duplicate queries, hence the work around, guess I was wrong :-P

Anyways, new patch, slimmed down a bit. This fixes user deletion, adds a watchdog warning upon user deletion and fixes access to users that don't exist (e.g., user/234623462346).

Duplicate queries (2 of them) exist on all user/N pages, that is it. Fairly trivial, only way around this is to pass the variable in (since you have to call user_load() to check if the user exists) but since this is not the "prettiest" way maybe it'll suffice?

Should be good to go now, nothing else left to debate ;-)

simon rawson’s picture

Couple of issues still.

One of them is my fault, because the patch I submitted last night had a silly mistake in it.

The patch I'm submitting does the following.

1. Users can now be deleted using the delete button from admin/users.
2. Users are now returned to admin/users if they delete a user and to user/number if they have just edited the profile.
3. A destination is not set when entering the user editing/deleting form from admin/users but if one was set from another source, it wouldn't break the system.
4. The tabs no longer appear if the user doesn't exist and the url e.g. user/1245 is accessed.

Which we all seem agreed on.

With this done, I was running into problems with content which was authored by deleted users. Nodes were appearing as teasers and just "N/A" as body.

My opinion is that the content should be set to 'uid = 0' when the user is deleted, at least there should be an option.

So this patch also:

5. Sets uid=0 in the node table for all the nodes where uid=deleted_uid.

simon rawson’s picture

FileSize
5.2 KB

Couple of issues still.

One of them is my fault, because the patch I submitted last night had a silly mistake in it.

The patch I'm submitting does the following.

1. Users can now be deleted using the delete button from admin/users.
2. Users are now returned to admin/users if they delete a user and to user/number if they have just edited the profile.
3. A destination is not set when entering the user editing/deleting form from admin/users but if one was set from another source, it wouldn't break the system.
4. The tabs no longer appear if the user doesn't exist and the url e.g. user/1245 is accessed.

Which we all seem agreed on.

With this done, I was running into problems with content which was authored by deleted users. Nodes were appearing as teasers and just "N/A" as body.

My opinion is that the content should be set to 'uid = 0' when the user is deleted, at least there should be an option.

So this patch also:

5. Sets uid=0 in the node table for all the nodes where uid=deleted_uid.

dopry’s picture

+1,

just installed against HEAD, works as advertised...
I like user_load returning false instead of empty object.
slightly concerned about its implications else where,

blog.module, comment.module, contact.module, node.module,
profile.module, statistics.module, and tracker.module..

A cursory check say things will keep working...
most required changes will probably be minor..

ala blog.mode: 140
- if ($account->uid)
+ if ($account !== false)

If this patch gets commited I'll pick up the cleanup work.

dopry’s picture

hrm #26 applies to #23

UncleD’s picture

Status: Needs review » Reviewed & tested by the community

I just tested this patch against a fresh install of drupal HEAD cvs. It worked perfectly. At first before applying it, I couldn't delete my test user account. Then, after applying the patch, it properly prompted me to delete the user and the user deleted subsequently after confirming it.

I also checked the mysql database and the user was deleted from the database.

UncleD’s picture

My above post refers to user.module_24.patch (4.41 KB) by the way.

simon rawson’s picture

Don't you find this problem:

With this done, I was running into problems with content which was authored by deleted users. Nodes were appearing as teasers and just "N/A" as body.

with that patch?

m3avrck’s picture

Status: Reviewed & tested by the community » Needs work

I think that last problem about deleting users and having empty content is an entirely seperate issue. That has existed for quite a while now and needs to be tackled in a seperate issue.

Let's cleanup this patch and *not* set anything uid=0, get everything working like it should. simon can you revert that out of your patch?

After that is ready to go, let's focus on what to do after a user is deleted, proposed idea here: http://drupal.org/node/43674

simon rawson’s picture

Status: Needs work » Needs review
FileSize
5.12 KB

Ok, fair call.

This patch fixes all the issues with deleting users but does not do anything with their content (despite the warning message!).

Please review and RTC.

Dries’s picture

Haven't applied the patch but can't you put the new user_load after the 'if (arg(0) == 'user' && is_numeric(arg(1))) {'?

simon rawson’s picture

FileSize
5.1 KB

Yes, you can. New patch attached.

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
5.23 KB

updated patch against head, cleaned up some spacing issues with the last patch. ready to go now!

m3avrck’s picture

FileSize
5.2 KB

updated patch, test for !== FALSE instead.

m3avrck’s picture

Dries, please put a note in the commit:

Note: user_load() now returns FALSE if a user cannot be loaded, instead of an empty object

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed the patch. Thanks.

Dries’s picture

Status: Fixed » Closed (fixed)