Skip to content

Commit

Permalink
Merge pull request #160 from UnitapApp/feature/gastap_dynamic_round_d…
Browse files Browse the repository at this point in the history
…uration

db error permissions
  • Loading branch information
Mohamad Bastin authored Oct 27, 2023
2 parents 8b76d1e + 82346ec commit 7a6cd8f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
25 changes: 25 additions & 0 deletions permissions/migrations/0007_oncepermonthverification.py
Original file line number Diff line number Diff line change
@@ -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',),
),
]
25 changes: 25 additions & 0 deletions permissions/migrations/0008_onceperweekverification.py
Original file line number Diff line number Diff line change
@@ -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',),
),
]
40 changes: 21 additions & 19 deletions permissions/models.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7a6cd8f

Please sign in to comment.