feat: implement privileged containers for post editor#654
Merged
Conversation
- 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
|
@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! 🚀 |
There was a problem hiding this comment.
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
/editorto route permission checks and middleware matchers, with safer path matching (exact or subpath). - Introduces shared auth helpers (
isAtLeastRole,canAccessPostEditor) and aPrivilegedContainerUI wrapper. - Adds
/unauthorizedpage 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
UserRolevalues 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 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 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 on lines
+26
to
28
| const requiredRole = Object.entries(ROUTE_PERMISSIONS).find( | ||
| ([path]) => pathname === path || pathname.startsWith(`${path}/`), | ||
| )?.[1]; |
| @@ -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(); | ||
| }); |
Contributor
|
Thank you for contributing to the project. |
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.
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