Skip to content

Commit 3098b06

Browse files
Allow super user to bypass ratelimit
1 parent 28f58b3 commit 3098b06

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

api/views.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,24 @@ def create(self, request, format="json"):
213213
"""
214214
runs the job.
215215
"""
216-
if (
217-
ExportRun.objects.filter(
218-
created_at__gt=timezone.now() - timedelta(minutes=1), user=request.user
219-
).count()
220-
>= 1
221-
):
222-
return Response(
223-
{"status": "RATE_LIMITED"}, status=status.HTTP_400_BAD_REQUEST
224-
)
216+
if not request.user.is_superuser:
217+
if (
218+
ExportRun.objects.filter(
219+
created_at__gt=timezone.now() - timedelta(minutes=1),
220+
user=request.user,
221+
).count()
222+
>= 1
223+
):
224+
return Response(
225+
{"status": "RATE_LIMITED"}, status=status.HTTP_400_BAD_REQUEST
226+
)
225227

226228
job_uid = request.query_params.get("job_uid", None)
227-
if Job.objects.get(uid=job_uid).last_run_status == "SUBMITTED":
228-
return Response(
229-
{"status": "PREVIOUS_RUN_IN_QUEUE"}, status=status.HTTP_400_BAD_REQUEST
230-
)
229+
if not request.user.is_superuser:
230+
if Job.objects.get(uid=job_uid).last_run_status == "SUBMITTED":
231+
return Response(
232+
{"status": "PREVIOUS_RUN_IN_QUEUE"}, status=status.HTTP_400_BAD_REQUEST
233+
)
231234
task_runner = ExportTaskRunner()
232235
task_runner.run_task(job_uid=job_uid, user=request.user)
233236
return Response({"status": "OK"}, status=status.HTTP_201_CREATED)

0 commit comments

Comments
 (0)