4

In regards 7.x.

Say a user that has a role of (registered user) wants to block another user with the same role that is harassing them and they don't want to see any more posts or comments from the harassing user. But, I as the "Admin" don't want to Block either user. The user just wants to block the other harassing users comments or posts to be viewable by them....

For example: Other websites offer a way for a user to block someone that is harassing them. They can even block that harassing user from ever seeing their information/profiles/comments or posts.... But, that blocked user isn't blocked to everyone else, just blocked to that specific user from being able to see their information/profiles/comments or posts.

Is there a way to do that in drupal? What modules would I use to make that work? How can I make that work?

I am concerned that users could start harassing one another in posts and comments, there should be a way to mute users posts or comments from being viewable.

For example: Say I start a conversation with you and you don't like what I'm saying and you don't want to see those type of posts anymore from me. How can you block me from me posting such things on the drupal about you? So if there was a way to mute me, then my posts or comments would nolonger be visible by you but still visible by everyone else.

Is this possible?

  • Were you able to find a solution for this issue? I have looked into User Relationships, Flags, and Relations, and I cannot find a way to create this type of access check/denial. – hockey2112 May 16 '16 at 21:16
6

I think best and easy approach would be using Flag module. You can create a Flag for user entity and grant authenticated users to flag other users, then you can check if the user is flagged as below.

$flag = flag_get_flag('ban_user') or die('no "ban_user" flag defined');

if ($flag->is_flagged($GLOBAL['user']->uid, $user->uid)) {
  // The optional second parameter to is_flagged(), which allows
  // us to ask if an item is flagged on behalf of a certain user. If this
  // parameter isn't provided, the check is made against the current user.
  print "This user has banned you!";
}
  • I tried your code in a custom module (renaming the flag to my own flag's name), but it returned this error message: "Fatal error: Call to undefined function flag_get_flag" – hockey2112 May 16 '16 at 21:15
1

From memory, this has to be a custom solution. There was a useful article, however, here

0

You could use the Relation module. Create a many-to-many user-to-user relationship, call it "block_user" and allow users to add relations.

Whether you use relation or flag (see heshanlk's answer): If you do not want to write code, you could replace the default comments with a view in a block. See How to display comments of current node in a view, and just add another filter for the relation or flag. You will be filtering with two contexts: the current node, AND the current user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.