Starting with a fresh install of D7 alpha7 installed with an SQLite DB.
The admin account is the only account, if you go to user/1/edit you can block your account yourself.
You can't reverse because your account is blocked.

I think that an user must not be able to block is account.

Comments

derjochenmeyer’s picture

Title: Admin user can block is account isself » Any user should not be allowed to block his/her own account
Version: 7.0-alpha7 » 7.x-dev
Status: Active » Needs review
StatusFileSize
new434 bytes

Attached patch disables the status options for the active user for his/her own account.

danillonunes’s picture

I think that expression ? TRUE : FALSE is a little redundant. Is there some code standard for this? If not, it can be simplified to '#disabled' => $user->uid == $account->uid.

derjochenmeyer’s picture

StatusFileSize
new483 bytes

I did a grep search for $user->uid == $account->uid, its commonly used throughout drupal.

New patch implements suggestion #1.

derjochenmeyer’s picture

StatusFileSize
new419 bytes

Here's the right patch.

danillonunes’s picture

Great! +1 for RTBC in #4.

moshe weitzman’s picture

Related issue from the days before one could cancel own account - #119683: User administrators should not be able to delete their own accounts

rschwab’s picture

Status: Needs review » Reviewed & tested by the community

I can't think of any reason a user would need/want to block their own account, and this patch applies cleanly and works as intended.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I think this makes sense, but should come with tests.

rschwab’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB

This patch makes the change in #4 and also adds a test to make sure the Block account radio button is disabled. This is my first attempt at writing a test so please bear with me if I've made some horrible mistakes (that and the crazy hour that I'm awake trying to do this)!

:)

rschwab’s picture

Version: 7.x-dev » 8.x-dev
tstoeckler’s picture

Status: Needs review » Needs work

From http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

Note that disabling a form field doesn't necessarily prevent someone from submitting a value through DOM manipulation.

#disabled is not correct here. We should merge the condition into #access.

larowlan’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.23 KB

New patch attached

larowlan’s picture

Issue tags: +Needs backport to D7

Tagging for D7 backport

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

That looks perfectly reasonable, and bot is happy.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Security improvements
+++ b/modules/user/user.test
@@ -1268,6 +1268,12 @@ class UserAdminTestCase extends DrupalWebTestCase {
+    // Test that a user cannot block their own account (See #920250)

We don't usually include issue numbers, unless the issue contains in-depth discussions and background information which is too much to include in-code. In this code, we can just drop it, I think. Also there should be a period at the end of the sentence.

Leaving at RTBC and marking as "Security improvement".

-3 days to next Drupal core point release.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.22 KB

Darn you Dreditor! :)
Anyway, quick reroll for the comment fix I mentioned above.

tstoeckler’s picture

And yes, I'm marking my own patch RTBC, because I only touched one line of comments and in a very trivial way. Feel free to mark "needs review", I won't fight it.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 920250-13.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.24 KB

Oops, this was pre-/core...

Still RTBC if it's green.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 920250-14.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.26 KB

Sorry for the noise, this one should really work.

moshe weitzman’s picture

Thanks for reroll. Looks good.

I'd argue that the Test is not needed. The #access system is tested elsewhere. Browser based tests like these slow our suite down a little bit so there should be tangible benefit from each. I think the committer can choose to omit that hunk if they agree. I'm OK either way.

sun’s picture

+++ b/core/modules/user/user.test
@@ -1268,6 +1268,12 @@ class UserAdminTestCase extends DrupalWebTestCase {
+    $element = $this->xpath('//input[@id="edit-status-0"]');
+    $this->assertEqual(count($element), 0, t('Radio button to block own account was not found.'));

Usage of assertNoFieldByName() would be more appropriate here.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Novice

Thanks @moshe weitzman, @sun, @tstoeckler. Improving the assertion as sun suggests in #23 would make a good novice task, so marking needs work and tagging for that. Thanks!

benjf’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

new patch using sun's suggestion above.

tstoeckler’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.test
@@ -1268,6 +1268,11 @@ class UserAdminTestCase extends DrupalWebTestCase {
+    ¶

There is trailing whitespace here.

-10 days to next Drupal core point release.

devin carlson’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

Removed trailing whitespace.

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @benjf and @Devin Carlson!

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.x. Moving back to 7.x for backport.

albert volkman’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.16 KB

D7 backport.

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

Yeah! Thanks!

David_Rothstein’s picture

Title: Any user should not be allowed to block his/her own account » Users should not be able to easily to block their own account (i.e., without email confirmation)
Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: -Security improvements, -Novice

This issue title is a little misleading... Users should definitely be able to block their own accounts, and they can still do it both before and after this patch. That's one of the main use cases of the "Cancel account" button.

So, I'm changing the issue title to what I think was the actual intent here. I don't see how this is a security improvement, actually. It's more of a usability issue.

Given that, we should discuss whether this patch was complete? It addressed the user edit form, but not the bulk edit form at admin/people. I think that's inconsistent; it's just as easy (and maybe even easier) to accidentally block yourself there. If we stop it in one place, we should stop it in the other too. That's consistent with what we do for cancelling the user 1 account also (it's prevented in both places).

And:

-    '#access' => $admin,
+    '#access' => $admin && ($user->uid != $account->uid),

It's pretty minor, but we should add a !empty($account->uid) check there too. Yes, the use case is close to zero.... but there are setups where granting anonymous users "administer users" permission actually does make sense, so we shouldn't prevent them from creating new accounts with whatever status they want in that case.

David_Rothstein’s picture

It's pretty minor, but we should add a !empty($account->uid) check there too.

To clarify what I meant above, I guess what I'm actually saying is that it should be this:

'#access' => $admin && (empty($account->uid) || $user->uid != $account->uid),

***

By the way, a somewhat related issue to this one is here: #472074: Don't let the all administrator accounts get blocked

catch’s picture

Hmm, that makes sense. I've reverted the commit to 8.x so we can discuss this more.

klonos’s picture

This seems like a pretty trivial thing that's been bugging me since D6, but there's no movement (not here neither in #472074: Don't let the all administrator accounts get blocked). Can we come to an agreement and get on with this?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Version: 8.2.x-dev » 8.3.x-dev
Issue summary: View changes

It's mildly humorous that this is still an issue.

For reference, since the commits did not contain issue ID's:

Patch was originally committed to 8.x in #920250-29: Users should not be able to easily to block their own account (i.e., without email confirmation), Ref #1ab05706

Then the patch was reverted in #920250-34: Users should not be able to easily to block their own account (i.e., without email confirmation), Ref #e3a6372c

sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Patch #27 does not apply. Here is a new patch if we need this.

Status: Needs review » Needs work

The last submitted patch, 39: 920250-39.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

Category: Bug report » Feature request
Issue tags: +Bug Smash Initiative

This came up as a Bug Smash Initiative daily triage target.

Discussed this in the #bugsmash channel with @catch and we felt this should be seen as a feature. There is a clear benefit to user 1 not being able to block user 1, the wider scope might not be something that is wanted on every install. Judging by the lack of activity, this is not something that is relevant for a lot of sites.

As always, feel free to move this back if you believe this does feel like a bug.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new2.03 KB

I've added reroll of the patch #39 on Drupal 9.5.x., This issue still exists.

Status: Needs review » Needs work

The last submitted patch, 53: 920250-53.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB
new726 bytes

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new969 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.