Usability: Remove inappropriate "Login or register to post comments" links

salvis - November 25, 2007 - 15:22
Project:Drupal
Version:5.x-dev
Component:comment.module
Category:bug report
Priority:normal
Assigned:tanper
Status:closed
Description

If the authenticated user role does not have the 'post comments' permission, then the "Login or register to post comments" links are inappropriate, because the user may not be able to post comments even after logging in.

Users in that position might see this as a broken promise. This problem may be the reason for inventing the "you can't post comments" text (see http://drupal.org/node/137100), but that text doesn't solve the problem at all, on the contrary: it's a constant reminder of the broken promise and the fact that the user apparently belongs to a lesser user category.

I propose to remove "Login or register to post comments", if the authenticated user role does not have 'post comments' permission.

See also http://drupal.org/node/169938.

#1

catch - November 26, 2007 - 11:40

+1 on this, not too hard to do but probably best dealt with in a general cleanup of comment module.

#2

mcarbone - December 7, 2007 - 01:12
Status:active» needs review

Here's a patch that addresses this problem, but I narrowed the application a bit from what salvis described. Namely, rather than removing "Login or register to post comments" if the authenticated user role doesn't have a 'post comments' permission, I removed it if no user role has such a permission. The idea being that if another created role has the permission, we generally wouldn't want this link to be automatically hidden, even if only some authenticated users can post comments. And if you wanted it to be hidden in that case, you can always override the theme function. But if absolutely no users can post comments, there's no reason to display "Login or register to post comments."

AttachmentSize
comment_login_message.patch 1.53 KB

#3

amanuel - December 7, 2007 - 04:09

+1 on this.

I can't believe I never noticed this little issue. Slightly changed the patch to make it simpler and use the user_access() instead of a doing a select.

Cheers.

Index: comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.604
diff -u -r1.604 comment.module
--- comment.module 6 Dec 2007 09:58:30 -0000 1.604
+++ comment.module 7 Dec 2007 04:03:04 -0000
@@ -1639,7 +1639,7 @@
       $destination = "destination=". drupal_urlencode("node/$node->nid#comment-form");
     }

-    if (variable_get('user_register', 1)) {
+    if (variable_get('user_register', 1) && (user_access('post comments'))) {
       return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
     }
     else {

AttachmentSize
comment2.patch 806 bytes

#4

mcarbone - December 7, 2007 - 17:11

Sorry, amanuel, your patch isn't going to work, for two reasons:

1) user_access just checks the currently logged in user's permissions, unless you pass in an $account. But either way, it's not going to check if no user has 'post comments' permissions.

2) You actually should be checking both 'post comments' and 'post comments without approval' -- my patch checks both by virtue of a LIKE query.

I'm pretty sure the select on the permission table is necessary to check to see if the permission exists for any role. If you think the functionality of my patch in comment #2 should be changed, or the approach but keeping the same functionality, I'm happy to discuss that.

#5

Gábor Hojtsy - December 7, 2007 - 19:08
Status:needs review» needs work

- Introducing an SQL query in a theme function is a big no-no. Even if there are examples to this somewhere, we are not going down this route.
- Because there might be several calls to this theme function, the result of the query should be cached.

#6

salvis - December 7, 2007 - 20:47

@mcarbone: I see your reasoning, but I don't understand it. If only some roles have posting privileges, then those users can be assumed to be more knowledgeable, more trustworthy, in closer touch with your site, etc.

The higher ranking users should know that they get more functionality when they log in. There's no use in telling them to "Login or register to post comments" because they already know that, and for the lowly ones who don't know — well, for those it doesn't apply...

Or do you give posting permissions for first-time registrants and remove those permissions as your users become more mature?

#7

mcarbone - December 7, 2007 - 21:08

@salvis: Hmm, I guess you have a point. It only makes sense to display this message if core knows for a fact that logging in/registration gives comment posting access, which it can only do if the authenticated user has that permission. If it doesn't, but another role does, in that case one could override the theme to display an alternative message if they want. (e.g., "Login or register to learn how to become eligible to post comments," or whatever).

I will work on a patch with this, and Gábor's comments, in mind.

#8

mcarbone - December 8, 2007 - 03:26
Status:needs work» needs review

