Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add daily approval request limit and tracking #4400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def __init__(self, *args, **kwargs):
null=True, blank=True, max_length=2048, default=""
)
slack_webhook_url = models.URLField(max_length=200, blank=True, null=True)
daily_approval_request_limit = models.IntegerField(null=True, blank=True, default=5)
last_daily_approval_request = models.DateTimeField(null=True, blank=True)
# Identifier for the github repository of a challenge in format: account_name/repository_name
github_repository = models.CharField(
max_length=1000, null=True, blank=True, default=""
Expand Down
16 changes: 16 additions & 0 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4648,6 +4648,8 @@ def request_challenge_approval_by_pk(request, challenge_pk):
and send approval request for the challenge
"""
challenge = get_challenge_model(challenge_pk)
daily_approval_request_limit = challenge.daily_approval_request_limit
last_check_time = challenge.last_daily_approval_request
challenge_phases = ChallengePhase.objects.filter(challenge=challenge)
unfinished_phases = []

Expand All @@ -4664,6 +4666,20 @@ def request_challenge_approval_by_pk(request, challenge_pk):
error_message = f"The following challenge phases do not have finished submissions: {', '.join(unfinished_phases)}"
return Response({"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE)

# check if the last time check is today, then check if the daily limit is reached
if last_check_time.date() == timezone.now().date():
if daily_approval_request_limit == 0:
error_message = "Sorry, the daily submission limit for approval requests has been reached."
return Response(
{"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
)
challenge.daily_approval_requests += 1

# if the last time check is not today, reset the daily approval requests
if last_check_time.date() != timezone.now().date():
challenge.daily_approval_requests = 0
challenge.last_daily_approval_request = timezone.now()
challenge.save()
if not settings.DEBUG:
try:
evalai_api_server = settings.EVALAI_API_SERVER
Expand Down