I'm speaking with a developer about creating the following functionality with userpoints

1. points not given if a) node is created in unpublished state b) node created and goes into moderation (with modr8 module, for example)

2. only positive points go into userpoints moderation. If there are negative points, such as for pageviews, downloads, etc, these are not moderated. Otherwise, a user could download/view pages for hours until the negative points are moderated by admin, so there needs to be a separation between positive/negative userpoints.

now, I don't want to create an orphaned version of the module and then fall behind when the userpoints module gets upgraded so my choice is either to commit a patch to this module or create a contrib module (or two) with this functionality.

which is the better path to take? If a working patch with either or both of these functions was added here, would it be accepted?

CommentFileSizeAuthor
#3 negative_bypass.patch2.24 KBjbrown

Comments

kbahey’s picture

I don't have time to examine the details, but yes, patches are normally accepted provided they do not break backwards compatibility, and are configurable. They have to be tested and reviewed by at least 2 people before they can be included.

esllou’s picture

thanks. I think the "points only if published" is something quite a few have mentioned on here in the past.

jbrown’s picture

Status: Active » Needs review
StatusFileSize
new2.24 KB

I created a patch for 2. for esllou.

Please review.

kbahey’s picture

Please explain what this patch does. Use cases, ...etc.

esllou’s picture

Status: Needs review » Reviewed & tested by the community

It adds a checkbox in the "Moderation" div on the userpoints config page - "Allow negative points to bypass moderation"

when checked, positive points go into moderation (for creating a node, etc) whereas negative points (for pageviews, downloads, etc) come straight off. That prevents someone abusing the moderation system because if negative points need to be moderated too, they can download files or view all the nodes on a site without their userpoints changing.

I've reviewed it and it works as per design.

BillyBoy’s picture

this looks interesting. I have negative points for pageviews on a site. I'll test this out tomorrow. Thanks for the patch!

BillyBoy’s picture

tested this patch this morning. Works fine. Great addition. Ta!

esllou’s picture

when will this patch be added to userpoints?

kbahey’s picture

Status: Reviewed & tested by the community » Needs work

@esllou

Please don't rush maintainers. Give them time, they are busy people.

@jbrown

I am wondering if this can be done in an external module, rather than the userpoints API itself.

There is the 'moderate' flag, which can be set to true or false. Combine that with the points before, and you probably get what you need, without a modification to userpoints.

Try this, before we cram complexity and cruft to the module itself.

function yourmodule_userpoints($op, &$params = array()) {
  if ($op == 'points before') {
    // Is points negative?
    if ($params['points'] < 0) {
       // Turn off moderation
         $params['moderate'] = FALSE;
    }
  }
}
esllou’s picture

kbahey, I made a custom module, called it mysite and altered the first line of that code to "function mysite_userpoints", etc, etc

gave the module a low weight and when I do something that means negative points, they go into the points moderation queue anyway. Is there something else I need to do? The module is loading fine as I have other stuff in there to alter forms and it's doing everything as planned. Just this mysite_userpoints function (as is currently) doesn't seem to do anything.

kbahey’s picture

Version: 6.x-1.1 » 6.x-1.x-dev

It could be that the code snippet I mentioned needs some tweeks.

More debugging is needed to see if the 'moderate' modification takes effect or not.

Specifically, this code in userpoints.module:userpoints_userpointsapi()

    if (!isset($params['moderate'])) {
      //if not passed then site default is used
      $params['status'] = variable_get(USERPOINTS_POINTS_MODERATION, 0);
    }
    else { 
      if ($params['moderate'] == true) {
        $params['status'] = 1;
      }
      else {   
        $params['status'] = 0;
      }
    }

There is some similar code in the transaction function too.

This is not something I have time for, so someone else needs to confirm it.

berdir’s picture

$params is currently not passed by reference, so it's not possible to do that :) Just like any other modification.

#668284: hook_userpoints pass $params by reference would change that.

Also, since this patch is actually in the rules integration category, wouldn't it be better to provide Moderate "default/yes/no" as a option when creating a rule? That's much more flexible than a generic negative points are not moderated option.

+++ userpoints.module	8 Jun 2010 16:29:49 -0000
@@ -581,7 +588,12 @@
+      if (variable_get(USERPOINTS_POINTS_MODERATION, 0)) {
+      ¶
+        if ($params['points'] > 0 || (variable_get(USERPOINTS_POINTS_MODERATION_NEGATIVE_BYPASS, 0) == 0)) {

There are some trailing whitespaces that should be removed when the patch is re-rolled, but depending on the above idea, it might look totally different anyway :)

Powered by Dreditor.

kbahey’s picture

I still think that a separate module could do this, without the need to over-complicate the API with special cases.

Let us resist this temptation for increased complexity.

berdir’s picture

No, it can't, unless you commit the linked issue :)

Currently, modules can not change anything in $params, ever :)

Also, I agree with not adding complexity, that's why I suggested to make this a per-action/rule option for rules integration (only). In my opinion, rules integration should be as feature-complete as possible, allowing control over any setting/field/option that userpoints_userpointsapi() supports.

manuel.adan’s picture

Component: Code: userpoints_rules/userpoints_workflow_ng » Code: userpoints
Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing this as outdated, 6.x version is no longer maintained.