Fix: Guard Profiles page failing to load (403 errors) — FE 001 - #445
Fix: Guard Profiles page failing to load (403 errors) — FE 001#445josephmoorman wants to merge 5 commits into
Conversation
… into josephmoorman/fix/employerpanel-guard-profiles-issue
LoopyB
left a comment
There was a problem hiding this comment.
PR #445 - FE 001: One backend authorisation correction is required before merge. The new empty-permissions fallback broadens access and causes users with an explicitly empty permission set to receive default permissions. Please remove that fallback so empty permissions remain deny-by-default, while retaining the employer seed and route fixes.
Please resolve merge conflicts.
No other changes requested.
|
Completed requested change and resolved merge conflict. |
josephmoorman
left a comment
There was a problem hiding this comment.
Completed requested change and resolved merge conflict.
LoopyB
left a comment
There was a problem hiding this comment.
Thanks for the work on this. I’ve reviewed the PR against current main and there are a couple of things I think need resolving before merge.
The new user:read requirement appears to change the existing /users/guards contract and could cause existing employer roles to receive 403s unless the role seed is manually rerun. Can you please confirm whether this permission change is actually required for FE 001? If not, I think it should be removed.
Also, FE 001 includes fixing Guard Profile data mapping/rendering, but the current PR doesn’t appear to change the frontend mapping. The page is still expecting fields that don’t match the current Guard/User schema.
Could you please revisit the API-to-UI mapping and add focused testing/evidence for the intended end-to-end behaviour? Once those are addressed I’m happy to review again.
Root cause
Employers got 403s ("Insufficient role" → "Insufficient permissions") loading Guard Profiles. Root cause was a data issue, not a code bug: the seeded
employerRole doc in MongoDB was missinguser:read. The RBAC logic was working correctly just with incomplete data.The fix
"user:read"to theemployerrole insrc/scripts/seedRoles.js.Also fixed (not root cause)
user.routes.js:/guardsroute referencedROLES.EMPLOYEE, which doesn't exist (onlyEMPLOYERdoes) dead code, removed.rbac.js:getEffectivePermissions()let an empty DB permissions array silently override in-code defaults. Added a guard so defaults are used unless the DB array is non-empty.rbac.js:authorizeRoles()now normalizes case/whitespace on role checks (defensive only — ruled out as the cause here).Action required
docker exec -it secureshift-backend node -r dotenv/config ./src/scripts/seedRoles.jsTesting
Reproduced by removing
user:readfrom the localemployerdoc → confirmed 403. Re-ran seed script → confirmed Guard Profiles loads end-to-end for an Employer account.