Repository navigation
Closed
Description
Problem
Currently, NEMAR only has a binary is_admin flag for user permissions. This is insufficient for a proper role-based access control (RBAC) system. We need a hierarchical role system with clear permission boundaries.
Current State
User table:
users (
id INTEGER PRIMARY KEY,
username TEXT,
email TEXT,
is_admin INTEGER DEFAULT 0, -- Binary: 0 or 1
status TEXT DEFAULT 'pending',
...
)Current permission model:
- Regular users:
is_admin = 0 - Admins:
is_admin = 1 - No distinction between different admin levels
- No concept of ownership or maintainership
Proposed Role Hierarchy
Role Levels (from highest to lowest)
-
Owner (highest privilege)
- Can onboard admins
- Can perform all admin actions
- Can manage system-wide settings
- Typically: Project founders, organization leads
-
Admin
- Can verify/approve member registrations
- Can manage datasets (publish, visibility changes)
- Can create concept DOIs
- Cannot onboard other admins (only owners can)
- Typically: Trusted maintainers, senior researchers
-
Maintainer (optional tier)
- Can manage datasets they collaborate on
- Can review and approve PRs for datasets
- Can invite collaborators to datasets
- Cannot approve new user registrations
- Typically: Active contributors, dataset curators
-
Member (base level)
- Can create and upload datasets
- Can request collaborator access
- Can download public datasets
- Requires admin approval after signup
- Typically: Regular users, researchers
Permission Matrix
| Action | Owner | Admin | Maintainer | Member |
|---|---|---|---|---|
| Onboard admins | ✅ | ❌ | ❌ | ❌ |
| Approve user registrations | ✅ | ✅ | ❌ | ❌ |
| Create concept DOIs | ✅ | ✅ | ❌ | ❌ |
| Publish datasets (any) | ✅ | ✅ | ❌ | ❌ |
| Change dataset visibility (any) | ✅ | ✅ | ❌ | ❌ |
| Manage own datasets | ✅ | ✅ | ✅ | ✅ |
| Invite collaborators to own datasets | ✅ | ✅ | ✅ | ✅ |
| Approve PRs on collaborated datasets | ✅ | ✅ | ✅ | ❌ |
| Upload datasets | ✅ | ✅ | ✅ | ✅ |
| Request collaborator access | ✅ | ✅ | ✅ | ✅ |
| Download public datasets | ✅ | ✅ | ✅ | ✅ |
Database Changes
Migration: Add role column
-- Migration: 0007_user_roles
-- Description: Replace binary is_admin with role-based system
-- Add role column
ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'member'
CHECK (role IN ('owner', 'admin', 'maintainer', 'member'));
-- Migrate existing users
UPDATE users SET role = CASE
WHEN is_admin = 1 THEN 'admin'
ELSE 'member'
END;
-- First admin becomes owner (manually set)
-- UPDATE users SET role = 'owner' WHERE username = 'yahya';
-- Index for role-based queries
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);Code Changes Required
1. Auth Middleware Enhancement
export type UserRole = 'owner' | 'admin' | 'maintainer' | 'member';
export function isOwner(user: AuthenticatedUser): boolean {
return user.role === 'owner';
}
export function isAdmin(user: AuthenticatedUser): boolean {
return ['owner', 'admin'].includes(user.role);
}2. New Admin Routes
// Owner-only: Promote users to admin/maintainer
POST /admin/users/:username/promote
// Admin+: Approve member registrations
POST /admin/users/:username/approve3. CLI Commands
# New commands (owner only)
nemar admin users promote <username> <role>
nemar admin users demote <username>
nemar admin users list --role admin
# Updated output
$ nemar whoami
Authenticated
Username: yahya
Role: OwnerMigration Strategy
- Phase 1: Database migration (add role column)
- Phase 2: Backend updates (permission checks)
- Phase 3: CLI updates (new commands)
- Phase 4: Testing & validation
- Phase 5: Documentation
- Phase 6: Remove
is_admincolumn (future)
Security Considerations
- First owner must be set manually during deployment
- Owners cannot demote themselves (prevents lockout)
- All role changes must be audit logged
- Consider token invalidation on role changes
- Prevent demoting the last owner
Acceptance Criteria
- Database migration adds role column
- Existing admins migrated to 'admin' role
- At least one owner account exists
- Owners can promote users to admin/maintainer
- Admins cannot promote users to admin
- CLI shows user roles
- All role changes are audit logged
- Documentation updated
Metadata
Metadata
Assignees
Labels
No labels
Activity