It would be useful if Vote Up/Down defined a hook that allowed modules to alter the voting permissions. One use case would be for a contributed module to provide timed voting based on a node's CCK date fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cpliakas’s picture

Status: Active » Needs review
FileSize
4.38 KB

The attached patch adds a hook_vud_access() hook modeled after the Flag module's hook_flag_access(). There is also a hook implementation in the vud_node() module that allows for users to select "One time voting" restrictions so they cannot vote more than once.

Status: Needs review » Needs work

The last submitted patch, vote_up_down-877392-1.patch, failed testing.

cpliakas’s picture

FileSize
9.29 KB

Committed an older patch in #1. The attached patch is the most recent and takes vud_comment and vud_term into account. Will work on unit tests.

marvil07’s picture

Status: Needs work » Closed (works as designed)

The patch is clean, but IMHO this is out of the scope of the module.

I would suggest to implement that functionality at the widget level, showing the voting control only when needed. I am willing to move more interaction to the widget in the future, but definitely not for the actual 2.x stable branch.

cpliakas’s picture

Hi marvil07.

Thanks for the feedback. First, I should have patched this against 3.x, I agree with you that it shouldn't be in the 2.x stable branch since it is a significant change. Regarding preventing voting by the widget, my opinion is that it should not be handled on the display layer. The reason is that you should be denied access to vote as opposed to the widget just hiding the voting options. Furthermore, preventing voting via a universal access callback allows you to have the changes reflected across all widgets, so your logic isn't determined solely in the presentation layer. Looking at some of the voting features we want to implement in Drupal Commons, we would most likely have to override the menu callback and implement an access hook which is a viable solution, but it would be cool if we could get this code into the core module.

Thanks for a great project, big fan of the work you have done on it.
~Chris

marvil07’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Status: Closed (works as designed) » Needs work

Thinking this a little more, I notice this could help to achieve #554360: Disallow Voting on Your Own Content from another module, so re-opening this.

In the other side, I think we only want the hook declaration, I mean, not the hook implementation inside any of the modules.

cpliakas’s picture

Version: 6.x-3.x-dev » 6.x-2.x-dev
Status: Needs work » Closed (works as designed)

Hi marvil07.

Sounds good, and thanks for taking the time to consider this further. Also, I agree with you that there probably shouldn't be any hook implementations inside of the module. Leaves room for contribs and custom mods to fill that space.

Thanks again,
Chris

cpliakas’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Status: Closed (works as designed) » Needs work

Accidentally reverted tags... changing back.

cpliakas’s picture

Status: Needs work » Needs review
FileSize
7.8 KB

Re-rolled patch against the 6.x-3.x-dev version of the module. As requested in #6, it includes only the hook definition and no implementations.

Thanks,
Chris

Status: Needs review » Needs work

The last submitted patch, vote_up_down-877392-9.patch, failed testing.

cpliakas’s picture

Status: Needs work » Needs review

#9: vote_up_down-877392-9.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, vote_up_down-877392-9.patch, failed testing.

ressa’s picture

It would be really great to be able to prevent users from voting on own content, so I hope this patch passes the test soon 8o)

marvil07’s picture

+++ vud.module	17 Sep 2010 14:50:22 -0000
@@ -108,6 +110,46 @@ function vud_menu() {
+function vud_access($perm, $type, $content_id, $value, $tag, $account = NULL) {

This accidentally implements hook_access(), so changing the name would be better.

+++ vud.module	17 Sep 2010 14:50:22 -0000
@@ -108,6 +110,46 @@ function vud_menu() {
+  if (NULL === $user) {

minor bug here, the comparison if against $account variable.

Powered by Dreditor.

udvranto’s picture

Any update on this?

cpliakas’s picture

Status: Needs work » Needs review
FileSize
8.01 KB

Re-rolled patch based on comments in #14.

Thanks,
Chris

marvil07’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

I finally returned to this \o/. Committed to 6.x-3.x. Thanks for the patience here!

I have just changed the way of the hook, the behaviour now is deny access if:

  • User do not have enough permissions to vote
  • Some module decide to deny access

In other case, allow. IMHO that's more clear to read.

I have also made some tweaks here and there. Attaching the patch I am going to commit and the interdiff patch for people here since the last patch ;-)

Moving status to port(not sure if in exactly the same way) it to the 7.x version when possible.

marvil07’s picture

sorry, forgot to attach the patches for convenience :-p

cpliakas’s picture

Thanks for getting back to this and posting your modifications. I think this will help in building ideation solutions similar to ideascale and quora.

klonos’s picture

...and if anyone manages to put something together based on this that solves #1201938: How To: Disallow voting on your own content (script or unofficial sub-module or whatever), please post it here or there so we can finally close that one too. Thanx.

vonderro’s picture

So, in Drupal 6 version, how can I deny voting on user's own content, can anyaone help me with this?

marvil07’s picture

@vonderro: You can do it using hook_vud_access().

marvil07’s picture

Status: Patch (to be ported) » Fixed
FileSize
4.33 KB

The attached patch is now on 7.x-1.x.

From commit message:

This is a backport of the original patch on #877392-18

The main difference here is that I am applying changes only on vud
module because of the plan(see #1360572).
The othe minor difference is about re-naming some variables to make it
D7-friendly.

Status: Fixed » Closed (fixed)

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