Contact module has wrong access expression for displaying Contact tab in user account. When you have "administer users" permissions, you can see Contact tab in your own profile. But it's not reasonable, as even if you admin, it doesn't make sense to contact yourself.

Here are two patches fro D7 and D6 to fix that usability issue.

CommentFileSizeAuthor
#69 After-patch-contact.png184.25 KBMadhu kumar
#69 before-patch-contact.png171.43 KBMadhu kumar
#65 602234-after_patch.png42.48 KBAbhijith S
#65 602234-before_patch.png49.5 KBAbhijith S
#64 After.png79.07 KBanmolgoyal74
#64 Before.png65.79 KBanmolgoyal74
#62 interdiff_58-62.txt732 bytesadityasingh
#62 602234-62.patch3.3 KBadityasingh
#58 interdiff_51_58.txt805 bytesshaktik
#58 contact_yourself_tab-602234-58.patch3.24 KBshaktik
#52 Screenshot 2020-07-28 at 11.59.21 AM.png46.94 KBsamiullah
#52 Screenshot 2020-07-28 at 11.51.35 AM.png17.61 KBsamiullah
#51 602234-51.patch3.32 KBshaktik
#36 Contact-Tab-Drupal8.2.x.png38.97 KBsurbz
#31 contact_yourself_tab_in-602234-31.patch3.12 KBtalhaparacha
#31 contact_yourself_tab_in-test-only-602234-31.patch930 bytestalhaparacha
#28 contact_yourself_tab_in-602234-28.patch2.3 KBtalhaparacha
#28 contact_yourself_tab_in-test-only-602234-28.patch930 bytestalhaparacha
#23 contact_yourself_tab_in-602234-23.patch2.32 KBtalhaparacha
#23 contact_yourself_tab_in-602234-23.patch2.32 KBtalhaparacha
#18 self-contact-admin-test-only-602234-18.patch1.75 KBdrupal_was_my_past
#18 self-contact-admin-with-test-602234-18.patch2.6 KBdrupal_was_my_past
#16 User1ProfileWithoutPatch.png12.43 KBTor Arne Thune
#16 User1ProfileWithPatch.png6.5 KBTor Arne Thune
#16 User1ProfileWithPatchAsAnonymousUser.png8.68 KBTor Arne Thune
#15 self-contact-admin-test-only-602234-15.patch1.89 KBdrupal_was_my_past
#15 self-contact-admin-with-test-602234-15.patch2.75 KBdrupal_was_my_past
#13 self-contact-admin-test-only-602234-13.patch1.79 KBdrupal_was_my_past
#13 self-contact-admin-with-test-602234-13.patch2.66 KBdrupal_was_my_past
#6 otheruser.jpg10.67 KBdcor
#6 activeuser.jpg7.38 KBdcor
#2 contact-D7.patch738 bytesneochief
contact-D6.patch688 bytesneochief
contact-D7.patch963 bytesneochief
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

neochief’s picture

Status: Needs work » Needs review
FileSize
738 bytes
jim0203’s picture

Does what it says on the tin and, barring some crazy circumstance where someone would want to contact themselves, a good move. This is for the D7 patch btw; haven't looked at the D6 one.

neochief’s picture

yeah, crazy circumstance = dual personality :)

dcor’s picture

Assigned: Unassigned » dcor

reviewing

dcor’s picture

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

No problems with patches.

Works like a charm in D6... you have my stamp of approval. "Contact" tab is there under regular circumstances, apply the patch and "contact" tab disappears for my user but is still there for other users. Tried it in D7 too.

Attached are screen shots of d6..

dcor’s picture

Assigned: dcor » Unassigned

unassign

neochief’s picture

thanks for review!

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs review

Please include a simple test to make sure this stays fixed for both normal users and user-admin users.

Dave Reid’s picture

Status: Needs review » Needs work
gpk’s picture

Is is this simple? Since now in 7.x you can give anonymous users permission to view user contact forms, it would be odd if you can only view your own contact form if you are logged out.

See also #345541: Link to contact form in user account and e-mails leads to 403..

skirpichev’s picture

subscribe

drupal_was_my_past’s picture

Version: 7.x-dev » 8.x-dev
Assigned: Unassigned » drupal_was_my_past
Status: Needs work » Needs review
FileSize
2.66 KB
1.79 KB

Patch based on #2 with tests for review.

Status: Needs review » Needs work

The last submitted patch, self-contact-admin-with-test-602234-13.patch, failed testing.

drupal_was_my_past’s picture

Priority: Normal » Minor
Status: Needs work » Needs review
FileSize
2.75 KB
1.89 KB

Re-rolled patch from #13.

