The latest changes made to user points allow using points as a currency of sorts for a web site.

For example someone can purchase points for real money, and the admin can designate creating a node type as consuming 50 points (e.g. a resume or a job posting).

At present, there is no safeguard to prevent an action if there is insufficient points for it.

We need to add this check with an option to enable/disable this feature.



greggles’s picture

Version: master » 5.x-3.x-dev
Component: Code » Code: userpoints API
Assigned: Unassigned » greggles

I need this.

I'm adding a checkbox to the admin screen "Allow negative points" and then in the api will check if a transaction will take a user to a negative number before processing the transaction.

One problem scenario:

1. Users write a bunch of stupid comments which earns a bunch of points.
2. They "spend" all of these points.
3. A moderator comes by and sees that the comments were stupid and deletes them so the user is now supposed to lose all those points.

Thoughts? I guess that's a scenario where putting points into moderation makes the most sense. Or you can just "cest la vie" that users can spend points which they may not really deserve.

greggles’s picture

Status: Active » Needs review
2.33 KB

And here's a patch.

This doesn't go back and enforce the rule on existing accounts, which could cause some problems. I tried to make the gating logic work to let users build their way out of that situation but a second set of eyes on it would be great.

jredding’s picture

I was (actually did) writeup a question as to why it needed to be in "core" vs a contributed module. You can do this with the hook right now, same code just with the hook returning false.

Sorry that I didn't catch this earlier and prevented you from writing the code.

I guess I'm not 100% sure as to why this should be in core and can't be a small contrib module? I know I've had more requests for having/allowing negative than I've had for preventing them.

I agree with your scenario though but, on an unrelated sidenote, don't how it prevents the user from spending all of their points from lame comments. The way I read it is that...
1) User create tons of lame comments
2) User "spends" them (and has already derived the value from their lame commenting)
3) Admin deletes the comments thus the user loses points..
with negative points not allowed the user's balance remains at 0 and their wrongdoing might go unnoticed by a point administrator. With negative points allowed their balance would be negative and might alert attention.
---This, however, is off-topic to the contrib vs. core subject above.

greggles’s picture

Yeah, I agree about the negative points situation you mentioned. Maybe this should drupal_set_message() about the fact that negative points were not removed to help admins know about it.

It feels like a really small amount of code to have to put into a contrib, though. It's not like userpoints3.x is a static thing - this adds new features without breaking the API. That return message thing broke the API...

But, if you definitely don't want this in core then I'll make it into a contrib in a heartbeat - it's no biggy.

kbahey’s picture

Project: User Points » User Points Contributed modules
Version: 5.x-3.x-dev » 5.x-2.x-dev
Component: Code: userpoints API » Code

I think this should be a contrib. The API allows, but the implication on existing sites need to be factored in.

For example, in your _install hook, you can check that no one has below zero "balances", and refuse to work with a dsm() for the admin to that effect.

I will leave it to you as to what happens when admin deletes lame comments. Since it is a contrib, you can freely decide what happens. Even block the user if you want to.

jredding’s picture

kbahey... your call.

greggles’s picture

Ok, but I don't care about 5.x-2.x-dev. Does this mean that I have to port all the other contribs to 5.x-3.x just to get this published? And/or create a separate "userpoints no negative" project on d.o?

I need my module to depend on this now.

kbahey’s picture

Sorry about the 2.x thing.

userpoints contrib does not have a 3.x branch yet for 5.x.

However, you can go ahead and commit your module to userpoints contrib's HEAD, and then I will branch a 3.x (DRUPAL-5--3) off of that.

I just cleaned up HEAD so you can go ahead and do that.

Let me know when it is committed, and I will branch it off.

(Oh, and if you want to port all the other modules, please do so! ;-)

jredding’s picture

I'm going to try to jump in and upgrade the contrib modules, today I'm attempting to round up a marathon team. They want to learn Drupal modules and I want these things updated, seems like a decent match. ;)

kbahey’s picture

Yay! Nothing beats forced labor!

I just deleted all the modules from HEAD.

So, you have to go get them from the 2.x branch, and commit them one by one to HEAD as they become available for 3.x.

Once we have one module ported to 3.x, (whether Greg's or one of your "prisoners") I can create a 3.x-dev and that would be what 3.x commits to.

greggles’s picture

Status: Needs review » Fixed

Committed to head.

If you have any feedback on improvements please let me know.

kbahey’s picture

Version: 5.x-2.x-dev » 5.x-3.x-dev

Branch and dev release created for 3.x.

greggles’s picture

Thanks, Khalid.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

mattze’s picture

Hi Greg, is your patch adapted for the current 5.x-3.x-dev (
How can I play the patch in the userpoints.module?

greggles’s picture

@mattze - it is available in the 5.x-3.x branch of userpoints contrib:

@kbahey, @jredding: I altered the userpoints contrib project page so that the 3.x snapshot release would show up as supported and would show on the project page to help adoption of 3.x.

mattze’s picture

I use the cotrib user2userpoints but i can't transfer more points that i have. Why?

jredding’s picture

Please create a new support request instead of posting in existing unrelated threads.

To answer your question.
umm.. You can't transer more points than you have because umm.. you don't have enough points.
This is akin to transfering money. I'd love to transfer 100 dollars to my friend even though I only have 50 dollars in my account but something tells me this would lead to abuse.