Problem/Motivation
When an admin sends an email to a user via the personal contact form, it has this message:
Brad Landis (site/user/1) has sent you a message via your
contact form (site/user/12/contact) at siteName.If you don't want to receive such e-mails, you can change your settings at
site/user/12.
But even if you change the settings, the admin can still contact you. If the admin user sends the email, this message should not be included.
Steps to reproduce
- Install Drupal
- Enable contact module
- Create a non-admin user and opt out of the personal contact form
- Visit that user's profile as an admin and see that you can still contact them via the form
- Send a message to an email address you have access to and confirm it includes text about how to opt out, even though you can't opt out of emails from admins
Proposed resolution
Don't include the opt-out text line in emails from users with 'Administer users' permission.
Remaining tasks
- Convert existing patch to MR
- Review
- Commit
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|
Issue fork drupal-124969
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
marcingy commentedAlso affects 5.1.
Patch for 5.1 uploaded
Comment #2
catchNo longer applies and should use two spaces instead of tabs for indentation. If this is still valid in D6 it'd be a nice one to fix.
Comment #3
stevenpatzHere's an updated patch. Should we be checking for uid==1, or uid > 1?
Comment #4
stevenpatzactual patch this time.
Comment #5
catchI would think > 1, or even <> 1 to allow for anonymous contact form submissions.
Comment #6
marcingy commentedThe value has be uid == 1 as this fix is to supress the message being displayed for the administrator.
Comment #7
dave reidThe logic so far is incorrect. It's perfectly valid for me as user/1 to be able to turn off my contact form, so why should that line be hidden? We should *not* show this line if the user that *sent* the e-mail has the 'administer users' permission, since they can always send contact e-mails. We also shouldn't send that line if the e-mail is the copy sent to the sender.
With the attached patch, the only time the contact form opt-out line will show up is in the original e-mails to the recipient, and only if the e-mail was sent by a user without the 'administer users' permission'.
Comment #8
cburschkaThis makes sense, but a one-line comment above it would be great. It's not immediately obvious why you don't want to show the opt-out message in these cases, without mentioning that a user-administror can override the opt-out, and that
$key == 'user_mail'filters out sender copies.Comment #9
dave reidComment #10
dave reidRevised patch for review. Arancaytar does this look good?
Comment #11
dave reidRe-rolled for latest commits.
Comment #13
dave reidFixes the testbot exceptions.
Comment #14
dave reidAdding tags
Comment #15
andypostThis patch is simple so I see no reason in Tests. But +1 for port to D6
Comment #17
andypostNeed re-roll
Comment #18
dave reidNo need to rush on any bug reports like this, we still have plenty of time to fix them. :) Re-rolled for latest changes.
Comment #19
naxoc commentedIt makes a lot of sense only to have the opt-out in the e-mail when there is an actual chance of opting out. I wrote a test for it.
Comment #20
batje commentedLooks good. Test runs flawless, and the patch makes a lot of sense.
Comment #21
dries commentedThis looks really good. Some minor comments:
It would be great if we could split this up in 2 lines or so. The inline check is a bit ugly.
For consistency, it might be sense to treat the check above identical. That is, explicitly test the return value of strpos, probably using '!==' and '==' instead of '!=' and '=='.
Comment #22
naxoc commentedAll the comparison using strpos became really confusing, so I am using strstr instead because it has return values that are easier and prettier to work with. It will be marginally slower..
Comment #23
dries commentedstrstr() will not return TRUE so I feel that check is misleading. Let's continue to work with strpos().
Comment #24
naxoc commentedHere is some rearranging of boolean comparisons. This is hopefully less confusing :)
Comment #25
naxoc commentedHere is a reroll for D8.
Comment #26
kscheirerPatch looks clean and there's a test included, nice work! Removed tags since the patch has a test, and there won't be a backport to D6. RTBC from me unless the testbot complains.
Comment #27
kscheirer#25: 124969-25.patch queued for re-testing.
Comment #29
andypostComment #30
larowlanComment #31
amitgoyal commentedReroll of #25.
Comment #45
danielvezaLooking at the code, the text will still be included on emails sent from the admin users.
Needs a reroll
Comment #46
yogeshmpawarUpdated patch with reroll diff.
Comment #48
danielvezauser_access has been removed - See the change record
Comment #49
larowlanComment #50
_pratik_Comment #51
_pratik_Rerolled #46. Attached diff for reference.
Comment #53
andregp commentedThe tests are failing, I'll see if I can fix it.
Comment #54
andregp commentedIt took me a while to figure out all the little errors here and there, but I finally got it.
Fixed all errors (mainly typos, wrong function names, missing calls), removed t() call from the test, moved the comment at ContactPersonalTest.php to before the if statement, as it seems to make more sense there, and rephrased some comments at contact.module to make them more concise.
Sending also a tests-only patch (expected to fail).
Comment #56
rootworkShould still be a good novice task to review.
Comment #57
mstrelan commentedThe strpos and assertTrue is a bit awkward, can we use assertStringContainsString and assertStringNotContainsString instead?
Nit: we should be using === here.
Comment #58
andregp commented@mstrelan, thanks for the feedback!
#57.1 Sure! I'll change that.
#57.2 Okay.
Comment #59
andregp commentedUpdated patch as per #57.
Comment #61
Johnny Santos commentedGoing for the review
Comment #62
Johnny Santos commentedI applied the patch and reviewed the code, looks good to me, just as demanded on the issue.
Adding screenshots.
you can see that the second paragraph it's absent.
Comment #68
quietone commentedI noticed this because it is on 9.3.x and then re-testing a fail patch every two days.
This needs to be on 10.0.x, changing version. And I took a brief look at the patch and suggest two changes to comments.
This work is suitable for a first time contributor, adding tag.
That doesn't read well to me. How about 'Tests if the opt-out message is included correctly in contact emails.'
What is a 'normal user'? Lets makes this specific,
'// Send an email from a non admin user (should contain the opt-out message).'
Comment #69
ravi.shankar commentedMade changes as per comment #68.
Comment #70
paulocsLooks good now! Indeed the message suggested by @quietone is cleaner.
Moving to RTBC.
Comment #72
andregp commentedUnrelated random fail. Restoring status.
Comment #74
andregp commentedRandom fail again. Restoring status.
Comment #75
larowlanI think this is redundant?
$params['sender'] is the user,
Its like
$user = User::load($user->id());So I think it can just be
$params['sender']->hasPermissions(...)Is there any need to put $user_access in a variable if we only use it once?
We have a mix of emails (in the code) and e-mails in the comment. We should standardize on one. Given 'email' exists in the original code, should we use that in the comments too?
Can we add
:voidtypehint here.We can use
\Drupal\Core\Test\AssertMailTrait::assertMailStringhereComment #76
ravi.shankar commentedAddressed points 1, 2, and 4 of comment #75, but still needs work for the remaining points of comment #75.
Comment #77
ravi.shankar commentedSorry, forgot to add interdiff in #76 so added here.
Comment #78
bruno.bicudoI don't know if i understood #75.3 well, but i changed the text from "e-mails" to "messages" (sorry if i misunderstood that one).
I also changed
assertStringContainsStringtoassertMailStringas told at #75.5Hope it helps. Kindly review it :)
Comment #79
bruno.bicudoI didn't pay attention to the assertion changes, sorry for #78.
I've corrected everything now. Still:
Hope it helps. Kindly review it :)
Comment #80
bruno.bicudoComment #81
anmolgoyal74 commentedI have tested the patch in #79. It is working as expected.


