Skip to content

Commit

Permalink
Fix check for editing club application committees after start time
Browse files Browse the repository at this point in the history
  • Loading branch information
julianweng committed Feb 13, 2024
1 parent 3b49bcd commit 900e1b4
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ def get_status(self, obj):
Return the status string of the status associated with the submission
"""
status_string = ApplicationSubmission.STATUS_TYPES[0][1]
for (status, name) in ApplicationSubmission.STATUS_TYPES:
for status, name in ApplicationSubmission.STATUS_TYPES:
if obj["status"] == status:
status_string = name
return status_string
Expand Down Expand Up @@ -2746,12 +2746,6 @@ def get_image_url(self, obj):
def validate(self, data):
acceptance_template = data.get("acceptance_email", "")
rejection_template = data.get("rejection_email", "")
request = self.context["request"].data

if "committees" in request and data["application_start_time"] < timezone.now():
raise serializers.ValidationError(
"You cannot edit committees once the application is open"
)

if not ClubApplication.validate_template(
acceptance_template
Expand Down Expand Up @@ -2790,19 +2784,24 @@ def save(self):
# manually create committee objects as Django does
# not support nested serializers out of the box
request = self.context["request"].data

# only allow modifications to committees if the application is not yet open
now = timezone.now()
if "committees" in request and application_obj.application_start_time > now:
committees = map(
prev_committees = ApplicationCommittee.objects.filter(
application=application_obj
)
prev_committee_names = list(map(lambda x: x.name, prev_committees))
committees = list(
map(
lambda x: x["value"] if "value" in x else x["name"],
request["committees"],
)
prev_committees = ApplicationCommittee.objects.filter(
application=application_obj
)
)
if prev_committee_names != committees:
if application_obj.application_start_time > now:
raise serializers.ValidationError(
"You cannot edit committees once the application is open"
)
# nasty hack for idempotency
prev_committee_names = prev_committees.values("name")
for prev_committee in prev_committees:
if prev_committee.name not in committees:
prev_committee.delete()
Expand Down

0 comments on commit 900e1b4

Please sign in to comment.