diff options
author | ankonym <ankonym@gmail.com> | 2015-10-02 16:51:57 +0200 |
---|---|---|
committer | ankonym <ankonym@gmail.com> | 2015-10-02 16:51:57 +0200 |
commit | 82a33300818dd8f6e06856944fe7c658746efca1 (patch) | |
tree | a38234fa3a6e4cca22ad1f7b7a42743a19ec96d4 /app/models/invite_code_validator.rb | |
parent | d45f6c61f6a13be06f1977b857e0cb31e79c5317 (diff) |
Allow multi-use invite codes
Introduce a invite_max_uses property to invite codes to allow admins to set a maximum number of uses for invite codes.
Diffstat (limited to 'app/models/invite_code_validator.rb')
-rw-r--r-- | app/models/invite_code_validator.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb index f96ca4a..d52e698 100644 --- a/app/models/invite_code_validator.rb +++ b/app/models/invite_code_validator.rb @@ -6,8 +6,11 @@ class InviteCodeValidator < ActiveModel::Validator if not_existent?(user_invite_code) add_error_to_user("This is not a valid code", user) - elsif count_greater_than_zero?(user_invite_code) + elsif has_no_uses_left?(user_invite_code) add_error_to_user("This code has already been used", user) + + # elsif count_greater_than_zero?(user_invite_code) + # add_error_to_user("This code has already been used", user) end end @@ -16,10 +19,14 @@ class InviteCodeValidator < ActiveModel::Validator code == nil end - def count_greater_than_zero?(code) - code.invite_count > 0 + def has_no_uses_left?(code) + code.invite_count >= code.invite_max_uses end + # def count_greater_than_zero?(code) + # code.invite_count > 0 + # end + def add_error_to_user(error, user) user.errors[:invite_code] << error end |