Repository navigation
Implement role-based access control (owner > admin > member) - #119
Merged
Merged
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR119Version: 🤖 Updated on each push. |
Adds role column to users table, migrates existing is_admin data, and sets initial owner/admin assignments for yahya, nemarOwner, nemarAdmin.
Adds UserRole type (owner/admin/member), hasRole() hierarchy check, isValidRole() validator, and role field to AuthUser interface. Keeps is_admin as deprecated computed field for backward compatibility.
Read role column from DB instead of is_admin. Compute is_admin from role for backward compatibility. Add ownerMiddleware for owner-only routes.
Add POST /admin/users/:username/role (owner-only) with safety checks: cannot self-demote, cannot remove last owner, token revocation on demotion. Update user listing to include role, update regenerate-iam to use role instead of is_admin.
Update datasets.ts: replace all is_admin inline checks with hasRole(), update IAM query to read role column, update notification queries. Update auth.ts: return role in login response, update notification query. Update users.ts: return role in /users/me response.
Add role field to API types (LoginResponse, UserInfo, UserListItem). Add changeUserRole() API function and 'nemar admin role' command. Show role badges in user list, role-specific login messages, and role in 'auth status --refresh' output.
Add test-owner user to test setup, add role column to all test users, update test assertions to check role field alongside is_admin for backward compatibility.
- Add parseRole() for validated role parsing instead of unsafe casts - Add isDemotion() helper, export ROLE_HIERARCHY - Fix privilege escalation: only owners can revoke other owners - Wrap token revocation and audit log in try-catch - Remove is_admin from AuthUser, API responses, CLI types, and tests - Fix IAM null-role logic: use validated user.role from middleware - Add requireAuth() to role command - Add migration 0010 to drop is_admin column from users table - Update test scripts to remove is_admin references
neuromechanist
force-pushed
the
feature/user-roles
branch
from
February 12, 2026 01:46
52778ed to
cecd5da
Compare
This branch was previously deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replaces the binary
is_adminflag with a hierarchical role system: owner > admin > member. Closes #81, addresses #35.rolecolumn to users table via migration (0009), then fully dropis_admincolumn (0010)yahya+nemarOwner= owner,nemarAdmin= adminownerMiddlewarefor owner-only operationsPOST /admin/users/:username/roleendpoint (owner-only) with safety checks: cannot self-demote, cannot remove last owner, token revocation on demotionis_adminchecks withhasRole()helperparseRole()for validated role parsing with null-safety and error loggingisDemotion()helper for checking role downgradesnemar admin role <username> <role>CLI commandis_adminfrom all API responses, CLI types, and test assertionsTest plan
bun run build)wrangler d1 migrations apply nemar-db --local(all 11 migrations including 0010)is_admincolumn dropped:PRAGMA table_info(users)shows nois_adminbun test(305 pass, 28 skip, 35 fail - all failures pre-existing)nemar admin usersshows role badgesnemar admin role <user> adminworks as ownernemar admin rolefails as admin (403)