From 8de3641624023697615fce97b90c36b35dc2b22b Mon Sep 17 00:00:00 2001 From: notpua Date: Thu, 16 May 2024 22:03:46 +0530 Subject: [PATCH 1/3] feature: add approval times --- mtypes.py | 9 +++++++++ mutations.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/mtypes.py b/mtypes.py index f2871a3..9934423 100644 --- a/mtypes.py +++ b/mtypes.py @@ -56,8 +56,11 @@ class Event_Status: room: bool = False budget: bool = False cc_approver: str | None = None + cc_approver_time: str | None = None slo_approver: str | None = None + slo_approver_time: str | None = None slc_approver: str | None = None + slc_approver_time: str | None = None # def __init__ (self, state: Event_State_Status = None, room: Event_Room_Status = None, budget: Event_Budget_Status = None) : # self.state: Event_State_Status = Event_State_Status.incomplete if state is None else state @@ -69,15 +72,21 @@ def __init__( room: bool = False, budget: bool = False, cc_approver: str | None = None, + cc_approver_time: str = "notset", slo_approver: str | None = None, + slo_approver_time: str = "notset", slc_approver: str | None = None, + slc_approver_time: str = "notset", ): self.state = state self.room = room self.budget = budget self.cc_approver = cc_approver + self.cc_approver_time = cc_approver_time self.slo_approver = slo_approver + self.slo_approver_time = slo_approver_time self.slc_approver = slc_approver + self.slc_approver_time = slc_approver_time # Event Modes diff --git a/mutations.py b/mutations.py index d74b42e..934025c 100644 --- a/mutations.py +++ b/mutations.py @@ -1,8 +1,9 @@ import strawberry -from datetime import timedelta +from datetime import timedelta, datetime from pydantic import HttpUrl, parse_obj_as from fastapi.encoders import jsonable_encoder import os +import logging from db import eventsdb @@ -110,6 +111,9 @@ def createEvent(details: InputEventDetails, info: Info) -> EventType: else: event_instance.status.state = Event_State_Status.incomplete + # debug + logging.error(event_instance) + # set event code event_instance.code = getEventCode(details.clubid, details.datetimeperiod[0]) @@ -254,6 +258,10 @@ def progressEvent( raise noaccess_error event_instance = Event.parse_obj(event_ref) + # get current time + current_time = datetime.now() + time_str = current_time.strftime("%d-%m-%Y %I:%M %p") + if event_instance.status.state == Event_State_Status.incomplete: if user["role"] != "club" or user["uid"] != event_instance.clubid: raise noaccess_error @@ -266,6 +274,9 @@ def progressEvent( "cc_approver": event_instance.status.cc_approver, "slc_approver": event_instance.status.slc_approver, "slo_approver": event_instance.status.slo_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": event_instance.status.slo_approver_time, } elif event_instance.status.state == Event_State_Status.pending_cc: @@ -279,6 +290,9 @@ def progressEvent( "cc_approver": user["uid"], "slc_approver": event_instance.status.slc_approver, "slo_approver": event_instance.status.slo_approver, + "cc_approver_time": time_str, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": event_instance.status.slo_approver_time, } if cc_progress_budget is not None: updation["budget"] = cc_progress_budget @@ -292,8 +306,13 @@ def progressEvent( if not updation["budget"]: updation["state"] = Event_State_Status.pending_budget.value elif not updation["room"]: + # if budget is approved + updation["slc_approver_time"] = time_str updation["state"] = Event_State_Status.pending_room.value else: + # if both are approved + updation["slc_approver_time"] = time_str + updation["slo_approver_time"] = time_str updation["state"] = Event_State_Status.approved.value elif event_instance.status.state == Event_State_Status.pending_budget: @@ -307,11 +326,15 @@ def progressEvent( "slc_approver": user["uid"], "slo_approver": event_instance.status.slo_approver, "cc_approver": event_instance.status.cc_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": time_str, + "slo_approver_time": event_instance.status.slo_approver_time, } if not updation["room"]: updation["state"] = Event_State_Status.pending_room.value else: + updation["slo_approver_time"] = time_str updation["state"] = Event_State_Status.approved.value elif event_instance.status.state == Event_State_Status.pending_room: @@ -326,6 +349,9 @@ def progressEvent( "slo_approver": user["uid"], "slc_approver": event_instance.status.slc_approver, "cc_approver": event_instance.status.cc_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": time_str, } elif event_instance.status.state == Event_State_Status.approved: @@ -341,6 +367,9 @@ def progressEvent( "cc_approver": event_instance.status.cc_approver, "slc_approver": event_instance.status.slc_approver, "slo_approver": event_instance.status.slo_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": event_instance.status.slo_approver_time, } upd_ref = eventsdb.update_one({"_id": eventid}, {"$set": {"status": updation}}) From 2fecbd779b6bd403f8d0d62ac53e531fc3d4180c Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Fri, 17 May 2024 16:31:01 +0530 Subject: [PATCH 2/3] Updated deafult values of the EventStatus Class and where it is being set --- mtypes.py | 17 ++++++++++++----- mutations.py | 22 ++++++++++------------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/mtypes.py b/mtypes.py index 9934423..f7d93ef 100644 --- a/mtypes.py +++ b/mtypes.py @@ -50,15 +50,18 @@ class Event_State_Status(StrEnum): @strawberry.type class Event_Status: - state: Event_State_Status = Event_State_Status.incomplete + state: Event_State_Status = Event_State_Status.incomplete # type: ignore # room: Event_Room_Status = Event_Room_Status.unapproved # budget: Event_Budget_Status = Event_Budget_Status.unapproved room: bool = False budget: bool = False + cc_approver: str | None = None cc_approver_time: str | None = None + slo_approver: str | None = None slo_approver_time: str | None = None + slc_approver: str | None = None slc_approver_time: str | None = None @@ -66,25 +69,29 @@ class Event_Status: # self.state: Event_State_Status = Event_State_Status.incomplete if state is None else state # self.room: Event_Room_Status = Event_Room_Status.unapproved if room is None else room # self.budget: Event_Budget_Status = Event_Budget_Status.unapproved if budget is None else budget + def __init__( self, - state: Event_State_Status = Event_State_Status.incomplete, + state: Event_State_Status = Event_State_Status.incomplete, # type: ignore room: bool = False, budget: bool = False, cc_approver: str | None = None, - cc_approver_time: str = "notset", + cc_approver_time: str | None = None, slo_approver: str | None = None, - slo_approver_time: str = "notset", + slo_approver_time: str | None = None, slc_approver: str | None = None, - slc_approver_time: str = "notset", + slc_approver_time: str | None = None, ): self.state = state self.room = room self.budget = budget + self.cc_approver = cc_approver self.cc_approver_time = cc_approver_time + self.slo_approver = slo_approver self.slo_approver_time = slo_approver_time + self.slc_approver = slc_approver self.slc_approver_time = slc_approver_time diff --git a/mutations.py b/mutations.py index 934025c..8aca354 100644 --- a/mutations.py +++ b/mutations.py @@ -111,9 +111,6 @@ def createEvent(details: InputEventDetails, info: Info) -> EventType: else: event_instance.status.state = Event_State_Status.incomplete - # debug - logging.error(event_instance) - # set event code event_instance.code = getEventCode(details.clubid, details.datetimeperiod[0]) @@ -271,12 +268,13 @@ def progressEvent( "room": False, # or len(event_instance.location) == 0, "state": Event_State_Status.pending_cc.value, - "cc_approver": event_instance.status.cc_approver, - "slc_approver": event_instance.status.slc_approver, - "slo_approver": event_instance.status.slo_approver, - "cc_approver_time": event_instance.status.cc_approver_time, - "slc_approver_time": event_instance.status.slc_approver_time, - "slo_approver_time": event_instance.status.slo_approver_time, + + "cc_approver": None, + "slc_approver": None, + "slo_approver": None, + "cc_approver_time": "Not Approved", + "slc_approver_time": "Not Approved", + "slo_approver_time": "Not Approved", } elif event_instance.status.state == Event_State_Status.pending_cc: @@ -307,12 +305,12 @@ def progressEvent( updation["state"] = Event_State_Status.pending_budget.value elif not updation["room"]: # if budget is approved - updation["slc_approver_time"] = time_str + updation["slc_approver_time"] = None updation["state"] = Event_State_Status.pending_room.value else: # if both are approved - updation["slc_approver_time"] = time_str - updation["slo_approver_time"] = time_str + updation["slc_approver_time"] = None + updation["slo_approver_time"] = None updation["state"] = Event_State_Status.approved.value elif event_instance.status.state == Event_State_Status.pending_budget: From 84da9045667dc7243fb6e94fd99c661f8cbcc41a Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Fri, 17 May 2024 16:45:48 +0530 Subject: [PATCH 3/3] Fix getUser if it returns None, and change the variable name for more readability --- mutations.py | 54 +++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/mutations.py b/mutations.py index 8aca354..c84f779 100644 --- a/mutations.py +++ b/mutations.py @@ -3,7 +3,6 @@ from pydantic import HttpUrl, parse_obj_as from fastapi.encoders import jsonable_encoder import os -import logging from db import eventsdb @@ -375,44 +374,44 @@ def progressEvent( raise noaccess_error event_ref = eventsdb.find_one({"_id": eventid}) - event = Event.parse_obj(event_ref) + updated_event_instance = Event.parse_obj(event_ref) # trigger mail notification # Data Preparation for the mailing mail_uid = user["uid"] - mail_club = getClubNameEmail(event.clubid, email=True, name=True) + mail_club = getClubNameEmail(updated_event_instance.clubid, email=True, name=True) if mail_club is None: raise Exception("Club does not exist.") else: clubname, mail_club = mail_club - mail_event_title = event.name - mail_eventlink = getEventLink(event.code) - mail_description = event.description + mail_event_title = updated_event_instance.name + mail_eventlink = getEventLink(updated_event_instance.code) + mail_description = updated_event_instance.description if mail_description == "": mail_description = "N/A" - student_count = event.population + student_count = updated_event_instance.population mail_location = "" - if event.mode == Event_Mode.online: + if updated_event_instance.mode == Event_Mode.online: mail_location = "online" student_count = "N/A" else: mail_location = ", ".join( - [getattr(Event_Full_Location, loc) for loc in event.location] + [getattr(Event_Full_Location, loc) for loc in updated_event_instance.location] ) equipment, additional = "N/A", "N/A" - if event.equipment: - equipment = event.equipment - if event.additional: - additional = event.additional + if updated_event_instance.equipment: + equipment = updated_event_instance.equipment + if updated_event_instance.additional: + additional = updated_event_instance.additional ist_offset = timedelta(hours=5, minutes=30) - start_dt = event.datetimeperiod[0] + ist_offset - end_dt = event.datetimeperiod[1] + ist_offset + start_dt = updated_event_instance.datetimeperiod[0] + ist_offset + end_dt = updated_event_instance.datetimeperiod[1] + ist_offset event_start_time = ( str(start_dt.strftime("%d-%m-%Y")) + " " + str(start_dt.strftime("%H:%M")) ) @@ -420,7 +419,10 @@ def progressEvent( str(end_dt.strftime("%d-%m-%Y")) + " " + str(end_dt.strftime("%H:%M")) ) - poc_details, poc_phone = getUser(event.poc, info.context.cookies) + poc = getUser(updated_event_instance.poc, info.context.cookies) + if not poc: + raise Exception("POC does not exist.") + poc_details, poc_phone = poc poc_name = poc_details["firstName"] + " " + poc_details["lastName"] poc_email = poc_details["email"] poc_roll = poc_details["rollno"] @@ -440,9 +442,9 @@ def progressEvent( eventlink=mail_eventlink, ) - if event.status.state == Event_State_Status.pending_room: + if updated_event_instance.status.state == Event_State_Status.pending_room: mail_body = PROGRESS_EVENT_BODY_FOR_SLO.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, club=clubname, event=mail_event_title, description=mail_description, @@ -459,7 +461,7 @@ def progressEvent( ) mail_to = [] - if event.status.state == Event_State_Status.pending_cc: + if updated_event_instance.status.state == Event_State_Status.pending_cc: mail_to = getRoleEmails("cc") # Mail to club also for the successful submission of the event @@ -467,13 +469,13 @@ def progressEvent( mail_club, ] mail_subject_club = CLUB_EVENT_SUBJECT.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, event=mail_event_title, ) mail_body_club = SUBMIT_EVENT_BODY_FOR_CLUB.safe_substitute( event=mail_event_title, eventlink=mail_eventlink, - event_id=event.code, + event_id=updated_event_instance.code, club=clubname, description=mail_description, start_time=event_start_time, @@ -492,17 +494,17 @@ def progressEvent( toRecipients=mail_to_club, cookies=info.context.cookies, ) - if event.status.state == Event_State_Status.pending_budget: + if updated_event_instance.status.state == Event_State_Status.pending_budget: mail_to = getRoleEmails("slc") - if event.status.state == Event_State_Status.pending_room: + if updated_event_instance.status.state == Event_State_Status.pending_room: mail_to = getRoleEmails("slo") - if event.status.state == Event_State_Status.approved: + if updated_event_instance.status.state == Event_State_Status.approved: # mail to the club email mail_to = [ mail_club, ] mail_subject = CLUB_EVENT_SUBJECT.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, event=mail_event_title, ) mail_body = APPROVED_EVENT_BODY_FOR_CLUB.safe_substitute( @@ -520,7 +522,7 @@ def progressEvent( cookies=info.context.cookies, ) - return EventType.from_pydantic(event) + return EventType.from_pydantic(updated_event_instance) @strawberry.mutation