Skip to content

guard: Show commenters why their comment was rejected - #1129

Merged
jelmer merged 1 commit into
isso-comments:masterfrom
pkvach:feat/guard-rejection-feedback
Sep 15, 2026
Merged

jelmer merged 1 commit into
isso-comments:masterfrom
pkvach:feat/guard-rejection-feedback

Conversation

@pkvach

@pkvach pkvach commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • All new and existing tests are passing
  • (If adding features:) I have added tests to cover my changes
  • (If docs changes needed:) I have updated the documentation accordingly.
  • I have added an entry to CHANGES.rst because this is a user-facing change or an important bugfix
  • I have written proper commit message(s)

What changes does this Pull Request introduce?

Guard rejections (rate limit, direct-reply cap, reply-to-self, missing email/author) used to just raise a 403 with an internal-only message; the JS client only console.error'd it, so commenters saw nothing.

  • Guard.validate() now returns (valid, reason, message): reason is a stable machine-readable code (ratelimit, direct-reply, reply-to-self, require-email, require-author), message stays the human-readable log/extension text.
  • /new returns {"reason": ...} as JSON 403 instead of raising Forbidden(message).
  • JS postbox maps reason to a guard-<reason> i18n key and shows it inline above the submit button, falling back to a generic guard-error message for unknown reasons.
image

Why is this necessary?

Part of #446

Guard.validate() returned only True/False and a raw internal message,
which comments.py raised as an 403 Forbidden with that message
as the body. The JS client just console.error'd it, so a rejected
commenter (rate limit, direct-reply cap, reply-to-self, missing
email/author) saw nothing.

Split the internal message into a machine-readable reason code (e.g.
"ratelimit", "reply-to-self") and a human-readable message. The
reason is returned as JSON ({"reason": ...}, 403) instead of raising
Forbidden; the message keeps going to comments.new:guard for logging
and extensions. isso.js maps reason -> "guard-" + reason i18n key and
shows it inline in the postbox, falling back to a generic "guard-
error" text for unknown reasons.

Part of isso-comments#446
@jelmer
jelmer merged commit 413d447 into isso-comments:master Sep 15, 2026
20 checks passed
@pkvach
pkvach deleted the feat/guard-rejection-feedback branch September 15, 2026 19:07
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.

2 participants