Tor Arne Thune’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
8.68 KB
6.5 KB
12.43 KB

Tested the patch in #15 with success. With the patch the contact page of user 1 is reachable as user 1, without it's not reachable (see attached screenshots 1 and 2). The contact form of user 1 is still accessible as an anonymous user with the "Use users' personal contact forms" permission (see attached screenshot 3).

I reviewed the patch and the code looks good and has the necessary tests so this looks RTBC to me. It basically just prevents the personal contact form tab access check from returning TRUE if the visitor tries to view his/her own contact form, while preserving the administrators' rights to view all users' personal contact forms. The "can not view own contact form" check was already there before but was not in the right order, leaving administrators with the possibility of viewing their own contact form.

Tor Arne Thune’s picture

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

This was committed to D8: a478bad.

drupal_was_my_past’s picture

Status: Patch (to be ported) » Needs review
FileSize
2.6 KB
1.75 KB

Here are the patches for 7.x.

Tor Arne Thune’s picture

Status: Needs review » Reviewed & tested by the community

Clean backport :)

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs review

I'm not sure this makes sense - if I'm an administrator who just turned on the Contact module, one of the first things I'd probably do is go to my own account and see if the tab is there (and probably try to contact myself also to test how it works).

I ran "git blame" to see when this code was originally added, and after a long slog through Git history I came across #70895: usability: don't show contact when viewing *own* profile. Reading the comments there, leaving the tab there for administrators was indeed done on purpose (and for the reason I mentioned above).

So personally I think this should be rolled back in Drupal 8. But maybe either way we need better code comments here to explain the logic of why the code does what it does.

andypost’s picture

Status: Needs review » Needs work

This needs re-roll for D8

krishworks’s picture

Version: 8.x-dev » 7.x-dev

the code discussed in 7.x patch is already in 8.x. See below taken from 8.x code as of today.

