Repository navigation
Discord chat: connect a forum account from Discord's Linked Roles menu - #452
Conversation
discord_chat_linked_roles_enabled serves Discord's Linked Roles Verification URL at /discord-chat/link. A member starts from the server menu, signs in here if needed, approves the app on Discord, and comes back connected: the Discord account is linked to their forum account the way the Discord login links it, the role connection is recorded, and the sync runs straight away to give the roles the forum allows. Core's Discord connect can't be reused because its OAuth request has fixed scopes, and Linked Roles needs role_connections.write. This is stricter than core on conflicts: a Discord account linked to another forum account, or a forum account already linked to another Discord account, is refused rather than moved. The OAuth state lives in the server session for ten minutes and is single-use. The linked role grants nothing itself; the docs and setting description say to keep its requirement off the member role, since Discord lets people claim linked roles from its menu and a suspended member could otherwise claim their way back in. Turning the setting on registers the one yes/no requirement with Discord. Off by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b02ce5864
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if name.to_sym == :discord_chat_linked_roles_enabled | ||
| Jobs.enqueue(:discord_chat_register_linked_role) |
There was a problem hiding this comment.
Register linked-role metadata after configuration changes
If discord_chat_linked_roles_enabled is enabled before the bot token or guild ID is configured, this event is skipped by the preceding configured? guard; setting the missing prerequisite later only enqueues member sync because this condition matches exclusively on the linked-role setting. The metadata is therefore never registered, and Linked Roles remains unusable until an administrator toggles the setting off and on again. Trigger registration when any prerequisite becomes valid, not only when this single setting changes.
Useful? React with 👍 / 👎.
| rescue Api::Error => e | ||
| Rails.logger.warn("#{DiscourseDiscordChat::LOG_TAG} link: #{e.message}") | ||
| finish("Discord didn't answer. Try again in a minute.", 502) |
There was a problem hiding this comment.
Handle Discord transport failures in the callback
If Discord is unreachable, DNS fails, or either Net::HTTP timeout expires, Net::HTTP.start raises exceptions such as SocketError, Net::OpenTimeout, or Net::ReadTimeout, none of which inherit from Api::Error. Those expected outage cases therefore escape this rescue and turn the OAuth callback into an internal-server-error response instead of the intended retryable 502 message.
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs
Serves the Linked Roles Verification URL at
/discord-chat/link(default off,discord_chat_linked_roles_enabled).Flow: server menu → Linked Roles → sign in here → approve on Discord → accounts linked (same fields core stores), role connection recorded, sync enqueued.
role_connections.write.Specs: login redirect, authorize redirect, link + role-connection + sync, bad/reused state, both conflicts, signed-out callback links nothing, cancel links nothing, setting off → 404; metadata registration job.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs