[Customer Portal][BE] Add updates endpoints - #98
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughIntroduces a complete updates module integration into the customer portal backend, including HTTP client configuration with OAuth2 authentication and retry logic, comprehensive data types for updates-related information, three service functions for updates operations, and three new REST endpoints for fetching recommended update levels, searching updates, and retrieving product update levels. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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: 5
🤖 Fix all issues with AI agents
In `@apps/customer-portal/backend/modules/updates/client.bal`:
- Around line 22-40: The shared HTTP client updatesClient is configured to retry
on http:STATUS_INTERNAL_SERVER_ERROR which is risky for non-idempotent
operations like addUpdate (POST /updates); modify the retryConfig on
updatesClient by removing http:STATUS_INTERNAL_SERVER_ERROR from statusCodes (or
create a separate client/config for the write path used by addUpdate with 500
excluded) and add a backOffFactor (e.g., 2.0) to retryConfig to implement
exponential backoff instead of a constant 2.0s interval.
In `@apps/customer-portal/backend/modules/updates/types.bal`:
- Around line 30-75: The UpdateDescription type's updateLevel field lacks the
same validation as UpdatesPayload.updateLevel, allowing invalid values through
updateDescriptions; locate the UpdateDescription definition and add the same
integer constraint annotation (`@constraint`:Int {minValue: 1}) to the updateLevel
field so each nested UpdateDescription enforces updateLevel >= 1, matching the
invariant enforced by UpdatesPayload.updateLevel.
In `@apps/customer-portal/backend/modules/updates/updates.bal`:
- Around line 61-71: The getProductUpdateLevels function uses two different
request paths depending on updateLevelState:
updatesClient->/product-update-levels.get(...) when updateLevelState is present
and updatesClient->/updates/product-update-levels.get(...) when nil; make them
consistent by using the correct base path (e.g.,
/updates/product-update-levels.get) in both branches, keeping the same
generateHeaders(idToken) call and the updateLevelState parameter
(updateLevelState = updateLevelStateToUse) in the branch that supplies it so
both calls target the same endpoint.
In `@apps/customer-portal/backend/service.bal`:
- Around line 974-977: Fix the typo in the doc comment for the "Get product
update levels" block: change the word "Lost" to "List" in the return description
(the line that currently reads "# + return - Lost of product update levels or an
error"); update the comment near "updateLevelState" so the return line reads "#
+ return - List of product update levels or an error" to accurately describe the
return value.
- Around line 885-913: The POST updates resource (resource function post
updates) currently converts all errors from updates:addUpdate into a generic
500; change it to inspect the upstream error for STATUS_UNAUTHORIZED and
STATUS_FORBIDDEN (same pattern used by projects/cases/comments/attachments) and
return http:Unauthorized and http:Forbidden respectively, else log and return
http:InternalServerError; also update the function return type union to include
http:Unauthorized|http:Forbidden so callers get proper 401/403 responses.
e454808 to
3cf529b
Compare
c2ceb08 to
9b3b387
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/customer-portal/backend/modules/updates/updates.bal`:
- Around line 30-32: In listUpdates, the call to
updatesClient->/updates/list-updates.post passes headers positionally; change it
to pass headers as a named argument (use headers = generateHeaders(idToken))
while keeping readOnly = true so
updateClient->/updates/list-updates.post(payload, headers =
generateHeaders(idToken), readOnly = true) is used; locate this in the public
isolated function listUpdates and update the call that currently references
generateHeaders(idToken).
🧹 Nitpick comments (1)
apps/customer-portal/backend/modules/updates/types.bal (1)
82-93: Document the security model for forwarding upstreamjwtTokento the portal client.
BasicFileInfoexposes ajwtTokenfield that originates from the upstream updates service and is forwarded directly in the HTTP response to the portal frontend. This design appears intentional—the tokens enable client-side downloads of update files via the provideddownloadUrl. However, the security posture depends entirely on the upstream service's token generation and scope. Consider adding documentation clarifying:
- The intended scope and lifetime of these tokens
- Whether they grant access only to update files or have broader permissions
- Any security assumptions about the downstream update service
This ensures future maintainers understand the security model behind this forwarding pattern.
dd62bb3
into
wso2-open-operations:customer-portal-milestone-1
Description
This PR adds backend endpoints to support the Updates feature in the Customer Portal, aligned with the existing Support Portal APIs.
The implementation follows the same request/response patterns, validations, and filtering behavior used in the Support Portal to ensure consistency.
All payloads are validated using constraints matching the existing updates invoker endpoints.
Endpoints Added
POST /updatesGET /updates/recommended-update-levelsPOST /updates/searchGET /updates/product-update-levelsChanges Introduced
Scope
Related Issues
Notes
Summary by CodeRabbit