Skip to content

Commit

Permalink
Merge pull request #21 from Clubs-Council-IIITH/inter_communication_s…
Browse files Browse the repository at this point in the history
…ecret-

Inter communication secret
  • Loading branch information
abhiramtilakiiit authored Apr 6, 2024
2 parents 17c7ef1 + 8dbe063 commit df0d1db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mailing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import requests
import os

inter_communication_secret = os.getenv("INTER_COMMUNICATION_SECRET")


# API call to send mail notification
Expand All @@ -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 = {
Expand All @@ -23,7 +26,8 @@ def triggerMail(
"uid": uid,
"toRecipients": toRecipients,
"ccRecipients": ccRecipients,
}
},
"interCommunicationCecret": inter_communication_secret,
}
if cookies:
requests.post(
Expand Down
32 changes: 32 additions & 0 deletions mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -37,6 +38,8 @@
getUser,
)

inter_communication_secret_global = os.getenv("INTER_COMMUNICATION_SECRET")


@strawberry.mutation
def createEvent(details: InputEventDetails, info: Info) -> EventType:
Expand Down Expand Up @@ -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,
]

0 comments on commit df0d1db

Please sign in to comment.