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( diff --git a/mutations.py b/mutations.py index f8e5e6f..61dd93e 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: @@ -604,10 +607,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, ]