Problem/Motivation
Users should not be able to registered with name Anonymous
Steps to reproduce
Create a new user with name Anonymous
Verify account was saved
Proposed resolution
Don't allow the system to save when anonymous is used
Remaining tasks
Review issue summary
Agree on approach
Review commit
Commit
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
NA
Original Post
If there is a user registered as 'Anonymous', unregistered users cannot be offered a default name 'Anonymous' in the comment form. Better to leave the name field blank in any case.
Comments
Comment #1
bleen commentedI think the original post is actually a symptom of a larger issue. We should not let users register using the name that we are using for the Anonymous user. Similarly, we should not be able to set the anonymous user name to the name of a user that already exists.
This patch fixes this (and thus fixes the original issue).
Comment #2
rayasa commentedThank you. But, the patch just addresses a part of the issue. Although the user name registration is case sensitive, user name validation in the comment form and configuration -> account settings is not so.
I mean, if some user registers as 'anonymous', an unregistered user cannot use the default comment-form name as 'Anonymous'.
Comment #3
bleen commentedso would the patch in #1 + a case insensitive comment name check solve this?
Comment #4
rayasa commentedI guess so. A case sensitive name check in both the comment form and configuration - account settings should work just fine.
Comment #5
bleen commentedWill play with this a bit later
Comment #6
bleen commentedrayasa: Actually, I think the patch in #1 does completely address the issue.
Lets say we have a default drupal install... the anon user is called 'Anonymous'. With the patch in #1 a user cannot register with the name "Anonymous" therefore a user commenting with "Anonymous" in the name field is fine. If a user registers as "anonymous" then there is still no problem because if someone tries to comment as "anonymous" they will get an error that there is a user registered as "anonymous".
In another case, lets say that our anonymous user name is set as "Bob"... The comment form will be pre-populated with "Bob" in the name field which is fine. And again, if a user tries to register as "Bob" he will get an error and not be able to.
Finally if the site admin tries to change the anonymous user name to "George" and there is already a registered username with that name, the patch in #1 throws an error and tells the site admin to pick something else.
I think that is every possible case covered ...
Am I missing anything?
Comment #7
rayasa commentedYou covered all the cases, but still missed the point. Now consider the following scenario where the patch at #1 wont help:
-> Fresh drupal install with all modules and settings required by this scenario turned on.
-> The install sets the name of unregistered user as 'Anonymous'
-> The default name in the comment form for unregistered user is set to 'Anonymous'.
-> The unregistered user can comment keeping the default name (no errors yet)
-> Now a new user registers as 'anonymous' (which is possible due to case sensitive user name registration)
-> Still, Drupal offers the default name in comment form as 'Anonymous' to the unregistered user
-> Now when the unregistered user tries to comment keeping the default name, there is an error saying the name is registered. But, here the name "anonymous" is regisetered and not "Anonymous".
So, the point is, Drupal should not offer a default comment form name to an unregistered user that can fail if used. Or, there should be a case sensitive check in the comment name, that will allow unregistered user to comment with "Anonymous" even if there is a user named "anonymous"
Comment #8
bleen commentedThis patch does not allow a user to register as "Anonymous" or "anoNymous" (assuming that is the value of variable_get('anonymous') ... so you can never run into the situation you describe in #7
Comment #9
rayasa commentedThis works for me. :)
Comment #10
Anonymous (not verified) commentedReviewed and tested.
This patch:
Comment #11
dries commentedPatch has some code style issues; tabs, abbreviation of 'anonymous', etc.
Comment #12
bleen commentedblaaarg ... been testing out Firefox4 and there is no Dreditor yet :(
How's this
Comment #13
Anonymous (not verified) commentedWhoops, sorry, I should have caught that.
Anonymous is still abbreviated, I think this was one of the code style problems Dries was referencing.
Comment #14
bleen commentedlinclark ... where is anonymous abbreviated? I think I got them all.
Comment #15
Anonymous (not verified) commentedSorry bleen, turns out that I was having an issue with Dreditor (#907942: Hide button leads to wrong patch being shown).
I think that all the code style issues have been fixed, but I'm going to check in IRC to see if anyone more experienced can check code style.
Comment #16
Anonymous (not verified) commentedComment #17
Anonymous (not verified) commentedOk, I didn't get any responses from IC and I think that all the coding style stuff is ok in the patch now, so I'm going to RTBC (sorry if I'm wrong Dries/webchick!)
Comment #18
sun"Form validation handler for the user settings form."
Have a look at http://drupal.org/node/310075 and other code in core to see how we write dynamic database queries.
The error message looks a bit lengthy to me. Please try to shorten it without losing information.
1) Read http://drupal.org/node/473460 about Drupal's PHP Unicode wrapper functions. Full list of wrappers: http://api.drupal.org/api/group/php_wrappers/7
2) When a user registers in a non-English language, this does not check for the non-localized version of "Anonymous".
1) Quotes around %anonymous need to be removed. Afterwards, the surrounding double-quotes can be turned into single-quotes.
2) %anonymous should be %name, for consistency with the other messages.
3) Speaking of, the other messages do not seem to use any second "Please..." sentence.
Powered by Dreditor.
Comment #19
bleen commentedThis patch takes care of all the suggestion from sun in #18 except for changing the dynamic query. I basically took that query from here:
Can you be more specific about how I should do this differently
Comment #20
alexpottRerolled for Drupal 8, added tests and took the opportunity to convert
Drupal\user\Tests\UserValidationTesttoDrupalUnitTestBaseComment #21
sunHat tip: Whenever user permissions are irrelevant:
That logs in uid 1. Only available in D8 web tests.
Can we remove the custom assertion message here? It duplicates the raw text assertion.
If I'd get that error message, I'd like to see that user account. I think it would be helpful to turn the placeholder into a link.
To make that work, we could use user_load_by_name() instead of the $name_taken query.
I don't think we have to care for user-view permissions, since the administrative user who has access to these account settings most likely also has access to view user accounts.
Hm. I thought the
t('!anonymous')is obsolete in D8?Granted, there's no config translation system yet, but at least I was fairly sure that we've removed
t()from all dynamic/config strings in the meantime.Comment #22
alexpottImplemented suggestions from #21.
Really like the use of user_load_by_name() in admin_settings_validate() - makes the patch nice and tidy :)
Comment #23
sunI think we need to use $account->uri() for the URL here, like this:
$uri = $account->uri();
url($uri['path'], $uri['options'])
Comment #24
alexpottAhhh,,, learnt a new thing today :) thanks for the review.
Comment #25
sunThanks!
Comment #26
webchickThis is a good idea, but what's the upgrade path look like? From what I can tell, someone who was already pre-registered with the name "Anonymous" (or whatever) can no longer log in / edit their profile / etc. with this change?
Comment #27
sunErm. That's what support@example.com is for. I don't think we should care for that 0.01% case. Those sites have a registered user who posts as Anonymous in the first place, ... and by the looks of it, that's the bug which triggered this very issue, so ???
:)
Comment #28
alexpottWell the only way of doing this is probably something like this - which I'm not sure I particularly like but will prevent sites from getting in the situation @webchick describes in #26.
Comment #29
sunI'm really not sure I understand the logic for needing extra care for existing sites. Here's why:
A) Sites that are not experiencing this bug do not care.
B) Sites that are experiencing this bug want a straight fix.
C) Sites that are experiencing this bug, but are not aware of it, will face one of these two situations:
C.1) The site administrator attempts to update the administrative user settings form. An error is displayed that the existing (unchanged) value for "Anonymous" conflicts with an existing username. The site administrator needs to fix it in whichever way he prefers.
C.2) The user with the username that clashes with "Anonymous" attempts to update his own user profile. Only in case users are permitted to change their username, the existing (unchanged) username will be validated upon form submission. The user is asked to choose a different name. The user will either do that, or consult the site administrator to learn what's going on. The displayed error message clarifies that the chosen username clashes with a reserved username.
Am I missing something?
Comment #30
jibran#28: 903606.28.patch queued for re-testing.
Comment #40
pameeela commentedThis is covered in #472202: 'Name' value for anonymous comments can conflict with registered usernames. Closing this and will transfer credit over there.
Comment #41
pameeela commentedIn #472202-41: 'Name' value for anonymous comments can conflict with registered usernames @joachim suggested this problem is wider than comments, e.g. node author.
Did a bit of testing and there is no error on node creation by an anonymous if there is a registered user Anonymous. I think this is because it specifically references 'Anonymous (0)' so it's not just validating the plain text against the list of users.
I also don't think it's that confusing because as I pointed out in #472202-35: 'Name' value for anonymous comments can conflict with registered usernames the registered username is linked and the anon one says (not verified) and the same is true for nodes.
Creating a node as anon with author 'Anonymous'

