-
Notifications
You must be signed in to change notification settings - Fork 2
feat(permissions): support multiple admin and moderator roles #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
89cf90c
feat: migrate adminRoleId/moderatorRoleId to arrays with backward compat
6bf104a
feat(permissions): support multiple admin and moderator roles
5f0a8cd
📝 Add docstrings to `feat/multi-role-permissions`
coderabbitai[bot] 10cccf4
fix: sort imports in dbMaintenance.js (biome CI)
f341b2e
fix(permissions): correct backward compat for merged legacy config shape
f41423c
fix(api): add permissions section to CONFIG_SCHEMA for role array val…
github-actions[bot] 03d0ae1
fix(permissions): add permissions schema to configValidation; harden …
473ee55
test(permissions): add dedicated mergeRoleIds describe block with 13 …
4ae0333
fix(permissions): address PR #261 review comments
b2b604a
Merge branch 'main' into feat/multi-role-permissions
BillChirico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # TASK: Multi-role permissions (admin + moderator) | ||
|
|
||
| Branch: `feat/multi-role-permissions` | ||
| Repo: VolvoxLLC/volvox-bot | ||
| Work in: `/home/bill/worktrees/volvox-bot-multi-roles` | ||
|
|
||
| ## Goal | ||
| Allow configuring multiple Discord roles as admin and multiple roles as moderator, instead of a single role each. | ||
|
|
||
| ## Schema change | ||
| - `config.permissions.adminRoleId: string | null` → `config.permissions.adminRoleIds: string[]` | ||
| - `config.permissions.moderatorRoleId: string | null` → `config.permissions.moderatorRoleIds: string[]` | ||
|
|
||
| ## Files to change | ||
|
|
||
| ### 1. `src/config.json` (or wherever defaults live) | ||
| - Find the permissions defaults | ||
| - Change `adminRoleId: null` → `adminRoleIds: []` | ||
| - Change `moderatorRoleId: null` → `moderatorRoleIds: []` | ||
|
|
||
| ### 2. `web/src/types/config.ts` | ||
| - Line ~191: Change `adminRoleId: string | null` → `adminRoleIds: string[]` | ||
| - Line ~192: Change `moderatorRoleId: string | null` → `moderatorRoleIds: string[]` | ||
|
|
||
| ### 3. `src/utils/permissions.js` | ||
| - Line 66: `config.permissions?.adminRoleId` check → check if member has ANY role in `config.permissions?.adminRoleIds ?? []` | ||
| ```js | ||
| const adminRoleIds = config.permissions?.adminRoleIds ?? []; | ||
| if (adminRoleIds.length > 0) { | ||
| return adminRoleIds.some(id => member.roles.cache.has(id)); | ||
| } | ||
| ``` | ||
| - Line 162-169: Same pattern for both admin and moderator checks | ||
| - Keep backward compat: if `adminRoleId` (singular) exists in config, treat it as `[adminRoleId]` so old configs still work | ||
|
|
||
| ### 4. `src/utils/modExempt.js` | ||
| - Update to check array: `(config.permissions?.adminRoleIds ?? []).some(id => member.roles.cache.has(id))` | ||
| - Same for moderatorRoleIds | ||
| - Keep backward compat for old singular field | ||
|
|
||
| ### 5. `src/modules/moderation.js` | ||
| - Lines 589-594: Spread the arrays for protect roles: | ||
| ```js | ||
| ...(protectRoles.includeAdmins ? (config.permissions?.adminRoleIds ?? []) : []), | ||
| ...(protectRoles.includeModerators ? (config.permissions?.moderatorRoleIds ?? []) : []), | ||
| ``` | ||
|
|
||
| ### 6. `web/src/components/dashboard/config-editor.tsx` | ||
| - The RoleSelector for admin is currently single-select (wraps value in array, takes `selected[0]`). Change to true multi-select: | ||
| - `selected={draftConfig.permissions?.adminRoleIds ?? []}` (no wrapping) | ||
| - `onChange={(selected) => updatePermissionsField('adminRoleIds', selected)}` | ||
| - Remove `maxSelections={1}` if present | ||
| - Same for moderator: | ||
| - `selected={draftConfig.permissions?.moderatorRoleIds ?? []}` | ||
| - `onChange={(selected) => updatePermissionsField('moderatorRoleIds', selected)}` | ||
|
|
||
| ### 7. Check for any other references to old singular fields | ||
| ```bash | ||
| grep -rn "adminRoleId\b\|moderatorRoleId\b" src/ web/src/ --include="*.js" --include="*.ts" --include="*.tsx" | ||
| ``` | ||
| Fix any remaining references. | ||
|
|
||
| ### 8. Update tests | ||
| - `tests/utils/permissions.test.js` — update mocks and assertions to use arrays | ||
| - `tests/utils/modExempt.test.js` — same | ||
|
|
||
| ## Backward compat pattern | ||
| In permissions.js and modExempt.js, support old configs that have the singular field: | ||
| ```js | ||
| const adminRoleIds = config.permissions?.adminRoleIds | ||
| ?? (config.permissions?.adminRoleId ? [config.permissions.adminRoleId] : []); | ||
| ``` | ||
|
|
||
| ## Rules | ||
| - Conventional commits | ||
| - Run `pnpm format && pnpm lint && pnpm test` and `pnpm --prefix web lint && pnpm --prefix web typecheck` | ||
| - Do NOT push |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.