Skip to content

Commit

Permalink
Merge pull request #48 from Clubs-Council-IIITH/add_rejection
Browse files Browse the repository at this point in the history
mutation: add a new rejection feature
  • Loading branch information
bhavberi authored Oct 4, 2024
2 parents 7961576 + 90e3bb7 commit 76aea5b
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 10 deletions.
26 changes: 26 additions & 0 deletions mailing_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@
Clubs Council.
Note: This automated email has been generated from the Clubs Council website. For more details, visit clubs.iiit.ac.in.
""" # noqa: E501
)

REJECT_EVENT_SUBJECT = Template(
"""
[Events] $event_id: $event Rejected
"""
)

REJECT_EVENT_BODY_FOR_CLUB = Template(
"""
Dear $club,
Your event, $event, has been sent back for revisions by $deleted_by.
Reason Provided:
$reason
To update the event details, please visit the following link:
$eventlink
Best regards,
Clubs Council.
Note: This automated email has been generated from the Clubs Council website. For more details, visit clubs.iiit.ac.in.
""" # noqa: E501
)
90 changes: 80 additions & 10 deletions mutations/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
PROGRESS_EVENT_BODY_FOR_SLC,
PROGRESS_EVENT_BODY_FOR_SLO,
PROGRESS_EVENT_SUBJECT,
REJECT_EVENT_BODY_FOR_CLUB,
REJECT_EVENT_SUBJECT,
SUBMIT_EVENT_BODY_FOR_CLUB,
)

Expand All @@ -43,6 +45,9 @@
)

inter_communication_secret_global = os.getenv("INTER_COMMUNICATION_SECRET")
noaccess_error = Exception(
"Can not access event. Either it does not exist or user does not have perms." # noqa: E501
)


@strawberry.mutation
Expand Down Expand Up @@ -146,7 +151,9 @@ def createEvent(details: InputEventDetails, info: Info) -> EventType:
created_id = eventsdb.insert_one(
jsonable_encoder(event_instance)
).inserted_id
created_event = Event.model_validate(eventsdb.find_one({"_id": created_id}))
created_event = Event.model_validate(
eventsdb.find_one({"_id": created_id})
)

return EventType.from_pydantic(created_event)

Expand Down Expand Up @@ -288,9 +295,6 @@ def progressEvent(
after room is approved (through any track), the event is `approved`
once the event is over, the club or cc can change the state to `completed`
""" # noqa: E501
noaccess_error = Exception(
"Can not access event. Either it does not exist or user does not have perms." # noqa: E501
)

user = info.context.user

Expand Down Expand Up @@ -668,9 +672,7 @@ def deleteEvent(eventid: str, info: Info) -> EventType:

event_ref = eventsdb.find_one(query)
if event_ref is None:
raise Exception(
"Can not access event. Either it does not exist or user does not have perms." # noqa: E501
)
raise noaccess_error
event_instance = Event.model_validate(event_ref)

updation = event_ref["status"]
Expand All @@ -691,9 +693,7 @@ def deleteEvent(eventid: str, info: Info) -> EventType:

event_ref = eventsdb.update_one(query, {"$set": {"status": updation}})
if event_ref.matched_count == 0:
raise Exception(
"Can not access event. Either it does not exist or user does not have perms." # noqa: E501
)
raise noaccess_error

# Send the event deleted email.
if event_instance.status.state not in [
Expand Down Expand Up @@ -773,6 +773,75 @@ def deleteEvent(eventid: str, info: Info) -> EventType:
return EventType.from_pydantic(Event.model_validate(event_ref))


@strawberry.mutation
def rejectEvent(
eventid: str,
reason: str,
info: Info,
) -> EventType:
"""Reject Event by CC and reset the state to incomplete"""
user = info.context.user

if user is None or user["role"] != "cc":
raise Exception("Not Authenticated!")

query = {
"_id": eventid,
}

event_ref = eventsdb.find_one(query)
if event_ref is None:
raise noaccess_error

event_instance = Event.model_validate(event_ref)

clubDetails = getClubDetails(event_instance.clubid, info.context.cookies)
if len(clubDetails.keys()) == 0:
raise Exception("Club does not exist.")
else:
mail_club = clubDetails["email"]
clubname = clubDetails["name"]

if event_instance.status.state != Event_State_Status.pending_cc:
raise Exception("Cannot reset event that has progressed beyond CC.")

status = event_instance.model_dump()["status"]
status["state"] = Event_State_Status.incomplete.value
status["budget"] = False
status["room"] = False
status["submission_time"] = None

upd_ref = eventsdb.update_one(
{"_id": eventid}, {"$set": {"status": status}}
)
if upd_ref.matched_count == 0:
raise noaccess_error

# Send email to Club for allowing edits
mail_to = [mail_club]
mail_subject = REJECT_EVENT_SUBJECT.safe_substitute(
event_id=event_instance.code,
event=event_instance.name,
)
mail_body = REJECT_EVENT_BODY_FOR_CLUB.safe_substitute(
club=clubname,
event=event_instance.name,
eventlink=getEventLink(event_instance.code),
reason=reason,
deleted_by="Clubs Council",
)

triggerMail(
user["uid"],
mail_subject,
mail_body,
toRecipients=mail_to,
cookies=info.context.cookies,
)

return EventType.from_pydantic(Event.model_validate(event_ref))


@strawberry.mutation
def updateEventsCid(
info: Info,
Expand Down Expand Up @@ -807,5 +876,6 @@ def updateEventsCid(
editEvent,
progressEvent,
deleteEvent,
rejectEvent,
updateEventsCid,
]

0 comments on commit 76aea5b

Please sign in to comment.