Skip to content

Commit

Permalink
update application end time validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rm03 committed Nov 23, 2023
1 parent 57cbddf commit 3576e99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
29 changes: 19 additions & 10 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4458,10 +4458,17 @@ def question_response(self, *args, **kwargs):

# prevent submissions outside of the open duration
now = timezone.now()
if (
now > application.application_end_time
or now < application.application_start_time
):
extension = (
application.extensions.filter(user=self.request.user)
.order_by("-end_time")
.first()
)
end_time = (
max(extension.end_time, application.application_end_time)
if extension
else application.application_end_time
)
if now > end_time or now < application.application_start_time:
return Response(
{"success": False, "detail": "This application is not currently open!"}
)
Expand Down Expand Up @@ -4808,11 +4815,13 @@ def current(self, *args, **kwargs):
---
"""
qs = self.get_queryset()
return Response(
ClubApplicationSerializer(
qs.filter(application_end_time__gte=timezone.now()), many=True
).data
)
now = timezone.now()
user = self.request.user
q = Q(application_end_time__gte=now)
if user.is_authenticated:
q |= Q(extensions__end_time__gte=now, extensions__user=user)

return Response(ClubApplicationSerializer(qs.filter(q), many=True).data)

@action(detail=True, methods=["post"])
def duplicate(self, *args, **kwargs):
Expand Down Expand Up @@ -4953,7 +4962,7 @@ def get_queryset(self):


class ApplicationExtensionViewSet(viewsets.ModelViewSet):
# permission_classes = [ClubSensitiveItemPermission | IsSuperuser]
permission_classes = [ClubSensitiveItemPermission | IsSuperuser]
serializer_class = ApplicationExtensionSerializer

def get_queryset(self):
Expand Down
18 changes: 0 additions & 18 deletions frontend/pages/club/[club]/application/[application]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,6 @@ const ApplicationPage = ({
}
}

// submissions open & close error check
const applicationStartTime = moment.tz(
application.application_start_time,
'America/New_York',
)

const applicationEndTime = moment.tz(
application.application_end_time,
'America/New_York',
)
const currentTime = moment.tz('America/New_York')
if (
currentTime.valueOf() < applicationStartTime.valueOf() ||
currentTime.valueOf() > applicationEndTime.valueOf()
) {
submitErrors = 'This application is not currently open!'
}

if (submitErrors === null) {
const body: any = { questionIds: [] }
for (const [questionId, text] of Object.entries(values).filter(
Expand Down

0 comments on commit 3576e99

Please sign in to comment.