forked from rDrama/rDrama
Amend f8ae2a3d17c6: revert >= logic, fail loudly.
First, the apparent errors with >= 9 and 99 in the Marseys and referrals code after the refactor are not actually bugs: they were bug fixes mixed in with the refactor to fix an off-by-one. Next, instead of failing silently on the `not user` branch in badge_grant, we throw a ValueError. This retains the current behavior where users get 500s to report while also enforcing the assertion near the edge of the function.master
parent
ef00f31831
commit
7e54f858d3
|
@ -3,7 +3,9 @@ from files.classes.badges import Badge
|
||||||
from files.helpers.alerts import send_repeatable_notification
|
from files.helpers.alerts import send_repeatable_notification
|
||||||
|
|
||||||
def badge_grant(user, badge_id, description=None, url=None):
|
def badge_grant(user, badge_id, description=None, url=None):
|
||||||
if not user or user.has_badge(badge_id):
|
if not user:
|
||||||
|
raise ValueError('badge_grant: expected user, not None')
|
||||||
|
if user.has_badge(badge_id):
|
||||||
return
|
return
|
||||||
|
|
||||||
badge = Badge(
|
badge = Badge(
|
||||||
|
|
|
@ -279,7 +279,8 @@ def api_comment(v):
|
||||||
|
|
||||||
all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count()
|
all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count()
|
||||||
|
|
||||||
if all_by_author >= 10:
|
# off-by-one: newly added marsey isn't counted
|
||||||
|
if all_by_author >= 9:
|
||||||
badge_grant(badge_id=16, user=user)
|
badge_grant(badge_id=16, user=user)
|
||||||
else:
|
else:
|
||||||
badge_grant(badge_id=17, user=user)
|
badge_grant(badge_id=17, user=user)
|
||||||
|
|
|
@ -338,9 +338,10 @@ def sign_up_post(v):
|
||||||
|
|
||||||
if ref_user:
|
if ref_user:
|
||||||
badge_grant(user=ref_user, badge_id=10)
|
badge_grant(user=ref_user, badge_id=10)
|
||||||
if ref_user.referral_count >= 10:
|
# off-by-one: newly referred user isn't counted
|
||||||
|
if ref_user.referral_count >= 9:
|
||||||
badge_grant(user=ref_user, badge_id=11)
|
badge_grant(user=ref_user, badge_id=11)
|
||||||
if ref_user.referral_count >= 100:
|
if ref_user.referral_count >= 99:
|
||||||
badge_grant(user=ref_user, badge_id=12)
|
badge_grant(user=ref_user, badge_id=12)
|
||||||
|
|
||||||
if email:
|
if email:
|
||||||
|
|
Loading…
Reference in New Issue