Skip to content

Add RBAC, auth, and enriched admin resource views#1

Open
otontraore wants to merge 5 commits into
marmelab:mainfrom
otontraore:feat/rbac-authors-post-labels
Open

Add RBAC, auth, and enriched admin resource views#1
otontraore wants to merge 5 commits into
marmelab:mainfrom
otontraore:feat/rbac-authors-post-labels

Conversation

@otontraore

Copy link
Copy Markdown

Summary

  • add users, roles, permissions, login/logout and session-backed RBAC to the API
  • add permission-aware COBOL routing, navigation filtering, login page and CRUD guards
  • model authors as read-only users with an author role, enrich post list/show responses with author and tag names, and add timestamps where useful
  • polish admin navigation, footer links, and list labels for users/posts

Verification

  • docker compose build cobol
  • docker compose up -d --build
  • smoke-tested admin login with admin/admin
  • smoke-tested roles page access after login
  • smoke-tested post list output with author display names and tag names

- Added login and logout functionality with session management.
- Created a new page for user login with error handling.
- Introduced roles and permissions system with CRUD operations.
- Updated router to handle new authentication routes.
- Enhanced existing pages to check user permissions for actions.
- Added tests for new routes and query parameters handling.
- Updated OpenAPI specification to include new endpoints and schemas.
- Created fixtures for roles, permissions, and users for testing.
- Implemented resource ranking and comparison functions for sorting resources in a case-insensitive manner.
- Updated JSON resource sorting to utilize the new comparison logic.
- Added navigation label setting for better user experience in page layout.
- Introduced a new role for authors with specific permissions.
- Modified user fixture to include authors and adjusted author IDs.
- Updated OpenAPI documentation to reflect changes in user and author management.
- Removed unused author fixture file.
- Enhanced CSS styles for navigation and footer elements.
Copilot AI review requested due to automatic review settings May 12, 2026 11:40

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

This PR introduces session-backed authentication and RBAC concepts across the Express API and the COBOL admin UI, and enriches several admin-facing resource views (authors/posts/users) to include derived display data and timestamps.

Changes:

  • Added RBAC domain resources (users/roles/permissions) and auth endpoints (login/logout/me) to the API and OpenAPI spec.
  • Updated the COBOL admin to support login/logout, permission-aware navigation, and CRUD UI guards.
  • Reworked “authors” to be read-only users with an author role; enriched post responses with author display names and tag names; added updatedAt where applicable.

Reviewed changes

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

Show a summary per file
File Description
server/openapi.json Adds auth/RBAC endpoints and schemas; updates Author/Post/User shapes and timestamps.
server/index.js Adds in-memory sessions, auth endpoints, user/post “public” views, and new CRUD routes for RBAC resources.
server/fixtures/users.js Seeds staff + 100 authors as users with timestamps.
server/fixtures/roles.js Seeds roles and permission assignments (admin/editor/reader/author).
server/fixtures/posts.js Updates seeded posts to reference author users and adds updatedAt.
server/fixtures/permissions.js Seeds permission catalog used by roles/RBAC UI.
server/fixtures/comments.js Adds updatedAt to seeded comments.
server/fixtures/authors.js Removes legacy authors fixture (authors now come from users).
cobol/tests/test-router.cbl Adds router tests for query params and login/logout routes.
cobol/tests/test-pages.cbl Updates layout tests to pass auth context into PAGE-LAYOUT.
cobol/templates/layout.html Adds footer links to the layout template.
cobol/static/style.css Adds footer styling and .nav-user; adjusts nav styling.
cobol/run-tests.sh Compiles/links the new PAGE-LOGIN module during test runs.
cobol/router.cbl Adds /login and /logout routing; hardens query param parsing.
cobol/page-show.cbl Hides the Edit button unless update permission is present.
cobol/page-login.cbl Adds a login page renderer with error state.
cobol/page-list.cbl Hides Create unless permitted; hides users.roleId column; threads auth permissions.
cobol/page-layout.cbl Filters nav links by read permission; shows logged-in user + logout link.
cobol/page-edit.cbl Hides Delete unless permitted; improves array field handling for inputs.
cobol/page-create.cbl Enables array field inputs (with [] and placeholder) instead of skipping them.
cobol/main.cbl Adds auth resolution, login/logout handling, and per-route permission enforcement.
cobol/helpers.c Adds auth helpers (login/me/can/check), form-to-JSON array support, and resource sorting tweaks.
cobol/Dockerfile Builds/links PAGE-LOGIN and normalizes CRLF before running tests.
cobol/copybooks/ws-route.cpy Adds ROUTE-LOGIN and ROUTE-LOGOUT flags.
cobol/copybooks/ws-auth.cpy Adds shared auth working-storage fields (sid/user/role/permissions).

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

Comment thread server/index.js Outdated
}
db[resource].push(item);
res.status(201).json(item);
res.status(201).json(resource === "users" ? publicUser(item) : item);
Comment thread server/index.js Outdated
Comment on lines +137 to +138
if (timestamped) db[resource][idx].updatedAt = now;
res.json(resource === "users" ? publicUser(db[resource][idx]) : db[resource][idx]);
Comment thread server/index.js Outdated
Comment on lines +212 to +214
const sessionId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
sessions.set(sessionId, { userId: user.id, createdAt: new Date().toISOString() });
res.json({ sessionId, ...authPayload(user) });
Comment thread server/index.js Outdated
Comment on lines +195 to +199
app.use("/posts", crud("posts", true));
app.use("/comments", crud("comments", true));
app.use("/permissions", crud("permissions"));
app.use("/roles", crud("roles"));
app.use("/users", crud("users", true));
Comment thread server/index.js Outdated
Comment thread server/openapi.json
Comment thread cobol/main.cbl
Comment thread cobol/main.cbl
Comment thread cobol/page-layout.cbl
Comment thread cobol/page-layout.cbl
@otontraore

Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@otontraore otontraore left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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

Copilot reviewed 25 out of 25 changed files in this pull request and generated 9 comments.

Comment thread server/openapi.json
Comment thread server/openapi.json
Comment thread server/index.js Outdated
Comment thread server/index.js
Comment thread cobol/main.cbl
Comment thread cobol/page-layout.cbl
Comment thread cobol/page-layout.cbl
Comment thread server/openapi.json
Comment thread server/index.js Outdated
@otontraore

Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

@otontraore

Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

@otontraore

Copy link
Copy Markdown
Author

I addressed the main review points:

  • hardened session generation using crypto.randomUUID()
  • moved auth session handling to an HTTP-only cookie
  • cleared the session cookie on logout
  • aligned /posts CRUD responses with the enriched post presenter
  • exported the Express app for future tests
  • added a GitHub Actions CI workflow for server syntax and OpenAPI validation

Ready for another review.

@otontraore otontraore left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ThieryMichel benwinding Could you please review this PR again when you have a moment?

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.

2 participants