Skip to content

[Customer Portal][BE] Update users/me endpoint to fetch the last password update time - #375

Merged
cloby99 merged 2 commits into
wso2-open-operations:mainfrom
Rashmika998:customer-portal-milestone-1
Mar 19, 2026
Merged

cloby99 merged 2 commits into
wso2-open-operations:mainfrom
Rashmika998:customer-portal-milestone-1

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR updates the users/me endpoint to return the user's last password update time.

Changes

  • Extended the users/me response model to include the last password update timestamp
  • Updated service-layer logic to fetch the password last updated value
  • Adjusted DTOs/mappings and response serialization

Reason

The current users/me response does not expose when the user last updated their password.

Including this field helps:

  • Improve account security visibility
  • Support UI/account settings flows
  • Reduce the need for additional API calls

Testing

  • Verified users/me response includes the last password update time
  • Tested behavior when the value is available and unavailable
  • Performed regression testing on user-related endpoints

Impact

  • Response structure extended (non-breaking addition)
  • No changes to request payload

Summary by CodeRabbit

  • New Features
    • The user profile endpoint now returns a lastPasswordUpdateTime field so users can see when their password was last changed; if unavailable, the field remains unset (behavior mirrors existing phone number handling).

@Rashmika998 Rashmika998 self-assigned this Mar 19, 2026
@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features App/Customer Portal Area/Backend labels Mar 19, 2026
@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e67fb745-211d-4bb8-baaa-8211000a1475

📥 Commits

Reviewing files that changed from the base of the PR and between 67d230b and 6e06eb3.

📒 Files selected for processing (1)
  • apps/customer-portal/backend/modules/scim/utils.bal
✅ Files skipped from review due to trivial changes (1)
  • apps/customer-portal/backend/modules/scim/utils.bal

📝 Walkthrough

Walkthrough

Added SCIM schema attribute handling and propagated lastPasswordUpdateTime from SCIM into the user model and /users/me response via a new utility and type updates.

Changes

Cohort / File(s) Summary
SCIM Constants & Search
apps/customer-portal/backend/modules/scim/constants.bal, apps/customer-portal/backend/modules/scim/scim.bal
Introduced ATTRIBUTE_SCHEMA = "urn:scim:wso2:schema" and added it to the attributes requested by searchUsers.
SCIM Types & Utils
apps/customer-portal/backend/modules/scim/types.bal, apps/customer-portal/backend/modules/scim/utils.bal
Added SchemaScope record and extended User to include urn:scim:wso2:schema; added processLastPasswordUpdateTime(User) to extract lastPasswordUpdateTime.
Domain Types
apps/customer-portal/backend/modules/types/types.bal
Added optional lastPasswordUpdateTime?: string? to the public User record.
Service Endpoint
apps/customer-portal/backend/service.bal
Populates lastPasswordUpdateTime for /users/me by calling scim:processLastPasswordUpdateTime and includes it in the returned types:User.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service
    participant SCIM_Client
    participant TypesModule

    Client->>Service: GET /users/me
    Service->>SCIM_Client: searchUsers(attributes: phoneNumbers, username, urn:scim:wso2:schema)
    SCIM_Client-->>Service: userResults (includes schema scope)
    Service->>SCIM_Client: (or directly) scim.processLastPasswordUpdateTime(user)
    SCIM_Client-->>Service: lastPasswordUpdateTime?
    Service->>TypesModule: build types:User (phoneNumber, lastPasswordUpdateTime)
    Service-->>Client: 200 OK with types:User
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • shayanmalinda

Poem

🐇 I hopped through schemas, found a time,

tucked in SCIM's quiet, secret rhyme.
From distant user fields it came,
a timestamp now known by name.
Hooray — the portal keeps it safe and kind.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provided deviates significantly from the repository's required template, covering only a subset of required sections. Align the PR description with the repository's template by including Purpose/Goals/Approach sections and addressing required sections like Documentation, Security checks, and Test environment.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating the users/me endpoint to fetch and return the last password update time.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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)

138-160: ⚠️ Potential issue | 🟠 Major

Avoid caching partial /users/me data when SCIM lookup fails.

If SCIM lookup fails or returns empty, phoneNumber and lastPasswordUpdateTime stay unset, but Line 163 still caches that partial object for up to the cache TTL. A transient SCIM outage can therefore hide recovered values for too long.

🛠️ Proposed fix
         string? phoneNumber = ();
         string? lastPasswordUpdateTime = ();
+        boolean shouldCacheUser = true;
         scim:User[]|error userResults = scim:searchUsers(userInfo.email);
         if userResults is error {
             // Log the error and return nil
             log:printError("Error retrieving user phone number from scim service", userResults);
+            shouldCacheUser = false;
         } else {
             if userResults.length() == 0 {
                 log:printError(string `No user found while searching phone number for user: ${userInfo.userId}`);
+                shouldCacheUser = false;
             } else {
                 phoneNumber = scim:processPhoneNumber(userResults[0]);
                 lastPasswordUpdateTime = scim:processLastPasswordUpdateTime(userResults[0]);
             }
         }