Node created by anonymous user vs. node created by user 'Anonymous'

So unless there are other issues arising from having a user with the anonymous username, I think this can stay closed. The error that occurs on the comment form is covered in the other issue.
Comment #42
joachim commentedI think you're misunderstanding the bug.
This bug is not to do with content creation by anonymous users.
This bug is that you should not be allowed to register a user account with the username 'Anonymous', or 'Anonymous (not verified)' because it's confusing to see user labels on the site that look identical but refer to 2 totally different things.
(Conversely, you should not be allowed to change the configuration for anonymous user label (at admin/config/people/accounts) to a string that matches an existing username.)
I am reopening this because it really is a different bug from #472202: 'Name' value for anonymous comments can conflict with registered usernames. This bug occurs without comment module enabled. The other bug is only to do with comment module.
Comment #43
pameeela commentedI understand but I don’t agree that it’s confusing. Fair enough though, it’s OK to disagree.
But this needs an issue summary update at least to clarify that the intention is not to resolve a specific error but prevent the possibility of a clash.
Comment #46
mohit_aghera commentedI've implemented following changes:
Other changes related to hook_requirement():
I haven't included above
hook_requirement()implementation as I am not sure if it is required.@alexpott, can you please confirm whether these changes are required.
Let's see how many test cases get affected.
Comment #50
smustgrave commentedFor IS update
Comment #51
smustgrave commentedUpdated IS but leaving the tag for someone to confirm.
Also MR needs to be updated to point to 9.5.x please
Comment #53
bhanu951 commentedComment #54
bhanu951 commentedRebased the MR #909 against 11.x branch and pushed changes.
Comment #55
smustgrave commentedLeft some comments on the MR.