Skip to content

add rate limiting, duplicate detection, and email notifications for events - #24

Open
huncijr wants to merge 7 commits into
hackclub:mainfrom
huncijr:fix-bugs-and-add-features
Open

add rate limiting, duplicate detection, and email notifications for events#24
huncijr wants to merge 7 commits into
hackclub:mainfrom
huncijr:fix-bugs-and-add-features

Conversation

@huncijr

@huncijr huncijr commented Jun 18, 2026

Copy link
Copy Markdown

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.

Comment thread isabelle/tables.py Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two fields dropped?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"titla" seems to be a typo. Right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment thread main.py Outdated
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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the listening port changed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I already had something running there and I forgot to change it back. It was my fault

@0xDracula

Copy link
Copy Markdown
Member

#20 is merged

@huncijr

huncijr commented Jun 26, 2026

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants