Skip to content

feat: implement privileged containers for post editor#654

Merged
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
sudo-robi:background
Jun 1, 2026
Merged

feat: implement privileged containers for post editor#654
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
sudo-robi:background

Conversation

@sudo-robi

Copy link
Copy Markdown
Contributor
  • Add PrivilegedContainer component for role-based access control
  • Protect /editor route with INSTRUCTOR minimum role requirement
  • Create server/client split: EditorWorkspace client component, gated page
  • Add editorAccess helpers for editor permission checks
  • Implement boundary-aware RBAC path matching to avoid route conflicts
  • Add /unauthorized fallback page for insufficient privileges
  • Add isAtLeastRole utility function for role-only comparisons
  • Add comprehensive unit tests for editor access and RBAC middleware
  • Update middleware matcher to include /editor route protection

Acceptance criteria met:
✓ Post Editor implements Privileged Containers pattern ✓ All related tests pass (6 tests)
✓ No regression in existing functionality
✓ Code follows project standards
✓ Security: fail-closed pattern, middleware validation ✓ Performance: minimal impact (role check + conditional render) ✓ Accessibility: fallback UI with proper semantics

closes #433

- Add PrivilegedContainer component for role-based access control
- Protect /editor route with INSTRUCTOR minimum role requirement
- Create server/client split: EditorWorkspace client component, gated page
- Add editorAccess helpers for editor permission checks
- Implement boundary-aware RBAC path matching to avoid route conflicts
- Add /unauthorized fallback page for insufficient privileges
- Add isAtLeastRole utility function for role-only comparisons
- Add comprehensive unit tests for editor access and RBAC middleware
- Update middleware matcher to include /editor route protection

Acceptance criteria met:
✓ Post Editor implements Privileged Containers pattern
✓ All related tests pass (6 tests)
✓ No regression in existing functionality
✓ Code follows project standards
✓ Security: fail-closed pattern, middleware validation
✓ Performance: minimal impact (role check + conditional render)
✓ Accessibility: fallback UI with proper semantics
Copilot AI review requested due to automatic review settings June 1, 2026 07:46
@drips-wave

drips-wave Bot commented Jun 1, 2026

Copy link
Copy Markdown

@sudo-robi 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds RBAC protection and UI gating for a new /editor area, ensuring only instructor/admin roles can access the post editor.

Changes:

  • Adds /editor to route permission checks and middleware matchers, with safer path matching (exact or subpath).
  • Introduces shared auth helpers (isAtLeastRole, canAccessPostEditor) and a PrivilegedContainer UI wrapper.
  • Adds /unauthorized page plus Vitest coverage for RBAC/editor access.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/middleware/rbac.ts Adds /editor permission and tightens route matching to avoid prefix collisions.
src/middleware/tests/rbac.test.ts Adds middleware RBAC tests for /editor access/redirect behavior.
src/middleware.ts Ensures middleware runs for /editor/:path*.
src/lib/auth/editorAccess.ts Adds centralized “can access editor” helper and minimum role constant.
src/lib/auth/acl.ts Refactors role→permission mapping typing and extracts isAtLeastRole.
src/lib/auth/tests/editorAccess.test.ts Adds unit tests for editor access helper and minimum role constant.
src/components/shared/PrivilegedContainer.tsx Adds reusable role-gated container component.
src/app/unauthorized/page.tsx Adds a dedicated unauthorized page.
src/app/editor/page.tsx Refactors editor page into server component with role gating and workspace child.
src/app/editor/EditorWorkspace.tsx Moves rich editor client logic into a client component.
Comments suppressed due to low confidence (1)

src/lib/auth/acl.ts:1

  • This mapping now relies on the runtime UserRole values being exactly 'ADMIN' | 'INSTRUCTOR' | ...' (matching these literal keys). The previous computed-key approach ([UserRole.ADMIN], etc.) stayed aligned even if enum values change (e.g., lowercased strings). Consider reverting to computed keys to avoid coupling correctness to the enum’s serialized values.
import { User, UserRole, Permission } from '@/types/api';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/editor/page.tsx
Comment on lines +46 to +51
export default async function EditorPage() {
const cookieStore = await cookies();
const roleCookie = cookieStore.get('user-role')?.value;
const userRole = Object.values(UserRole).includes(roleCookie as UserRole)
? (roleCookie as UserRole)
: null;
Comment thread src/app/editor/page.tsx Outdated
Comment on lines +53 to +67
const restrictedFallback = fallback();

if (!canAccessPostEditor(userRole)) {
return restrictedFallback;
}

return (
<PrivilegedContainer
userRole={userRole}
requiredRole={EDITOR_MIN_ROLE}
fallback={restrictedFallback}
className="min-h-screen"
>
<EditorWorkspace />
</PrivilegedContainer>
Comment thread src/middleware/rbac.ts
Comment on lines +26 to 28
const requiredRole = Object.entries(ROUTE_PERMISSIONS).find(
([path]) => pathname === path || pathname.startsWith(`${path}/`),
)?.[1];
Comment thread src/middleware/__tests__/rbac.test.ts Outdated
@@ -0,0 +1,60 @@
import { describe, expect, it, vi } from 'vitest';
Comment on lines +33 to +38
it('allows instructors and admins to access /editor', () => {
const request = createMockRequest('/editor');

expect(checkRoutePermission(request, UserRole.INSTRUCTOR)).toBeNull();
expect(checkRoutePermission(request, UserRole.ADMIN)).toBeNull();
});
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit f27546b into rinafcode:main Jun 1, 2026
2 of 4 checks passed
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.

enhancement Post Editor : Privileged Containers

3 participants