Before
After
Comment #82
alexpottThe user-copy not having this makes sense. Nice one. But it's not tested. Let's add a test for that as well.
I think we can adjust \Drupal\Tests\contact\Functional\ContactPersonalTest::submitPersonalContact() to have accept a bool for the send your self a copy and then use this in the new test.
Comment #83
jnlarTried writing the new test testing against user-copy emails as per @alexpott request, and some changes to the patch in #79:
This will always evaluate to true,
assertMailStringdoesn't check if the string isn't there so I replaced it withassertStringNotContainsString.Comment #84
jnlarComment #85
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Won't tag for it but this could use an issue summary update to match the standard template. Not the most clear.
Can verify this problem on D10
Think this needs some work though
Created userA and userB
userB is content editor with permissions to administer user (so they can see users) and permission to contact user
UserA opted out of contact form
Login as userB I would expect to not see the contact tab for userA but I do and can send an email
userA received an email with the
Comment #87
pameeela commentedDiscussed in Slack, I think that the tab access issue mentioned in #85 is out of scope, this issue is to address the email text only. And if the email text is corrected, it's not unexpected that admins can view your contact tab, because as the OP notes, admins can still contact you even if you have opted out.
So in the interest of seeing this resolved, I think it should only be concerned with the email content.
Edit: For clarity, if the access issue were resolved, then the email text wouldn't need to be updated. The email text change is necessary because access to the form is not restricted for user admins.
Comment #88
pameeela commentedUpdated issue summary.
Comment #90
pameeela commentedMR created.
Comment #91
smustgrave commentedHiding patches for clarity.
Ran test-only feature
As mentioned in slack #85 is out of scope for this issue and can be ignored.
Issue summary is clear about the problem and steps to show the issue.
When applying the MR and following the steps I get the expected behavior.
Believe this long standing bug is good to go.
Comment #92
alexpottCommitted and pushed 1dbf2cc2ea to 11.x and e1a29d0851 to 10.3.x and 5fa98acae9 to 10.2.x. Thanks!