Skip to content

Feature/authorization#23

Merged
naveensanjula975 merged 3 commits into
devfrom
feature/authorization
May 4, 2026
Merged

Feature/authorization#23
naveensanjula975 merged 3 commits into
devfrom
feature/authorization

Conversation

@kavindalj

Copy link
Copy Markdown
Contributor

No description provided.

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 centralized JWT authentication/authorization middleware and begins enforcing role-based access control (RBAC) across issue- and branch-related endpoints, along with service/controller adjustments to shape returned data by role.

Changes:

  • Added authenticateToken / authorizeRoles middleware and applied auth globally for v1 API routes.
  • Introduced RBAC filtering/authorization logic in issue listing/detail endpoints and restricted certain routes by role.
  • Updated user-role fetching to include only role-specific profiles and attach branch details for branch managers.

Reviewed changes

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

Show a summary per file
File Description
src/middleware/auth.js Adds JWT auth middleware and role authorization helper.
server.js Applies authentication middleware globally before mounting protected routes.
src/routes/auth.js Refactors to use shared authenticateToken middleware for protected auth endpoints.
src/routes/issues.js Adds role gating to issue creation and reformats routes.
src/controllers/issueController.js Adds RBAC filtering for issue listing and authorization checks for issue detail.
src/services/issueService.js Tightens issue creation validation and changes “updated issue” return payloads for some operations.
src/routes/branch.js Restricts all branch routes to maintenance_executive.
src/services/userService.js Changes getUsersByRole to only include the relevant profile and manually attach branch data for branch managers.
Comments suppressed due to low confidence (2)

src/controllers/issueController.js:45

  • The inline comment says the service will auto-assign a branch manager when manager_id is 0/absent, but IssueService.createIssue now always validates manager_id and no longer auto-assigns. Update/remove this comment (and the surrounding logic) to reflect the current behavior.
      // Include manager_id only if it is a valid non-zero integer
      // When it's 0 or absent, issueService will auto-assign a branch manager
      const parsedManagerId = manager_id ? parseInt(manager_id) : 0;
      if (parsedManagerId > 0) {
        issueData.manager_id = parsedManagerId;
      }

src/routes/issues.js:46

  • The status-log endpoints (GET/POST /:id/statuses) are not protected by authorizeRoles(...). If these logs are sensitive, restrict access and ensure the caller is authorized to view the referenced issue (consistent with the RBAC in IssueController.getIssueById).
// GET /api/v1/issues/:id/statuses - Get all status update logs for an issue
router.get('/:id/statuses', statusController.getStatusUpdates);

// POST /api/v1/issues/:id/statuses - Add a status update log entry
router.post('/:id/statuses', statusController.createStatusUpdate);

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

Comment on lines 33 to +37
const issueData = {
branch_id: parseInt(branch_id),
title,
description
manager_id: parseInt(manager_id),
description,
Comment on lines +194 to +195
message:
"Access denied: This issue does not belong to your branch",
Comment thread src/routes/issues.js
Comment on lines 21 to +25
// PUT /api/v1/issues/:id - Update issue
router.put('/:id', issueController.updateIssue);
router.put("/:id", issueController.updateIssue);

// DELETE /api/v1/issues/:id - Delete issue
router.delete('/:id', issueController.deleteIssue);
router.delete("/:id", issueController.deleteIssue);
Comment thread src/routes/issues.js

// PUT /api/v1/issues/:id/status - Update issue status
router.put('/:id/status', issueController.updateStatus);
router.put("/:id/status", issueController.updateStatus);
success: true,
data: updatedIssueResult.data,
message: 'Issue status updated successfully'
data: issue,
Comment on lines +307 to +311
if (branchId) {
const branchResult = await branchService.getBranchById(branchId);
if (branchResult.success) {
userJson.Branch = branchResult.data; // Attaching branch data
}
Comment thread server.js
app.use("/api/v1/auth", authRoutes);

// Protected routes - require authentication
app.use(authenticateToken);
Comment on lines 33 to +37
const issueData = {
branch_id: parseInt(branch_id),
title,
description
manager_id: parseInt(manager_id),
description,
Comment on lines +121 to +125
// Strict Role-Based Access Control Filtering
const { role, roleSpecificId } = req.user;

if (role === "maintenance_executive") {
// Maintenance Executives can view all issues by default.
Comment thread src/routes/issues.js
Comment on lines 27 to 29
// POST /api/v1/issues/:id/assign-technician - Assign technician to issue
router.post('/:id/assign-technician', issueController.assignTechnician);
router.post("/:id/assign-technician", issueController.assignTechnician);

@naveensanjula975 naveensanjula975 merged commit edc5cbc into dev May 4, 2026
5 of 7 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.

3 participants