I was just wondering - is it possible to set it up so people can't vote for themselves or it defaults to giving them a vote automatically?

Great module btw, one of the communities I'm working for are drooling at the new site :)

Comments

frjo’s picture

Version: 4.7.x-1.x-dev »
Status: Active » Postponed

It could be added as a setting and I may take a look at it if I have some free time :-).

marcoBauli’s picture

Title: users voting for themselves » Prevent users voting for themselves

yep, that would make much more "par condicio" ;) +1

ola90@drupal.ru’s picture

I used the following code in node.tpl.php to solve this issue:

    global $user; 
    if ($user->uid): 
     if ($user->uid!=$node->uid): 
      print $vote_up_down_widget; 
     else:
      print $vote_up_down_points;
     endif;
    else:
     print $vote_up_down_points;
    endif;

It shows only points to anonymous users and the author of the node, but other authorised users see the voting widget.

madjr’s picture

umm , i can't actually get the code above to work. Dunno what i may be doing wrong.

Another strange thing is that users can also vote for themselves in the "preview" screen before posting (). After that they can still vote for themselves again once the node/comment is posted.

madidus’s picture

Has anyone come across a fix that works for this? I'm trying to eliminate the same problem

Anonymous’s picture

I've just done a hack, it works for me, YMMV ;) Also I've only done it for nodes and comments, not links, but shouldn't be hard to work out how to do it from what I've done here.

In vote_up_down.module, lines 208-246 are currently:

/**
 * Implementation of hook_nodeapi().
 */
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'view':
      $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
      if ($node_type) {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
          $node->content['vote_up_down'] = array(
            '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
            '#weight' => -10,
          );
        }
        else if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
          $node->content['vote_up_down'] = array(
            '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
            '#weight' => -10,
          );
        }
      }
      break;
  }
}

/**
 * Implementation of hook_comment().
 */
function vote_up_down_comment(&$comment, $op) {
  switch ($op) {
    case 'view':
      if (variable_get('vote_up_down_widget_comment', 1)) {
        $style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';
        $comment->comment = theme("vote_up_down_widget$style", $comment->cid, 'comment') . $comment->comment;
      }
      break;
  }
}

Replace them with this:

/**
 * Implementation of hook_nodeapi().
 */
function vote_up_down_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  global $user;
  switch ($op) {
    case 'view':
      $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
      if ($node_type) {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        if ($teaser && variable_get('vote_up_down_widget_node', 0) && variable_get('vote_up_down_widget_node', 0) != 2) {
          if ($user->uid!=$node->uid) {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
              '#weight' => -10,
            );
          }
          else {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_points", $node->nid, 'node'),
              '#weight' => -10,
            );          
          }
        }
        else if (!$teaser && variable_get('vote_up_down_widget_node', 0) > 1) {
          if ($user->uid!=$node->uid) {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_widget$style", $node->nid, 'node'),
              '#weight' => -10,
            );
          }
          else {
            $node->content['vote_up_down'] = array(
              '#value' => theme("vote_up_down_points", $node->nid, 'node'),
              '#weight' => -10,
            );          
          }
        }
      }
      break;
  }
}

/**
 * Implementation of hook_comment().
 */
function vote_up_down_comment(&$comment, $op) {
  switch ($op) {
    case 'view':
      if (variable_get('vote_up_down_widget_comment', 1)) {
        $style = variable_get('vote_up_down_widget_style_comment', 0) == 1 ? '_alt' : '';

        global $user;
        if ($user->uid!=$comment->uid) {
          $comment->comment = theme("vote_up_down_widget$style", $comment->cid, 'comment') . $comment->comment;
        } 
        else {
          $comment->comment = theme("vote_up_down_points", $comment->cid, 'comment') . $comment->comment; 
        }
      }

      break;
  }
}

Use at your own risk ;)

Ainur’s picture

Incredible, after 3 years of development, users still can vote on own content!
Just add more checks on vote_up_down_vote();
instead of

if ($user->uid != $content->uid && is_numeric($cid) && is_numeric($value) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], "vote_up_down/$type/$cid/$value")) {

use

global $user;
$content = votingapi_load_content($cid, $type);
if ($user->uid != $content->uid && is_numeric($cid) && is_numeric($value) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], "vote_up_down/$type/$cid/$value")) {
rbl’s picture

Ainur, what version is that code for? It doesn't match the latest 6 versions...

Ricardo

Flying Drupalist’s picture

Status: Postponed » Active

I think we should unpostpone it! :)

drupov’s picture

subscribe

Ainur’s picture

rbl, it's for 5.x version

rbl’s picture

Oh =(
Thanks!

drupov’s picture

Hi, for 6.x-version please check this issue: http://drupal.org/node/554360

marvil07’s picture

Version: » 6.x-2.x-dev
Status: Active » Closed (duplicate)

like mentioned in #13, this is now tracked on #554360: Disallow Voting on Your Own Content

bluesky_still’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev

Incredible, after 3 years of development, users still can vote on own content!

2012 rate modules still I met this problem.

marvil07’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev

@天空蔚蓝: I do not see the point on changing the metadata of this issue. Please see hook_vud_access().