Add is_admin() helper to utils/permissions.py #55

Closed
opened 2026-03-01 22:41:13 +00:00 by cal · 1 comment
Owner

Multiple places in the codebase manually check interaction.user.guild_permissions.administrator with slightly inconsistent patterns:

  • InjuryGroup._verify_team_ownership includes isinstance(interaction.user, discord.Member) guard (correct)
  • can_edit_player_image in commands/profile/images.py skips the isinstance check (would raise AttributeError in DM context)
  • admin_only() decorator in utils/permissions.py includes the guard

A simple is_admin(interaction: discord.Interaction) -> bool helper in utils/permissions.py would centralize this and prevent inconsistencies:

def is_admin(interaction: discord.Interaction) -> bool:
    return (
        isinstance(interaction.user, discord.Member)
        and interaction.user.guild_permissions.administrator
    )
Multiple places in the codebase manually check `interaction.user.guild_permissions.administrator` with slightly inconsistent patterns: - `InjuryGroup._verify_team_ownership` includes `isinstance(interaction.user, discord.Member)` guard (correct) - `can_edit_player_image` in `commands/profile/images.py` skips the `isinstance` check (would raise `AttributeError` in DM context) - `admin_only()` decorator in `utils/permissions.py` includes the guard A simple `is_admin(interaction: discord.Interaction) -> bool` helper in `utils/permissions.py` would centralize this and prevent inconsistencies: ```python def is_admin(interaction: discord.Interaction) -> bool: return ( isinstance(interaction.user, discord.Member) and interaction.user.guild_permissions.administrator ) ```
cal added the
ai-working
status/in-progress
labels 2026-03-05 04:31:44 +00:00
cal removed the
status/in-progress
label 2026-03-05 04:33:49 +00:00
Author
Owner

PR #64 opened: #64

Added is_admin(interaction) helper to utils/permissions.py with the isinstance(interaction.user, discord.Member) guard, then updated can_edit_player_image() in commands/profile/images.py to use it (fixing the missing DM-safety guard). Updated the admin test mock to use spec=discord.Member. All 930 tests pass.

PR #64 opened: https://git.manticorum.com/cal/major-domo-v2/pulls/64 Added `is_admin(interaction)` helper to `utils/permissions.py` with the `isinstance(interaction.user, discord.Member)` guard, then updated `can_edit_player_image()` in `commands/profile/images.py` to use it (fixing the missing DM-safety guard). Updated the admin test mock to use `spec=discord.Member`. All 930 tests pass.
cal added
status/pr-open
ai-pr-opened
and removed
ai-working
labels 2026-03-05 04:34:00 +00:00
cal closed this issue 2026-03-10 18:26:36 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-v2#55
No description provided.