Here's the patch. It displays the message only when the authenticated user has comment posting permissions. It puts the query in a helper function that uses caching. Naming convention suggestions welcome.

AttachmentSize
comment_login_message_1.patch 1.91 KB

#9

amanuel - December 8, 2007 - 14:28

@mcarbone: You are right about my patch not working correctly. However isn't issue to solve the situation where an unregistered user is given the promise of posting upon registration only to find out that is not allowed.

Having thought about it some more, we should check the 'destination role' (usually authenticated role) to see if a newly registered user WILL have permission.

As for already registered I agree with @salvis, they should already know they need to login.

perhaps using user_roles(TRUE,'comments') instead of your select statement may make your patch more acceptable.

thoughts?

#10

mcarbone - December 8, 2007 - 18:44

I'm not sure if I understood the first part of your comment, but my latest patch was already checking the authenticated role. However, you're right that user_roles is a much better way to go about it, and it obviates the need to add a helper function. So here's a much more economical patch that uses that function.

AttachmentSize
comment_login_message_2.patch 1.83 KB

#11

mcarbone - December 8, 2007 - 19:03

Ha, I found a bug in user_roles, so I tweaked my patch so as to not rely on the bug.

The bug is this: it uses a LIKE query to check which roles satisfy a permission. But that means that if one permission is a substring of another one, it can return incorrect data. So for example, imagine a role that has the 'post comments without approval' permission, but not the 'post comments' permission. If you called user_roles(TRUE, 'post comments'), it will return that role, even if it doesn't have that specific permission! Now, that might not matter with the 'post comments' permission, but it could with other cases where being a substring of another permission doesn't necessarily imply it being a subpermission.

edit: someone has already reported this bug: http://drupal.org/node/198362

AttachmentSize
comment_login_message_3.patch 1.9 KB

#12

Gábor Hojtsy - December 9, 2007 - 12:29

mcarbone: Can you please submit an issue with that bug and put a link up here. That sounds pretty important to fix. Thanks!

#13

mcarbone - December 9, 2007 - 18:29

As I said, it's already been reported. Someone just bumped it up to critical, so it'll probably get more attention now:

http://drupal.org/node/198362

#14

salvis - December 10, 2007 - 01:05

I think you can remove the "you can't post comments" text. It must have been put there to back out of the false promise, but since you're removing the false promise, there's nothing to back out of. The Drupal way is to hide what's not available.

#15

TapocoL - December 18, 2007 - 18:37

This was being discussed here as well:
http://drupal.org/node/137100

I recommend clearing the initial if in the theme function, because we do not need to let the person know that they are not allowed to post on every possible comment page. Just keep the area blank, as to not bring attention to their lack of permissions:

-  if ($user->uid) {
-    return t("you can't post comments");
-  }

Then, just change the else to represent the if 'Not' uid:

