diff --git a/permissions/migrations/0007_oncepermonthverification.py b/permissions/migrations/0007_oncepermonthverification.py new file mode 100644 index 00000000..da275fbd --- /dev/null +++ b/permissions/migrations/0007_oncepermonthverification.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.4 on 2023-10-27 18:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('permissions', '0006_remove_onceperweekverification_permission_ptr_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='OncePerMonthVerification', + fields=[ + ('permission_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='permissions.permission')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('permissions.permission',), + ), + ] diff --git a/permissions/migrations/0008_onceperweekverification.py b/permissions/migrations/0008_onceperweekverification.py new file mode 100644 index 00000000..054ec0ed --- /dev/null +++ b/permissions/migrations/0008_onceperweekverification.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.4 on 2023-10-27 18:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('permissions', '0007_oncepermonthverification'), + ] + + operations = [ + migrations.CreateModel( + name='OncePerWeekVerification', + fields=[ + ('permission_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='permissions.permission')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('permissions.permission',), + ), + ] diff --git a/permissions/models.py b/permissions/models.py index 1a80cc56..c1d5e0a7 100644 --- a/permissions/models.py +++ b/permissions/models.py @@ -1,6 +1,8 @@ from django.db import models from polymorphic.models import PolymorphicModel +from faucet.faucet_manager.credit_strategy import RoundCreditStrategy + class Permission(PolymorphicModel): name = models.CharField(max_length=200) @@ -30,28 +32,28 @@ def response(self): return "You must be Aura verified on BrightID to claim this token." -# class OncePerWeekVerification(Permission): -# def is_valid(self, user_profile, *args, **kwargs): -# token_distribution = kwargs.get("token_distribution") -# return not token_distribution.claims.filter( -# user_profile=user_profile, -# created_at__gte=WeeklyCreditStrategy.get_last_monday(), -# ).exists() +class OncePerWeekVerification(Permission): + def is_valid(self, user_profile, *args, **kwargs): + token_distribution = kwargs.get("token_distribution") + return not token_distribution.claims.filter( + user_profile=user_profile, + created_at__gte=RoundCreditStrategy.get_start_of_the_round(), + ).exists() + + def response(self): + return "You have already claimed this token this week" -# def response(self): -# return "You have already claimed this token this week" +class OncePerMonthVerification(Permission): + def is_valid(self, user_profile, *args, **kwargs): + token_distribution = kwargs.get("token_distribution") + return not token_distribution.claims.filter( + user_profile=user_profile, + created_at__gte=RoundCreditStrategy.get_start_of_the_round(), + ).exists() -# class OncePerMonthVerification(Permission): -# def is_valid(self, user_profile, *args, **kwargs): -# token_distribution = kwargs.get("token_distribution") -# return not token_distribution.claims.filter( -# user_profile=user_profile, -# created_at__gte=WeeklyCreditStrategy.get_first_day_of_the_month(), -# ).exists() - -# def response(self): -# return "You have already claimed this token this month" + def response(self): + return "You have already claimed this token this month" class OnceInALifeTimeVerification(Permission):