add rate limiting, duplicate detection, and email notifications for events - #24
add rate limiting, duplicate detection, and email notifications for events#24huncijr wants to merge 7 commits into
Conversation
| created_at = Timestamptz(auto_update=datetime.now,default=datetime.now) | ||
| updated_at = Timestamptz(auto_update=datetime.now,default=datetime.now) No newline at end of file | ||
| #created_at = Timestamptz(auto_update=datetime.now,default=datetime.now) | ||
| #updated_at = Timestamptz(auto_update=datetime.now,default=datetime.now) No newline at end of file |
There was a problem hiding this comment.
Why are these two fields dropped?
There was a problem hiding this comment.
I added these fields, but since they are not yet in the database and their necessity is still uncertain, I have commented them out. This way, they remain available for future use if required.
| user=body["user"]["id"], | ||
| channel=body["user"]["id"], | ||
| text=f'An error occurred whilst creating the event "{title[0]}".', | ||
| text=(f'Could not create "{title[0]}\n' f'An event with the same titla and start time may already exist\n' f'Please check exiting events or edit them instead') |
There was a problem hiding this comment.
"titla" seems to be a typo. Right?
| sentry_sdk.init(dsn=env.sentry_dsn, traces_sample_rate=1.0, enable_logs=True) | ||
| sentry_sdk.profiler.start_profiler() | ||
| uvicorn.run("app:api", port=3000,host="0.0.0.0") | ||
| uvicorn.run("app:api", port=3001,host="0.0.0.0") |
There was a problem hiding this comment.
Why was the listening port changed?
There was a problem hiding this comment.
Because I already had something running there and I forgot to change it back. It was my fault
|
#20 is merged |
|
There is some useful code that isn't in your version, and I've already connected it to the UI as well. I also made some changes, so if needed, I'll clean up any duplicate parts later. |
1.Rate Limiting
Added a custom RateLimitMiddleware that limits requests to 100 per 60-second window per IP. Exceeding clients receive a 429 response with {"error": "Rate limit exceeded. Try again later."}. Protects the /events/ REST API from abuse.
2. Event Duplicate Detection
Before creating a new event, the create_event function now checks for an existing event with the same title and start time. If a duplicate is found, the creation is blocked and a Slack message notifies the user: "Duplicate event blocked: <title> at <start_time>".
3. Email Notification on Approval/Rejection
Fixed the dead pass statement blocking email delivery in send_reminder, then wired email notifications into the approve and reject flows. Event hosts now receive an email when their event is approved or rejected, using the existing mailer infrastructure.