-  else {
+  if (!$user->uid) {

#16

mcarbone - December 18, 2007 - 19:38

I'm not sure I've been convinced that getting rid of "you can't post comments" is the right thing to do, but in case everyone else is, here's the patch with that removed. We can just use the patch in comment #11 if we decide to leave it in for now.

AttachmentSize
comment_login_message_4.patch 2.26 KB

#17

salvis - December 21, 2007 - 01:44

@mcarbone: What benefit do you see in displaying that "you can't post comments" text?

#18

mcarbone - December 21, 2007 - 17:36

None, really, but I didn't want to presume as to why it was there in the first place. But if we take it out, why should that theme function every be called if the user is logged in?

#19

mcarbone - December 21, 2007 - 17:38

To answer my own question, maybe it's to allow it to be themed when we have logged in users who can't comment.

#20

salvis - December 22, 2007 - 15:49

There's a large numbers of permissions that any given role or user may NOT have. The Drupal way of handling the situation is to not display whatever is not available to the current user. I'm not aware of any other functionality in Drupal, where Drupal says "you cannot do this."

It's not Drupal-like, and it alienates users.

#21

Benjamin Melançon - December 22, 2007 - 16:31
Status:needs review» needs work

mcarbone's patch in #16 certainly removes the login or register to post comments links for anonymous users, but it did so even when my authenticated user role does have permission to post comments!

#22

mcarbone - December 22, 2007 - 17:14

Odd, it's testing completely fine for me. Can anyone else confirm? Or, @Benjamin Melançon, can you think of why this line wouldn't return true in your case?

$authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, array_merge(user_roles(TRUE, 'post comments'), user_roles(TRUE, 'post comments without approval')));

I assume that you're testing with an anonymous user, and that the built-in 'authenticated' role has either 'post_comments' or 'post comments without approval' -- is that correct?

#23

Benjamin Melançon - December 22, 2007 - 20:05

array_merge is resetting your keys:

This is my output (on http://d6.openzuka.net/node/1)

* must set it, based on 2 pc Array ( [2] => authenticated user )
* gahArray ( [0] => authenticated user [1] => authenticated user )
* at the gates of authenticated_post_comments:

From all this testing:

<?php
   
if (!isset($authenticated_post_comments)) {
drupal_set_message("must set it, based on ". DRUPAL_AUTHENTICATED_RID . " pc " . print_r(user_roles(TRUE, 'post comments'), TRUE));
     
$authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, array_merge(user_roles(TRUE, 'post comments'), user_roles(TRUE, 'post comments without approval')));
drupal_set_message("gah" . print_r( array_merge(user_roles(TRUE, 'post comments'), user_roles(TRUE, 'post comments without approval')), TRUE));
   }
drupal_set_message("at the gates of authenticated_post_comments: " . $authenticated_post_comments);
    if (
$authenticated_post_comments) {
drupal_set_message("got inside the if authenticated_post_comments");
      if (
variable_get('user_register', 1)) {
drupal_set_message("inside user register now!");
        return
t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
      }
      else {
        return
t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
      }
    }
?>

#24

Benjamin Melançon - December 22, 2007 - 20:11

From PHP.net: http://us.php.net/array_merge

If you want to completely preserve the arrays and just want to append them to each other (not overwriting the previous keys), use the + operator:

$result = $array1 + $array2;

Worth a shot?

benjamin, Agaric Design Collective

#25

mcarbone - December 22, 2007 - 22:19

@Benjamin Melançon -- Nice find. Yet another reason why testing on a fresh install isn't good enough. Here's a patch using + instead of array_merge. Give it a shot.

AttachmentSize
comment_login_message_5.patch 2.25 KB

#26

mcarbone - December 22, 2007 - 22:20
Status:needs work» needs review

#27

Benjamin Melançon - December 23, 2007 - 18:47
Status:needs review» reviewed & tested by the community

Works great! Thanks for updating the patch.

One question I had was about was whether the login link should show up on teasers (for logged in users an "Add new comment" link does show up on teasers). But that's a separate issue from this patch.

This is ready to be committed based on my tests.

benjamin, Agaric Design Collective

#28

Dries - December 26, 2007 - 07:34
Status:reviewed & tested by the community» needs work

Why can't we use:

<?php
-    if (variable_get('user_register', 1)) {
+    if (
variable_get('user_register', 1) && (user_access('post comments') || user_access('post comments without approval')))) {
  return
t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
?>

#29

Gábor Hojtsy - December 26, 2007 - 09:53

Dries: user_access() uses the current user. In the issue at hand, the links are printed with the assumption that *after the user is loggedn in*, she will have permission to post comments. With your code example above, the body of the if() will never run, as this function is only invoked, if the user was checked to not have permission to post comments already.

The patch checks whether the assumption that after the login, the user will have permission to post comments is right. If not, it is misleading to print this note suggesting the user to log in or register.

#30

Benjamin Melançon - December 27, 2007 - 01:52
Status:needs work» reviewed & tested by the community

Based on the situation this patch fixes and my test and review, setting back to ready to be committed.

#31

spade - January 3, 2008 - 08:52
Version:6.x-dev» 5.5
Category:bug report» support request
Status:reviewed & tested by the community» won't fix

I have tried to patch this into 5.5, but with no success. I see you'll were talking about D6 though.

Has somebody worked out a patch for 5.5 and can post that? Or better send me the patched comment.module, since I am working under Windows and have problems getting patch to work.

Thanks

#32

Gábor Hojtsy - January 3, 2008 - 09:46
Version:5.5» 6.x-dev
Category:support request» bug report
Status:won't fix» reviewed & tested by the community

Eh, do not take over issues please.

#33

spade - January 3, 2008 - 15:29

I don't know what you mean. I didn't try to take over anything.

#34

catch - January 3, 2008 - 15:40

spade, you changed the version, status and category (and changed the subject to patching on windows) - which made this ready-to-be-fixed bugfix against 6.x an inactive (won't fix) support request against drupal 5. That's called 'taking over'. When this patch is committed to 6.x, it might be worth opening a request for a backport. http://drupal.org/patch has information for getting started on patching.

#35

spade - January 3, 2008 - 16:01

Thanks catch,

I am still new here and trying to find my way around ...

Thanks for the advise ...

#36

Dries - January 4, 2008 - 08:07

Gabor: OK, that makes sense. I suggest we document your explanation in the code, and that we commit this patch. Let's make sure this is easy to understand for other developers.

#37

Gábor Hojtsy - January 4, 2008 - 11:36
Status:reviewed & tested by the community» fixed

I went ahead, cleaned up the code a bit (ie. moved the $destination handling to the part where we already know we actually need that value), and added some comments to this function. Committed this one.

AttachmentSize
comment_login_message_6.patch 2.94 KB

#38

keith.smith - January 4, 2008 - 14:42
Status:fixed» needs review

Small typo in a code comment; follow up patch attached.

AttachmentSize
195161.patch 939 bytes

#39

catch - January 4, 2008 - 14:50
Status:needs review» reviewed & tested by the community

#40

Gábor Hojtsy - January 4, 2008 - 15:12
Status:reviewed & tested by the community» fixed

Thanks, committed.

#41

salvis - January 4, 2008 - 21:29

Thank you!

Is it possible to get this back-ported to D5? Can I retag this issue, or do I need to open a new issue, as catch suggested in #34?

#42

spade - January 6, 2008 - 11:29
Status:fixed» reviewed & tested by the community

As was to be expected, I support the request to get this back-ported to D5. ;-)

#43

Gábor Hojtsy - January 6, 2008 - 11:43
Version:6.x-dev» 5.x-dev
Status:reviewed & tested by the community» needs review

spade: you changed this to ready to be committed, but did not change the version? Did you check that this is ready to be committed in Drupal 5 as-is, without modification?

#44

mcarbone - January 6, 2008 - 23:39
Status:needs review» patch (to be ported)

No, it doesn't apply as-is, and will have to be ported.

#45

spade - January 8, 2008 - 12:47

Sorry, I didn't knowingly change anything and can't answer your question. I just ment to support the previous posters request (and left everything in the head of the form unchanged [I thought I had learned that much from my previous mistake]). I appologize should I have caused any confusion ...

#46

salvis - January 9, 2008 - 13:32

Ported one-to-one to 5.x-dev and tested.

AttachmentSize
comment.module.195161.46.patch 2.81 KB

#47

salvis - January 9, 2008 - 13:33
Status:patch (to be ported)» needs review

#49

omnyx - February 29, 2008 - 19:40

subscribing

#51

Sutharsan - August 31, 2008 - 20:30
Component:comment.module» usability

Moving all usability issues to Drupal - component usability.

#53

drumm - December 3, 2008 - 17:56
Status:needs review» fixed

Committed to 5.x.

#54

Bojhan - December 4, 2008 - 14:31

But in D7 this issue will still exist?

#55

salvis - December 7, 2008 - 15:41

#40 committed it to D6. I'm not sure whether that was before or after D6 was branched.

@Bojhan: Please check D7 and report back — thanks!

#56

mcarbone - December 8, 2008 - 20:27

#58

System Message - December 28, 2008 - 09:33
Status:fixed» closed

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

#61

gopisathya - March 18, 2009 - 15:05
Component:usability» comment.module

Found another solution..

In comment.module look for function

function comment_link($type, $node = NULL, $teaser = FALSE) {
...
....

else {
// this is for teaser - comment this line
// $links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node->nid);
}

this should hide the "login or register to post comment" link in the teaser..

Gopisathya

#67

nevets - June 29, 2009 - 13:34
Assigned to:Anonymous» tanper

Fixing some changes made by spammers.

 
 

Drupal is a registered trademark of Dries Buytaert.