@@
-        error? cacheError = userCache.put(cacheKey, user);
-        if cacheError is error {
-            log:printWarn("Error writing user information to cache", cacheError);
+        if shouldCacheUser {
+            error? cacheError = userCache.put(cacheKey, user);
+            if cacheError is error {
+                log:printWarn("Error writing user information to cache", cacheError);
+            }
         }
         return user;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/backend/service.bal` around lines 138 - 160, The SCIM
lookup can fail leaving phoneNumber and lastPasswordUpdateTime unset but the
code still builds and caches the types:User user; change the flow so that
scim:searchUsers + scim:processPhoneNumber + scim:processLastPasswordUpdateTime
must succeed (userResults not error and userResults.length() > 0) before
constructing/caching the types:User user from userDetails; if the SCIM call
errors or returns empty, avoid constructing or persisting the partial user
(either return/skip caching early or populate explicit nulls and refresh the
cache immediately), so move the user construction inside the successful branch
or add an explicit guard around caching to prevent storing incomplete /users/me
data.
🧹 Nitpick comments (1)
apps/customer-portal/backend/service.bal (1)

142-146: Update SCIM error logs to reflect both fields now being fetched.

Current log messages mention only phone-number lookup, which is now incomplete context during incidents.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/backend/service.bal` around lines 142 - 146, The
error/log lines that currently call log:printError with messages mentioning only
"phone number" should be updated to reflect that the SCIM lookup now fetches
both fields; locate the log:printError calls around userResults and
userInfo.userId (in the block handling no results and error cases) and change
the messages to say something like "phone number and [other SCIM field]" or
"phone number and additional SCIM field(s)" so the context is accurate during
incidents; ensure both the error branch (log:printError("Error retrieving ...",
userResults)) and the no-results branch (log:printError("No user found while
searching ...")) are updated to reference both fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/customer-portal/backend/modules/scim/utils.bal`:
- Line 42: Fix the docstring typo in the SCIM user processing comment: change
"lst" to "last" in the comment that currently reads "Process SCIM user to
extract the lst password update time." so it reads "Process SCIM user to extract
the last password update time." This update should be made near the SCIM user
password extraction helper in utils.bal to improve generated docs/readability.

---

Outside diff comments:
In `@apps/customer-portal/backend/service.bal`:
- Around line 138-160: The SCIM lookup can fail leaving phoneNumber and
lastPasswordUpdateTime unset but the code still builds and caches the types:User
user; change the flow so that scim:searchUsers + scim:processPhoneNumber +
scim:processLastPasswordUpdateTime must succeed (userResults not error and
userResults.length() > 0) before constructing/caching the types:User user from
userDetails; if the SCIM call errors or returns empty, avoid constructing or
persisting the partial user (either return/skip caching early or populate
explicit nulls and refresh the cache immediately), so move the user construction
inside the successful branch or add an explicit guard around caching to prevent
storing incomplete /users/me data.

---

Nitpick comments:
In `@apps/customer-portal/backend/service.bal`:
- Around line 142-146: The error/log lines that currently call log:printError
with messages mentioning only "phone number" should be updated to reflect that
the SCIM lookup now fetches both fields; locate the log:printError calls around
userResults and userInfo.userId (in the block handling no results and error
cases) and change the messages to say something like "phone number and [other
SCIM field]" or "phone number and additional SCIM field(s)" so the context is
accurate during incidents; ensure both the error branch (log:printError("Error
retrieving ...", userResults)) and the no-results branch (log:printError("No
user found while searching ...")) are updated to reference both fields.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b43ad2e-8ca4-4261-b29c-dc62c470357a

📥 Commits

Reviewing files that changed from the base of the PR and between 497d2fa and 67d230b.

📒 Files selected for processing (6)
  • apps/customer-portal/backend/modules/scim/constants.bal
  • apps/customer-portal/backend/modules/scim/scim.bal
  • apps/customer-portal/backend/modules/scim/types.bal
  • apps/customer-portal/backend/modules/scim/utils.bal
  • apps/customer-portal/backend/modules/types/types.bal
  • apps/customer-portal/backend/service.bal

Comment thread apps/customer-portal/backend/modules/scim/utils.bal Outdated
@cloby99
cloby99 merged commit d694025 into wso2-open-operations:main Mar 19, 2026
1 check passed
@Rashmika998 Rashmika998 moved this from Done to Staging Deployed in Customer Portal Development Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/Customer Portal Area/Backend Type/Improvement Marks enhancements or improvements to existing features

Projects

Status: Staging Deployed

Development

Successfully merging this pull request may close these issues.

2 participants