Skip to content

fix: guard Discord role apply on unlinked contacts#199

Open
michaelmwu wants to merge 1 commit intomainfrom
michaelmwu/fix-discord-link-roles
Open

fix: guard Discord role apply on unlinked contacts#199
michaelmwu wants to merge 1 commit intomainfrom
michaelmwu/fix-discord-link-roles

Conversation

@michaelmwu
Copy link
Member

@michaelmwu michaelmwu commented Mar 9, 2026

Description

Prevented resume-driven Discord role application when a contact is not linked to a Discord user.
The Suggested Discord Roles embed now clearly explains that role application is blocked when linking is missing.
The Apply Discord Roles button is now disabled unless a linked Discord user is available.
The apply callback also hard-fails with an explicit user-facing message if triggered while unlinked.
Linkability is now passed through the resume extraction flow so UI and runtime behavior stay consistent.

Related Issue

N/A

How Has This Been Tested?

Ran project pre-commit hooks and verified the diff against origin/main.

Copilot AI review requested due to automatic review settings March 9, 2026 20:11
@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

Warning

Rate limit exceeded

@michaelmwu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa688369-c63a-41f5-aa01-507d698b31d5

📥 Commits

Reviewing files that changed from the base of the PR and between 24679e8 and 28f8cf8.

📒 Files selected for processing (1)
  • apps/discord_bot/src/five08/discord_bot/cogs/crm.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch michaelmwu/fix-discord-link-roles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR guards Discord role application against contacts that are not linked to a Discord user. It prevents the "Apply Discord Roles" flow from being triggered when no Discord link exists, surfacing the missing-link status to the user both in the embed and via a disabled button.

Changes:

  • ResumeApplyDiscordRolesButton now accepts a disabled parameter and a new server-side guard in its callback rejects the action when can_apply_discord_roles is False.
  • ResumeUpdateConfirmationView receives and stores a new can_apply_discord_roles: bool field, used to initialize the apply button's disabled state.
  • _run_resume_extract_and_preview computes can_apply_discord_roles based on whether a Discord user ID or linked member is available, and passes it to both the embed builder and the view.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1272 to 1278
def __init__(self, *, disabled: bool = False) -> None:
super().__init__(
label="Apply Discord Roles",
style=discord.ButtonStyle.success,
custom_id="resume_apply_discord_roles",
disabled=disabled,
)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

In ResumeEditDiscordRolesModal.on_submit (line 1026, outside the diff), the apply button's disabled state is recomputed as not bool(normalized), which ignores can_apply_discord_roles. If a user with an unlinked contact opens and saves the Edit Discord Roles modal with at least one role, the button will be visually re-enabled even though it was intentionally disabled due to no Discord link. The disabled computation there should also check confirmation_view.can_apply_discord_roles, e.g. not bool(normalized) or not self.confirmation_view.can_apply_discord_roles. Although the server-side guard at line 1288 still protects against the action being carried out, the UI state becomes inconsistent with the intent of this PR.

Copilot uses AI. Check for mistakes.
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