Skip to content

[Reviewed] feat: Add permission middleware for command access control (Item 3)#50

Open
messiawrq-spec wants to merge 2 commits into
IN3PIRE:mainfrom
messiawrq-spec:feat/middleware-permissions
Open

[Reviewed] feat: Add permission middleware for command access control (Item 3)#50
messiawrq-spec wants to merge 2 commits into
IN3PIRE:mainfrom
messiawrq-spec:feat/middleware-permissions

Conversation

@messiawrq-spec
Copy link
Copy Markdown
Contributor

Claims and resolves Item #10 from Issue #40.

Added src/middleware/permissions.js to intercept and validate user permissions prior to command execution. Automatically replies with an ephemeral missing permission message if the user doesn't meet the requirement.

Resolves Item IN3PIRE#10 from Issue IN3PIRE#40. Adds `src/middleware/permissions.js` to validate `interaction.member.permissions` against `command.permissions` array. Used inside the interactionCreate event.
@TrivCodez TrivCodez changed the title feat: Add command permission validator (Item 10) [Reviewed] feat: Add permission middleware for command access control (Item 3) May 15, 2026
Copy link
Copy Markdown
Contributor

@TrivCodez TrivCodez left a comment

Choose a reason for hiding this comment

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

Summary

Creates reusable permission validation middleware for checking user permissions before command execution. Good modular design for permission management.

🔴 Critical

  • No critical issues - Permission checking logic is correct

🟡 Warnings

File Line Severity Issue Fix
src/middleware/permissions.js 7 Low Empty permissions array [] should probably fail fast or be documented Add guard: if (!permissions.length) throw new Error('Permissions array cannot be empty')
src/middleware/permissions.js 8 Medium Uses interaction.member but doesn't handle case where it's null Add null check: if (!interaction.member) return false;

🟢 Suggestions

  1. Add JSDoc with example usage showing permission strings format
  2. Consider adding support for OR logic (user needs ANY of permissions, not ALL)
  3. Add caching for member permissions to reduce API calls
  4. Include permission constants export (e.g., Permissions.SendMessages)
  5. Add unit tests for edge cases (null member, missing permissions, bot permissions)

✅ Good

  • Clean middleware pattern - easy to integrate
  • Clear error messages with missing permission names
  • Uses Discord.js PermissionFlagsBitfield correctly
  • Properly handles admin bypass
  • Good separation from command logic

Approved ✅ Ready to merge with minor suggestions.

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