Person should not vote his nodes (patch attached)

flexer - July 4, 2008 - 13:41
Project:Favorite Nodes
Version:5.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

In one installation of ours, we are using "favorites" as (also) a way to determine how a content has been "liked". So far, so good. The only issue was that now a person SHOULD NOT vote its own nodes as favorite. I simply added a "create favorites on own nodes" permission. I hope you like it

AttachmentSize
favorite_nodes_01.patch1.51 KB

#1

kbahey - July 4, 2008 - 16:11
Status:active» needs work

I don't like this piece of code. It is very complex and will be a maintenance nightmare.

+      if (user_access(FAVORITE_NODES_PERM_ADD) AND
+          (!$user->uid OR $user->uid != $node->uid OR ($user->uid == $node->uid AND user_access (FAVORITE_NODES_PERM_ADD_OWN)))) {

It has to be more clear with comments. For example:

if (....) {
  if (....) {
     // something
  }
  else {
    // something
  }
}

It has to be a separate function (e.g. function _favorite_node_can_add()) Also use && and || as per code guidelines.

#2

flexer - July 8, 2008 - 08:34

"Refactoring" the code as per your suggestions, I found that using permission doesn't work (the user 1 bypasses that check). I moved the option from being a permission to a setting. Patch attached.

AttachmentSize
favorite_nodes_flexer.patch 1.83 KB
 
 

Drupal is a registered trademark of Dries Buytaert.