Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion zeeguu/core/user_feature_toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def _feature_map():
"daily_feedback": _daily_feedback,
"hide_recommendations": _hide_recommendations,
"show_non_simplified_articles": _show_non_simplified_articles,
"gamification": _gamification
}


Expand Down Expand Up @@ -90,8 +91,41 @@ def _hide_recommendations(user):
return False

COHORTS_WITH_HIDDEN_RECOMMENDATIONS = {564}

for user_cohort in user.cohorts:
if user_cohort.cohort_id in COHORTS_WITH_HIDDEN_RECOMMENDATIONS:
return True
return False

# Gamification feature flag logic
from sqlalchemy.exc import NoResultFound

from .model.user import User
from .model.cohort import Cohort
from datetime import datetime, date
GAMIFICATION_START_DATE = date(2026, 4, 1)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be the start date?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we do not have a start date. That logic is not needed. The experiment will have two groups one with gamification and one without from day one.

def _gamification(user: User):
"""
Enable general gamification features for users whose invitation with the gamification invite code,
or who are in the gamification cohort. This includes features like badges, friends, and leaderboards.
"""

GAMIFICATION_INVITE_CODE = "CD8HGKKJ"
if user.is_dev:
return True

# Invitation code can be None
invitation_code = user.invitation_code or ""
if invitation_code.lower() == GAMIFICATION_INVITE_CODE.lower():
return True

# Find gamification cohort by invite code, if it exists.
try:
gamification_cohort = Cohort.find_by_code(GAMIFICATION_INVITE_CODE)
except NoResultFound:
gamification_cohort = None

if gamification_cohort and user.is_member_of_cohort(gamification_cohort.id):
return True

# Disabled for everyone else
return False
Loading