Skip to content

Feat/rbac implementation#686

Open
Tekprecious wants to merge 6 commits into
Smartdevs17:mainfrom
Tekprecious:feat/rbac-implementation
Open

Feat/rbac implementation#686
Tekprecious wants to merge 6 commits into
Smartdevs17:mainfrom
Tekprecious:feat/rbac-implementation

Conversation

@Tekprecious

Copy link
Copy Markdown

Pull Request Checklist

Quality Gates (All must pass before merge)

  • Lint: Code passes ESLint and Prettier checks
  • Type Check: TypeScript compilation succeeds
  • Tests: All tests pass
  • Build: Project builds successfully
  • Rust Format: Smart contract formatting is correct
  • Rust Clippy: Smart contract linting passes
  • Rust Tests: All smart contract tests pass
  • Rust Build: Smart contracts compile successfully

Additional Requirements

  • New code has appropriate TypeScript types
  • No hardcoded secrets or credentials
  • New features have corresponding tests
  • Documentation updated if needed

Reviewers

  • At least 1 approval required for merge
  • All CI checks must be green

This PR will not be mergeable until all quality gates pass.

This pull request implements a comprehensive, fine-grained Role-Based Access Control (RBAC) system to enhance security and auditability within SubTrackr. Previously, all team members had identical permissions, posing a significant security risk. This implementation introduces distinct roles, resource-level permissions, and a complete audit trail.

This change introduces the core backend components for RBAC, including:

  1. Database Schema: A new SQL migration (20260625_rbac_tables.sql) creates four tables:

    • roles: Defines system and custom roles (e.g., Admin, Billing).
    • role_permissions: Maps permissions in resource:action format to roles.
    • user_roles: Assigns roles to users, with a safe fallback to 'viewer' on role deletion.
    • permission_audit_logs: A critical table that records every single permission check (both ALLOW and DENY) for full auditability.
  2. Permission Logic: The PermissionRegistry.js utility provides a robust, static method for checking permissions. It supports exact matches, resource-level wildcards (subscription:*), and a global admin wildcard (all:*).

  3. Express Middleware: The rbacMiddleware.js contains a requirePermission(permission) factory. This middleware integrates the system by:

    • Extracting the user context.
    • Querying the database for the user's permissions.
    • Using PermissionRegistry to authorize or deny the request.
    • Crucially, logging every attempt to the permission_audit_logs table before responding.

This foundational work paves the way for securing all API endpoints and building a user-facing UI for role management.

Closes #607

…h OCC

Implements an optimistic concurrency control (OCC) mechanism using version numbers to prevent silent data loss during concurrent updates.

- Adds a 'version' field to key entities.
- Introduces a backend OptimisticLockService for version checking.
- Returns 409 Conflict on version mismatch.
- Implements a client-side service with automatic retries and exponential backoff.
- Prepares for manual conflict resolution via a Zustand store if retries fail.

Closes Smartdevs17#613
Clears out multiple workspace errors:
- Fixes Prettier layout/syntax issues in crdt.ts and .storybook/main.js.
- Resolves import/export name collisions in the design-system barrel file.
- Corrects broken relative import paths in test files.
- Removes numerous unused variables and imports flagged by the linter.
@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@Tekprecious Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Implement RBAC with fine-grained resource-level permissions

2 participants