function _contact_personal_tab_access($account) {
  global $user;

  // Anonymous users cannot have contact forms.
  if (!$account->uid) {
    return FALSE;
  }

  // Users may not contact themselves.
  if ($user->uid == $account->uid) {
    return FALSE;
  }

  // User administrators should always have access to personal contact forms.
  if (user_access('administer users')) {
    return TRUE;
  }
talhaparacha’s picture

Version: 7.x-dev » 8.2.x-dev
Assigned: drupal_was_my_past » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.32 KB
2.32 KB

@David_Rothstein has rightly pointed in #20 that support for this functionality was intentionally added. But by looking at the code, it can be seen that the "can not view own contact form" check was also already there but was not in the right order, as explained in #16. So I think we have a bit of dilemma here and we need to make a decision now on whether the functionality should be removed or not.

If we go with removing this functionality (as was the original intent of this issue), then we can simply RTBC this issue. The fix for D8 has been committed. And I just tested that the patches from #18 still apply cleanly to D7 (commit # 1990861)

If we go with keeping this functionality, then we need to re-roll what got committed to D8 in #17. A patch is here in this regard.

In either case, the issue needs more review.

Status: Needs review » Needs work

The last submitted patch, 23: contact_yourself_tab_in-602234-23.patch, failed testing.

The last submitted patch, 23: contact_yourself_tab_in-602234-23.patch, failed testing.

talhaparacha’s picture

Status: Needs work » Needs review

Accidentally got the patch tested for D7. Though I don't know why the previous patch failed for D8. But lets make a decision first on what to do with this issue before working on the patch again...

andypost’s picture

Status: Needs review » Needs work
+++ b/core/modules/contact/src/Tests/ContactPersonalTest.php
@@ -116,14 +116,7 @@ function testPersonalContactAccess() {
-    $this->drupalLogout();
-    $this->drupalLogin($this->adminUser);
-    $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
-    $this->assertResponse(403);

tests should be fixed, not removed

talhaparacha’s picture

Fixed the test instead of removing it as per #27. Also, trying to fix what got the tests to fail in #23.

Again, the patch is intended to re-roll what got committed in #17 as per the suggestion in #20.

The last submitted patch, 28: contact_yourself_tab_in-test-only-602234-28.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: contact_yourself_tab_in-602234-28.patch, failed testing.

talhaparacha’s picture

This should pass the tests...

Status: Needs review » Needs work

The last submitted patch, 31: contact_yourself_tab_in-602234-31.patch, failed testing.

The last submitted patch, 31: contact_yourself_tab_in-test-only-602234-31.patch, failed testing.

talhaparacha’s picture

Status: Needs work » Needs review

Because retesting the patch went successful...

andypost’s picture

surbz’s picture

Version: 8.2.x-dev » 7.x-dev
Status: Needs review » Needs work
FileSize
38.97 KB

Hello, I installed drupal 8.2.x-dev and could not replicate the above issue.
Screen shot attached.
I also tried it with drupal 7.x-dev and could replicate it.

  • Dries committed a478bad on 8.3.x
    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user...

  • Dries committed a478bad on 8.3.x
    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user...

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.

  • Dries committed a478bad on 8.4.x
    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user...

  • Dries committed a478bad on 8.4.x
    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user...

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.

  • Dries committed a478bad on 9.1.x
    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user...

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.

shaktik’s picture

Status: Needs work » Needs review
FileSize
3.32 KB

Create a patch for 9.1 and tested on my local working fine, kindly check.

samiullah’s picture

Tested the patch on local clean install of drupal 9.1x

1. Before applying patch contact link is not visible in user profile
2. After applying patch contact link is visible
3. Anonymous user get access denied if they access particular users form example /user/1/contact
4. if authenticated user tried to access different users contact form he gets page not found example if user with uid 1 tries to access form of user with id 3 /user/3/contact

Looks good, waiting for tests to PASS
This can be moved to RTBC if code review is also fine

mayurjadhav’s picture

Patch applied cleanly on drupal 9.1x, Patch looks good, +1 for RTBC.

samiullah’s picture

Status: Needs review » Reviewed & tested by the community

larowlan credited Dries.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update
+++ b/core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php
@@ -71,9 +71,8 @@ public function testContactLink() {
+    // The admin user has access to all contact links including his own.

Let's not use gendered language here - their own was in the original comment, let's retain that

It's not clear what the remaining tasks of this issue are, it was committed in Mar 2020, but there's still a patch.

Can we get an issue summary update reflecting why the issue is still open? Thanks.

larowlan’s picture

Issue tags: +Bug Smash Initiative
shaktik’s picture

Status: Needs work » Needs review
FileSize
3.24 KB
805 bytes

Hi @larowlan,

Just updated for

Let's not use gendered language here - their own was in the original comment, let's retain that

, kindly check.

Thanks,
Shakti.

samiullah’s picture

Comment change looks good, waiting for review from @larowlan

quietone’s picture

Status: Needs review » Needs work

Setting NW for the issue summary update requested in #56.

+++ b/core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php
@@ -71,7 +71,7 @@ public function testContactLink() {
+    // The admin user has access to all contact links beside their own.

Personally, I think 'including their own' is easier to read.

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.

adityasingh’s picture

Status: Needs work » Needs review
FileSize
3.3 KB
732 bytes

Agree with #60
updated patch as suggested in #60.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Novice, +Needs screenshots

@adityasingh, thanks for the reroll.

This needs an issue summary update, requested in #56 and #62. To assist that process I have added the issue summary template and trimmed it to only those sections that need to be finished before this can be marked RTBC. The general guidelines for summaries provides guidance on what needs to be added. This work is suitable for a novice.

Oh, up to date screenshots are needed, I've marked a place in the issue summary where they can be added. I don't know if the screen shots from #52 are up to date. I haven't looked at the changes to the patch.

anmolgoyal74’s picture

Status: Needs work » Needs review
Issue tags: -Needs screenshots
FileSize
65.79 KB
79.07 KB

Adding screenshots.

Abhijith S’s picture

Applied patch #62 and it works fine.

Before patch:
before

After patch:
after

guilhermevp’s picture

Issue summary: View changes

I was unable to reproduce the error in in 9.2.x. As far I understood the point of the issue is to be unable to contact yourself, and as it is in 9.2.x seems impossible to do so. Maybe I'm doing something wrong. I have interest in filling the summary update but I could use steps to recreate the issue.

guilhermevp’s picture

Issue summary: View changes
quietone’s picture

Issue tags: -Novice

@guilhermevp, Welcome to Drupal. I too am finding this a bit confusing and like you I find that this is already fixed.

So what needs to be done? I read through the issue and found the answer in, #20. It points out that this overrides decisions made in an earlier patch. That history should be in the Issue Summary, enough so reviewers understand the problem. And in the 'remaining tasks' to state the next step, like 'Decide if the ability for the admin to contact themselves should be removed' and thus remove the capabilities pointed to in the issue referred to in #20.

@guilhermevp, would you like to work on the Issue Summary update?

Madhu kumar’s picture

@guilhermevp I was able to find the error in in 9.2.x. Added screenshot for the reference.
patch #62 applied cleanly and working as expected.

guilhermevp’s picture

Issue summary: View changes

@quietone

I dabbled in making a summary update. Let me know what you think.

guilhermevp’s picture

Issue summary: View changes
quietone’s picture

@guilhermevp, Very nice update. Good job! To further improve it this string "who just turned" can be changed to "who had just turned" and instead of the link with the text, 'this issue', change it to

[#70895]

which will expand it to show the issue number and issue title.

Putting on my reviewers hat, I think this can be further improved to make it easier for a reviewer. The first thing I notice is the title. Is it accurate? I don't think so because not we are deciding whether to have the tab or not. Maybe change it to 'Should the Contact yourself tab be in the user profile for the admin'. What do you think?

The next thing it would be helpful to know is that this issue was committed. Since it is not so common that an issue continues after commit (and not a backport) let's emphasize that. In the fist section, problem/motivation add a beginning paragraph. Something like this "This issue was committed in commit (put the hash link here) and then in #20 David_Rothstein pointed out that the behavior was a deliberate choice in #70895: usability: don't show contact when viewing *own* profile. The issue is currently to discuss whether to restore the previous behavior or not."

Then, there are a lot of blank sections. As a reviewer I don't know if these are to be filled out later or not. So for 'steps to reproduce' I search the issue to see if is they are available in a comment and then copy/paste. If not, either add it myself or add TBA (to be added). In this case, 'TBA' is fine. And in 'Proposed resolution' I would add the two choices.

Either keep the current behavior, no contact tab for the admin on their profile page
or
Restore the contact tab for the admin on their profile page

And then, to finish off the sections, in 'user interface changes' add 'TBD'.

@guilhermevp, looking forward to your changes!

quietone’s picture

@Madhu kumar, Remember to read the issue before adding a comment. The screenshots you have added were already added in #65.

guilhermevp’s picture

Title: Contact yourself tab in user profile when you're admin » Should the Admin be able to contact themself in the user profile
Issue summary: View changes

@quietone

Thanks for the feeback, I tried to change things a bit from your suggestions, but most of it was just perfect summarization of the updates the issue needed. Again, thanks!

guilhermevp’s picture

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.

pameeela’s picture

Title: Should the Admin be able to contact themself in the user profile » Users with 'Administer users' permission should be able to use their own contact form
Issue tags: +Needs issue summary update

Can someone who has worked on this lately update the issue summary with steps to reproduce the issue identified (this makes it easier to test that it is fixed) as well as the details of the proposed approach?

bnjmnm’s picture

Issue tags: +Needs followup

I recommend closing this issue and creating a new one that references it. Even if the issue summary is cleaned up, the comment history will more likely confuse than it will help. That commit history is bizarre/

@guilhermevp did a great job updating the issue summary, and some of his beneficial changes have already been reverted. This is a very old issue that started in 7.x. A new issue can repeat the valuable parts from here, but remove the noise.

I think the issue title of "Should the Admin be able to contact themself in the user profile" that @guilhermevp is the right approach. We need to determine if that is an acceptable change before anything is altered. This is still being interpreted as a bug when it isn't a bug. It's currently expected behavior (that I wouldn't mind seeing changed 🙂).

If you don't agree, remove the "needs followup" tag, but I think it will vastly increase the likelihood of contributors understanding what is going on.

pameeela’s picture

Title: Users with 'Administer users' permission should be able to use their own contact form » Don't allow admin users to access their own contact form
Issue summary: View changes
Status: Needs review » Fixed
Related issues: +#3221619: Allow users with 'Administer users' permission to use their own contact form

I agree, this is really confusing. Also agree it's not a bug since it was an intentional change. The only problem with closing this to create a new issue is there is a valid patch.

I've created #3221619: Allow users with 'Administer users' permission to use their own contact form. @adityasingh you can upload your patch to that issue but I wouldn't mark it Needs Review until there is consensus that the change should be made.

I'm also updating the issue back to the original title and summary so that it's clear what was actually changed here.

bnjmnm’s picture

Status: Fixed » Closed (outdated)

Thanks @pameeela! I updated [##3221619] with the patch from here, documented that the contributors from this issue should receive credit if it lands, and tagged it to hopefully get product manager approval on making a users own contact form visible.

pameeela’s picture

I believe this should be marked as ‘Fixed’ since it was committed to 8.x way back when. But now I’m not sure because there’s just a comment linking to a commit so maybe it was committed via another issue.

quietone’s picture

Status: Closed (outdated) » Fixed
Issue tags: -Needs followup

@bnjmnm and @pameeela, thanks for sorting this out. It has been in my too hard basket for a while now.

I can confirm this was committed. changing fixed. The followup has been created, removing tag.

commit a478badbf8b1e7fe28fb0680272aa70845393268
Author: Dries <dries@buytaert.net>
Date:   Fri Jun 29 09:55:56 2012 -0400

    - Patch #602234 by rocket_nova, neochief: contact yourself tab in user profile when you're admin.

Status: Fixed » Closed (fixed)

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