refactor: address /code-review on R11 feedback symmetry
- admin._decide: add an idempotency guard (409 unless status was 'pending') so a repeat/stale approve OR deny can't re-run its side effects — now that deny emails, this stops duplicate denial mails and a rejection mail to an already-approved user. - SavedViewsWidget: extract runViewMutation(fn, failMsg) (returns success) — dedups the five try/catch+refresh blocks AND lets create/rename close their input only on success, so a failed create keeps the user's typed name. - worker._notify_download_done: take user_id/title captured BEFORE the caller's commit (no post-commit refresh SELECT); add a so the inbox labels an edit job 'Edit ready' instead of 'Download ready' (new inbox.editDone i18n, HU+EN). Gate green (ruff/tsc/eslint-0/prettier/knip/vitest 79/pytest 193); smoke-tested the saved-views + notifications surfaces render clean on a fresh dev server.
This commit is contained in:
@@ -74,6 +74,12 @@ def _decide(db: Session, invite_id: int, admin: User, approved: bool) -> Invite:
|
||||
inv = db.get(Invite, invite_id)
|
||||
if inv is None:
|
||||
raise HTTPException(status_code=404, detail="No such invite")
|
||||
# Idempotency guard: only a still-pending invite can be decided. Without this a repeat/stale
|
||||
# approve or deny re-runs its side effects — re-activating a user, or (now that deny emails)
|
||||
# sending a duplicate decision mail, even flipping an already-approved invite to "denied" and
|
||||
# mailing a rejection to an already-active account.
|
||||
if inv.status != "pending":
|
||||
raise HTTPException(status_code=409, detail="Invite already decided")
|
||||
inv.status = "approved" if approved else "denied"
|
||||
inv.decided_at = datetime.now(timezone.utc)
|
||||
inv.decided_by = admin.email
|
||||
|
||||
Reference in New Issue
Block a user