fix: prevent duplicate forum topics from rapid double-submit
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
- Backend: reject identical title+content from same author within 60s (mirrors existing protection on forum_reply) - Frontend: disable submit button + 'Wysyłanie…' label on first click Daniel Kochański accidentally created 7 identical 'Local content w praktyce' topics within 5 seconds. Soft-deleted IDs 25-30 on prod, kept 24. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e9e8154eb0
commit
a68910d029
@ -149,6 +149,16 @@ def forum_new_topic():
|
|||||||
|
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
|
# Duplicate submission protection: same author, same title+content, within 60 seconds
|
||||||
|
recent_duplicate = db.query(ForumTopic).filter(
|
||||||
|
ForumTopic.author_id == current_user.id,
|
||||||
|
ForumTopic.title == title,
|
||||||
|
ForumTopic.content == content,
|
||||||
|
ForumTopic.created_at >= datetime.now() - timedelta(seconds=60)
|
||||||
|
).first()
|
||||||
|
if recent_duplicate:
|
||||||
|
return redirect(url_for('.forum_topic', topic_id=recent_duplicate.id))
|
||||||
|
|
||||||
topic = ForumTopic(
|
topic = ForumTopic(
|
||||||
title=title,
|
title=title,
|
||||||
content=content,
|
content=content,
|
||||||
|
|||||||
@ -383,6 +383,14 @@
|
|||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitBtn = this.querySelector('button[type="submit"]');
|
||||||
|
if (submitBtn) {
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
submitBtn.dataset.originalText = submitBtn.textContent;
|
||||||
|
submitBtn.textContent = 'Wysyłanie…';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user