[Customer Portal] Handle forbidden access - #68
Conversation
📝 WalkthroughWalkthroughThis pull request adds runtime checks for HTTP 403 Forbidden responses across four customer portal backend endpoints, expanding their return type signatures to explicitly include Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/customer-portal/backend/service.bal (1)
267-299: Add forbidden error handling to this endpoint for consistency.This endpoint calls
searchCases, which wraps the same entity client call that can return 403 errors (like other similar endpoints). All other endpoints that call entity functions (getProjects,getProjectDetails,getCase, etc.) handlehttp:STATUS_FORBIDDENand returnhttp:Forbidden. This endpoint should do the same: addhttp:Forbiddento the return type union and checkif getStatusCode(casesResponse) == http:STATUS_FORBIDDENbefore processing the response.
🤖 Fix all issues with AI agents
In `@apps/customer-portal/backend/service.bal`:
- Around line 93-101: The warning log currently prints "User:" with a trailing
colon but no identifier, which is misleading; update the log in the
forbidden-check (the block using getStatusCode(userDetails) and log:printWarn)
to either remove the trailing colon and use a complete message like "User does
not have access to the customer portal" or include a safe placeholder until PR
`#42` adds the UUID (e.g., "User:<unknown>" or use userDetails.id if present).
Ensure you only change the string passed to log:printWarn in this forbidden
branch so the message is clear and non-misleading.
- Around line 147-155: The warning log message inside the
getStatusCode(projectsList) == http:STATUS_FORBIDDEN branch is grammatically
wrong and incomplete; update the log:printWarn call to a complete, grammatically
correct sentence and include the user identifier (UUID) once available (replace
the trailing colon-only message). Specifically, change the message to something
like "Access to the requested project is forbidden for user: <userId>" and
populate <userId> from the appropriate variable (or the UUID placeholder
referenced in the TODO) so the log prints the identifier; ensure the
http:Forbidden response body remains unchanged.
🧹 Nitpick comments (1)
apps/customer-portal/backend/service.bal (1)
93-101: Consider extracting forbidden handling into a helper function.The forbidden response pattern is repeated across four endpoints with similar structure. You could extract this into a helper to reduce duplication and centralize the response format:
function createForbiddenResponse(string logMessage, string userMessage) returns http:Forbidden { log:printWarn(logMessage); return <http:Forbidden>{ body: { message: userMessage } }; }This would simplify each check to a single function call and make future updates (like adding the UUID from PR
#42) easier.Also applies to: 147-155, 194-202, 241-249
…tone-1-validation
4c5006a
into
wso2-open-operations:customer-portal-milestone-1
Description
This PR improves access control handling for protected endpoints by ensuring that forbidden access is properly detected and returned with meaningful error messages.
It standardizes how
403 Forbiddenresponses are sent to the frontend when users attempt to access resources without sufficient permissions.Changes
Affected endpoints:
Benefits
500 Internal Server ErrorresponsesExample Scenario
When a user without required permissions attempts to access a protected resource, the API will now return:
Instead of a generic server error.
Related Issues
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.