I think the function _watcher_hook_nodeapi_insert is a little too quick to automatically watch a newly-created node.

I have a drupal site, and I've configured it so that users automatically watch content that they create. I also have a php script that creates nodes for various authors. However, if I run this script from a browser tab when I'm currently logged into my drupal site, the Watcher module determines that I should automatically watch these new nodes.

This is because _watcher_hook_nodeapi_insert merely checks for the presence of a logged-in user, and doesn't compare this user to the author of the node being inserted. I propose the following change:

Old:

function _watcher_hook_nodeapi_insert(&$node, $a3, $a4) {
  global $user;
  if ($user->uid) {
    _watcher_user_autowatch_node_insert($node->nid);
  }
}

New:

function _watcher_hook_nodeapi_insert(&$node, $a3, $a4) {
  global $user;
  if ($user->uid && ($node->uid == $user->uid)) {
    _watcher_user_autowatch_node_insert($node->nid);
  }
}

Comments

solipsist’s picture

Either way we're dealing with assumptions. You assume that the current user wants the user set as owner of the node to watch it. Problem is that when you create a node in someone else's name and you're set as watching it and the "you're watching this" link is shown in green you also have a chance to respond to it. The user set as node owner does not have any chance to respond or change his or her mind. This "reactability" is the key reason to the current design.

I can more easily picture a situation in which a node is created in someone else's name even though the actual current user wants to watch it, than the opposite. I assumed that to be the common case, which is why Watcher deals with the current user and not the node owner. After all, it is the user that *created* the node that is set to watch it, not the user referenced as owner of it.

To those who are reading this, please comment. I'd like to know what others think is most natural and intuitive before I make a decision to keep it as it is or implement sadotter's proposed change.

solipsist’s picture

Category: bug » task
Priority: Normal » Minor

sadotter: If you can submit patches instead if just quoted code, I'd be very happy. Patches are much easier to deal with.

solipsist’s picture

Status: Active » Needs review