From e979f5456bb696afdd4697b3f5f2f547198608c4 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Wed, 13 Mar 2024 15:09:02 +0530 Subject: [PATCH 1/9] inter_communication_secret --- mailing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mailing.py b/mailing.py index 620afc9..7bc1fe1 100644 --- a/mailing.py +++ b/mailing.py @@ -1,4 +1,7 @@ import requests +import os + +inter_communication_secret = os.getenv("INTER_COMMUNICATION_SECRET") # API call to send mail notification @@ -12,8 +15,8 @@ def triggerMail( ) -> None: try: query = """ - mutation Mutation($mailInput: MailInput!) { - sendMail(mailInput: $mailInput) + mutation Mutation($mailInput: MailInput!, $interCommunicationSecret: String) { + sendMail(mailInput: $mailInput, interCommunicationSecret: $interCommunicationSecret) } """ variables = { @@ -23,7 +26,8 @@ def triggerMail( "uid": uid, "toRecipients": toRecipients, "ccRecipients": ccRecipients, - } + }, + "interCommunicationCecret": inter_communication_secret, } if cookies: requests.post( From a394eeb098ab46789e2148c306a3bf850bd0c3c3 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Wed, 13 Mar 2024 15:09:37 +0530 Subject: [PATCH 2/9] Added updateEventsCid mutation --- mutations.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mutations.py b/mutations.py index 2451634..26a42e5 100644 --- a/mutations.py +++ b/mutations.py @@ -2,6 +2,7 @@ from datetime import timedelta from pydantic import HttpUrl, parse_obj_as from fastapi.encoders import jsonable_encoder +import os from db import eventsdb @@ -37,6 +38,8 @@ getUser, ) +inter_communication_secret_global = os.getenv("INTER_COMMUNICATION_SECRET") + @strawberry.mutation def createEvent(details: InputEventDetails, info: Info) -> EventType: @@ -573,10 +576,39 @@ def deleteEvent(eventid: str, info: Info) -> EventType: return EventType.from_pydantic(Event.parse_obj(upd_ref)) +@strawberry.mutation +def updateEventsCid( + info: Info, + old_cid: str, + new_cid: str, + inter_communication_secret: str | None = None, +) -> int: + """ + update all events of old_cid to new_cid + """ + user = info.context.user + + if user is None or user["role"] not in ["cc"]: + raise Exception("Not Authenticated!") + + if inter_communication_secret != inter_communication_secret_global: + raise Exception("Authentication Error! Invalid secret!") + + updation = { + "$set": { + "clubid": new_cid, + } + } + + upd_ref = eventsdb.update_many({"clubid": old_cid}, updation) + return upd_ref.modified_count + + # register all mutations mutations = [ createEvent, editEvent, progressEvent, deleteEvent, + updateEventsCid, ] From 89859de1e0a8843139d74a808ba48ca64c3ea1ee Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Sun, 17 Mar 2024 10:52:03 +0530 Subject: [PATCH 3/9] Allow clubs to see the draft events as well in calendar --- queries.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/queries.py b/queries.py index 2353fe9..7b054ae 100644 --- a/queries.py +++ b/queries.py @@ -79,9 +79,11 @@ def events(clubid: str | None, public: bool | None, info: Info) -> List[EventTyp clubAccess = False restrictCCAccess = True if user is not None and (public is None or public is False): - if user["role"] in {"cc", "slc", "slo"}: + if user["role"] in ["cc", "slc", "slo"]: restrictAccess = False - if user["role"] not in {"slc", "slo"}: + if user["role"] in [ + "cc", + ]: restrictCCAccess = False if user["role"] == "club": @@ -90,6 +92,10 @@ def events(clubid: str | None, public: bool | None, info: Info) -> List[EventTyp if user["uid"] == clubid: restrictCCAccess = False + assert not ( + restrictAccess and not restrictCCAccess + ), "restrictAccess and not restrictCCAccess can not be True at the same time." + searchspace = dict() if clubid is not None: searchspace["clubid"] = clubid @@ -115,7 +121,8 @@ def events(clubid: str | None, public: bool | None, info: Info) -> List[EventTyp if clubAccess: searchspace["audience"] = {"$nin": ["internal"]} statuses.append(Event_State_Status.pending_cc.value) - + statuses.append(Event_State_Status.incomplete.value) + searchspace["status.state"] = { "$in": statuses, } From 89609b32ac7bdebbb78fe9f4e547ba70c2bb1689 Mon Sep 17 00:00:00 2001 From: bhavberi Date: Sun, 17 Mar 2024 05:22:23 +0000 Subject: [PATCH 4/9] Apply Linting & Formatting Fixes --- queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries.py b/queries.py index 7b054ae..bbcfa62 100644 --- a/queries.py +++ b/queries.py @@ -122,7 +122,7 @@ def events(clubid: str | None, public: bool | None, info: Info) -> List[EventTyp searchspace["audience"] = {"$nin": ["internal"]} statuses.append(Event_State_Status.pending_cc.value) statuses.append(Event_State_Status.incomplete.value) - + searchspace["status.state"] = { "$in": statuses, } From 0e92def3e5262f2e5e23d713e15e01beeee8dca0 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Tue, 19 Mar 2024 11:47:30 +0530 Subject: [PATCH 5/9] New Event by CC is not directly approved --- mutations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mutations.py b/mutations.py index 26a42e5..1462868 100644 --- a/mutations.py +++ b/mutations.py @@ -103,9 +103,12 @@ def createEvent(details: InputEventDetails, info: Info) -> EventType: # if creator is CC, set state to approved if user["role"] == "cc": - event_instance.status.state = Event_State_Status.approved - event_instance.status.budget = True - event_instance.status.room = True + event_instance.status.state = Event_State_Status.pending_cc + # event_instance.status.state = Event_State_Status.approved + # event_instance.status.budget = True + # event_instance.status.room = True + else: + event_instance.status.state = Event_State_Status.incomplete # set event code event_instance.code = getEventCode(details.clubid, details.datetimeperiod[0]) From 309acb6d8f1922c74b3f42db6bb2e38351113415 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Thu, 21 Mar 2024 14:09:16 +0530 Subject: [PATCH 6/9] Send equipment and additional filled by club to SLO in their email template --- mailing_templates.py | 5 ++++- mutations.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mailing_templates.py b/mailing_templates.py index 7173403..f350b39 100644 --- a/mailing_templates.py +++ b/mailing_templates.py @@ -38,8 +38,11 @@ 6. End Date : $end_time 7. Location : $location + + 8. Equipment Support : $equipment + 9. Additional Information : $additional - 8. Point of Contact - + 10. Point of Contact - Name : $poc_name RollNo : $poc_roll Email : $poc_email diff --git a/mutations.py b/mutations.py index 1462868..734cc43 100644 --- a/mutations.py +++ b/mutations.py @@ -173,7 +173,7 @@ def editEvent(details: InputEditEventDetails, info: Info) -> EventType: if details.location is not None and updatable: # updates["status.room"] = False or user["role"] == "cc" updates["location"] = [Event_Location(loc) for loc in details.location] - if details.poc is not None and event_ref["poc"] != details.poc: + if details.poc is not None and event_ref.get("poc", None) != details.poc: updates["poc"] = details.poc # Check POC Details Exist or not if not getMember(details.clubid, details.poc, cookies=info.context.cookies): @@ -357,6 +357,12 @@ def progressEvent( [getattr(Event_Full_Location, loc) for loc in event.location] ) + equipment, additional = "N/A", "N/A" + if event.equipment: + equipment = event.equipment + if event.additional: + additional = event.additional + ist_offset = timedelta(hours=5, minutes=30) start_dt = event.datetimeperiod[0] + ist_offset end_dt = event.datetimeperiod[1] + ist_offset @@ -397,6 +403,8 @@ def progressEvent( start_time=event_start_time, end_time=event_end_time, location=mail_location, + equipment=equipment, + additional=additional, poc_name=poc_name, poc_roll=poc_roll, poc_email=poc_email, From 70f0b42f734bda4c3214c948044bd7d8bfe9efe0 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Sun, 17 Mar 2024 13:37:42 +0530 Subject: [PATCH 7/9] Added cc_approver functionality in the progress event --- mtypes.py | 3 +++ mutations.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/mtypes.py b/mtypes.py index ed6b460..b65f881 100644 --- a/mtypes.py +++ b/mtypes.py @@ -55,6 +55,7 @@ class Event_Status: # budget: Event_Budget_Status = Event_Budget_Status.unapproved room: bool = False budget: bool = False + cc_approver: 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 @@ -65,10 +66,12 @@ def __init__( state: Event_State_Status = Event_State_Status.incomplete, room: bool = False, budget: bool = False, + cc_approver: str | None = None, ): self.state = state self.room = room self.budget = budget + self.cc_approver = cc_approver # Event Modes diff --git a/mutations.py b/mutations.py index 734cc43..87f1d22 100644 --- a/mutations.py +++ b/mutations.py @@ -228,6 +228,7 @@ def progressEvent( info: Info, cc_progress_budget: bool | None = None, cc_progress_room: bool | None = None, + cc_approver: str | None = None, ) -> EventType: """ progress the event state status for different users @@ -277,6 +278,10 @@ def progressEvent( updation["budget"] = cc_progress_budget if cc_progress_room is not None: updation["room"] = cc_progress_room + if cc_approver is not None: + updation["cc_approver"] = cc_approver + else: + raise Exception("CC Approver is required to progress the event.") if not updation["budget"]: updation["state"] = Event_State_Status.pending_budget.value From c287e80b83e3c28ff84f03b647486f6ec4dc3596 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Sun, 17 Mar 2024 13:52:13 +0530 Subject: [PATCH 8/9] Save SLO and SLC Approvers' uids also --- mtypes.py | 6 ++++++ mutations.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/mtypes.py b/mtypes.py index b65f881..f2871a3 100644 --- a/mtypes.py +++ b/mtypes.py @@ -56,6 +56,8 @@ class Event_Status: room: bool = False budget: bool = False cc_approver: str | None = None + slo_approver: str | None = None + slc_approver: 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 @@ -67,11 +69,15 @@ def __init__( room: bool = False, budget: bool = False, cc_approver: str | None = None, + slo_approver: str | None = None, + slc_approver: str | None = None, ): self.state = state self.room = room self.budget = budget self.cc_approver = cc_approver + self.slo_approver = slo_approver + self.slc_approver = slc_approver # Event Modes diff --git a/mutations.py b/mutations.py index 87f1d22..f2bb824 100644 --- a/mutations.py +++ b/mutations.py @@ -298,6 +298,7 @@ def progressEvent( "budget": True, "room": event_instance.status.room, # | len(event_instance.location) == 0, + "slc_approver": user["uid"], } if not updation["room"]: @@ -314,6 +315,7 @@ def progressEvent( "budget": event_instance.status.budget, "room": True, "state": Event_State_Status.approved.value, + "slo_approver": user["uid"], } elif event_instance.status.state == Event_State_Status.approved: From e940d766f36f946645cb9cbf4e10255861d58282 Mon Sep 17 00:00:00 2001 From: Bhav Beri Date: Sat, 23 Mar 2024 13:56:42 +0530 Subject: [PATCH 9/9] Fix the state being set and approver names being overwritten --- mutations.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mutations.py b/mutations.py index f2bb824..61dd93e 100644 --- a/mutations.py +++ b/mutations.py @@ -263,6 +263,9 @@ 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, } elif event_instance.status.state == Event_State_Status.pending_cc: @@ -273,6 +276,9 @@ def progressEvent( # or sum([b.amount for b in event_instance.budget]) == 0, "room": event_instance.status.room, # or len(event_instance.location) == 0, + "cc_approver": user["uid"], + "slc_approver": event_instance.status.slc_approver, + "slo_approver": event_instance.status.slo_approver, } if cc_progress_budget is not None: updation["budget"] = cc_progress_budget @@ -299,6 +305,8 @@ def progressEvent( "room": event_instance.status.room, # | len(event_instance.location) == 0, "slc_approver": user["uid"], + "slo_approver": event_instance.status.slo_approver, + "cc_approver": event_instance.status.cc_approver, } if not updation["room"]: @@ -316,6 +324,8 @@ def progressEvent( "room": True, "state": Event_State_Status.approved.value, "slo_approver": user["uid"], + "slc_approver": event_instance.status.slc_approver, + "cc_approver": event_instance.status.cc_approver, } elif event_instance.status.state == Event_State_Status.approved: @@ -328,6 +338,9 @@ def progressEvent( "budget": event_instance.status.budget, "room": event_instance.status.room, "state": Event_State_Status.approved.value, + "cc_approver": event_instance.status.cc_approver, + "slc_approver": event_instance.status.slc_approver, + "slo_approver": event_instance.status.slo_approver, } upd_ref = eventsdb.update_one({"_id": eventid}, {"$set": {"status": updation}})