devise_invitable icon indicating copy to clipboard operation
devise_invitable copied to clipboard

new option - config.invitation_limit_for

Open matzke opened this issue 13 years ago • 3 comments
trafficstars

It would be nice, if there was an option +invitation_limit_for+ = 1.day, so the user can send only X invitations per day.

I think it is important to limit the number of invitations, so nobody can spam people. But it is also important to make it possible (for power users) to invite a whole bunch of people.

matzke avatar Apr 13 '12 08:04 matzke

Do you have some ideas about implementation?

scambra avatar Apr 13 '12 09:04 scambra

Maybe have something like an invitation_reload_period key, an invitation_last_sent_on, and a invitations_for_period key.

So invitation_reload_period would store the amount of time between invite refills. invitation_last_sent_on stores the time the user last sent an invitation. And invitations_for_period would store the number of invitations remaining in that period.

When a new invitation is created, we check whether there are still any invitations_for_period. If so, proceed as normal and decrement invitations_for_period.

If not, check to see if Time.now - invitation_last_sent_on >= invitation_reload_period. When false, we can't send the invitation, otherwise we refill the invitations_for_period from invitation_limit and decrement.

I realise now that I've typed this, the issue with this approach is that it hinges on the invitation-create action. I was trying to come up with a solution that wouldn't involve a cron job, but now I'm not sure that's possible.

Edit: Actually, we can also do the refilling (from paragraph 4) any time we want to get the invitation count, so that the count wouldn't show 0 invitations remaining even when we're past the invitation reload period.

teddywing avatar Sep 06 '12 22:09 teddywing

invitations_for_period is not needed, invitation_limit can be used, class.invitation_limit would be the reset value time check could be done in has_invitations

scambra avatar Sep 07 '12 07:09 scambra