Skip to content

Commit

Permalink
feat(economy): add ranked season revoke consent mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexaor committed Nov 12, 2024
1 parent b91b7fe commit 44a9b45
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
45 changes: 44 additions & 1 deletion economy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class LeaderboardEntry(graphene.ObjectType):

class CurrentRankSeason(graphene.ObjectType):
is_participant = graphene.Boolean()
has_revoked_ranked_consent = graphene.Boolean()
ranked_season = graphene.Int()
season_expenditure = graphene.Int()
placement = graphene.Int()
Expand All @@ -711,13 +712,24 @@ class SociRankedQuery(graphene.ObjectType):
def resolve_current_ranked_season(self, info, *args, **kwargs):
current_user = info.context.user

if current_user.has_revoked_ranked_consent:
return CurrentRankSeason(
is_participant=False,
season_expenditure=0,
placement=None,
has_revoked_ranked_consent=True,
)

current_season = (
SociRankedSeason.objects.all().order_by("season_start_date").last()
)

if not current_season:
return CurrentRankSeason(
is_participant=False, season_expenditure=0, placement=None
is_participant=False,
season_expenditure=0,
placement=None,
has_revoked_ranked_consent=current_user.has_revoked_ranked_consent,
)

season_start_datetime = timezone.make_aware(
Expand Down Expand Up @@ -754,6 +766,7 @@ def resolve_current_ranked_season(self, info, *args, **kwargs):
if not is_participant and not current_user.is_superuser:
return CurrentRankSeason(
is_participant=False,
has_revoked_ranked_consent=current_user.has_revoked_ranked_consent,
season_expenditure=0,
placement=None,
participant_count=leaderboard.count(),
Expand Down Expand Up @@ -782,6 +795,7 @@ def resolve_current_ranked_season(self, info, *args, **kwargs):

return CurrentRankSeason(
is_participant=True,
has_revoked_ranked_consent=current_user.has_revoked_ranked_consent,
season_expenditure=user_expenditure,
placement=placement,
top_ten=top_ten_data_list,
Expand Down Expand Up @@ -810,10 +824,38 @@ def mutate(self, info):
)

current_user = info.context.user

if current_user.has_revoked_ranked_consent:
return JoinRankedSeasonMutation(
success=False,
message="Already revoked consent. Cannot join this season",
)
last_season.participants.add(current_user)
return JoinRankedSeasonMutation(success=True)


class RevokeRankedSeasonConsentMutation(graphene.Mutation):
class Arguments:
pass

success = graphene.Boolean()
message = graphene.String()

@gql_login_required()
def mutate(self, info):
last_season = SociRankedSeason.objects.order_by("season_start_date").last()
if last_season.season_end_date:
return RevokeRankedSeasonConsentMutation(
success=False, message="Cannot revoke consent after finished season."
)

current_user = info.context.user
last_season.participants.remove(current_user)
current_user.has_revoked_ranked_consent = True
current_user.save()
return RevokeRankedSeasonConsentMutation(success=True)


class UndoProductOrderMutation(graphene.Mutation):
class Arguments:
id = graphene.ID(required=True)
Expand Down Expand Up @@ -1447,3 +1489,4 @@ class EconomyMutations(graphene.ObjectType):
crash_stock_market = CrashStockMarketMutation.Field()

join_ranked_season = JoinRankedSeasonMutation.Field()
revoke_ranked_consent = RevokeRankedSeasonConsentMutation.Field()
18 changes: 18 additions & 0 deletions users/migrations/0003_user_has_revoked_ranked_consent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-11-12 00:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0002_user_can_rewrite_about_me'),
]

operations = [
migrations.AddField(
model_name='user',
name='has_revoked_ranked_consent',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class User(AbstractUser):
requires_migration_wizard = models.BooleanField(default=False)
first_time_login = models.BooleanField(default=True)
can_rewrite_about_me = models.BooleanField(default=True)
has_revoked_ranked_consent = models.BooleanField(default=False)

ical_token = models.CharField(
max_length=128, unique=True, null=True, blank=True, default=None
Expand Down

0 comments on commit 44a9b45

Please sign in to comment.