Skip to content

Conversation

@Jignesh-dimagi
Copy link
Contributor

Technical Summary

https://dimagi.atlassian.net/browse/CCCT-1275

Feature Flag

Improvements

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

📝 Walkthrough

Walkthrough

The changes refactor how API service instances are obtained across the codebase, shifting from direct Retrofit client usage to accessing a singleton ApiService interface via ApiClient.getClientApi(). Several method and constant names are updated to reflect a shift from "profile setting" to "profile completion," including changes to method signatures, endpoint paths, and parameter lists. The profile completion API now requires an additional PIN parameter. The affected methods and endpoints are renamed consistently throughout the relevant classes, with corresponding updates to method calls and endpoint annotations.

Sequence Diagram(s)

sequenceDiagram
    participant Fragment as PersonalIdPhotoCaptureFragment
    participant ApiPersonalId
    participant ApiClient
    participant ApiService
    participant Server

    Fragment->>ApiPersonalId: setPhotoAndCompleteProfile(userId, password, userName, photoAsBase64, pin, callback)
    ApiPersonalId->>ApiClient: getClientApi()
    ApiClient-->>ApiPersonalId: ApiService instance
    ApiPersonalId->>ApiService: completeProfile(authToken, body)
    ApiService->>Server: POST /users/complete_profile (with recovery_pin)
    Server-->>ApiService: Response
    ApiService-->>ApiPersonalId: Response
    ApiPersonalId-->>Fragment: callback.onSuccess/onFailure
Loading

Possibly related PRs

Suggested labels

product/invisible

Suggested reviewers

  • shubham1g5
  • OrangeAndGreen

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/src/org/commcare/fragments/personalId/PersonalIdPhotoCaptureFragment.java (1)

118-120: Fix spacing in parameter list

The spacing around the PIN parameter is inconsistent. Also, the method is now correctly using the updated API endpoint which requires the PIN parameter.

-        ApiPersonalId.setPhotoAndCompleteProfile(requireContext(), connectUserRecord.getUserId(), connectUserRecord.getPassword(),
-                connectUserRecord.getName(), photoAsBase64,connectUserRecord.getPin() ,networkResponseCallback);
+        ApiPersonalId.setPhotoAndCompleteProfile(requireContext(), connectUserRecord.getUserId(), connectUserRecord.getPassword(),
+                connectUserRecord.getName(), photoAsBase64, connectUserRecord.getPin(), networkResponseCallback);
app/src/org/commcare/connect/network/ApiPersonalId.java (1)

320-336: Consider adding validation for the PIN parameter.

The method accepts a PIN parameter but doesn't validate it before sending to the API. Consider adding validation to ensure it meets any format or length requirements specified by the backend.

public static void setPhotoAndCompleteProfile(Context context, String userId, String password, String userName,
                                          String photoAsBase64, String pin, IApiCallback callback) {
    Objects.requireNonNull(photoAsBase64);
    Objects.requireNonNull(userName);
+   Objects.requireNonNull(pin);
+   
+   // Consider adding PIN format validation
+   // if (!isValidPin(pin)) {
+   //     callback.processFailure(400);
+   //     return;
+   // }
    
    AuthInfo authInfo = new AuthInfo.ProvidedAuth(userId, password, false);
    String token = HttpUtils.getCredential(authInfo);
    Objects.requireNonNull(token);

    HashMap<String, String> params = new HashMap<>();
    params.put("photo", photoAsBase64);
    params.put("name", userName);
    params.put("recovery_pin", pin);

    ApiService apiService = ApiClient.getClientApi();
    Call<ResponseBody> call = apiService.completeProfile(token, params);
    callApi(context, call, callback);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19a21e2 and 9af3163.

📒 Files selected for processing (5)
  • app/src/org/commcare/connect/network/ApiPersonalId.java (11 hunks)
  • app/src/org/commcare/connect/network/connectId/ApiClient.java (1 hunks)
  • app/src/org/commcare/connect/network/connectId/ApiEndPoints.java (1 hunks)
  • app/src/org/commcare/connect/network/connectId/ApiService.java (1 hunks)
  • app/src/org/commcare/fragments/personalId/PersonalIdPhotoCaptureFragment.java (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
app/src/org/commcare/connect/network/connectId/ApiService.java (1)
app/src/org/commcare/connect/network/connectId/ApiEndPoints.java (1)
  • ApiEndPoints (3-35)
app/src/org/commcare/fragments/personalId/PersonalIdPhotoCaptureFragment.java (1)
app/src/org/commcare/connect/network/ApiPersonalId.java (1)
  • ApiPersonalId (47-431)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint Code Base
🔇 Additional comments (7)
app/src/org/commcare/connect/network/connectId/ApiClient.java (2)

19-19: Good singleton pattern implementation

Changed from holding a Retrofit instance to directly holding the ApiService interface instance. This is a better design that encapsulates the service creation logic.


24-33: Good refactoring to expose the API service directly

Renamed from getClient() to getClientApi() with appropriate return type change. This improvement:

  1. Prevents redundant service creation across the codebase
  2. Ensures a consistent singleton instance is used
  3. Simplifies client code by removing the need for .create(ApiService.class) calls

The double-checked locking pattern is correctly maintained for thread safety.

app/src/org/commcare/fragments/personalId/PersonalIdPhotoCaptureFragment.java (2)

75-75: Method name update aligns with new API endpoint

Renamed from uploadImage() to uploadImageAndCompleteProfile() to reflect the updated endpoint functionality.


85-85: Method implementation name correctly updated

Method declaration renamed to match the caller in line 75.

app/src/org/commcare/connect/network/connectId/ApiService.java (1)

23-25: API method updated to reflect new endpoint name

Renamed from setProfile to completeProfile to align with the endpoint rename in ApiEndPoints.java. This update is part of the changes needed for the profile completion flow that now requires a PIN parameter.

app/src/org/commcare/connect/network/ApiPersonalId.java (2)

256-256: Good refactoring to use singleton ApiService.

The code consistently switches from manually creating ApiService instances to using the singleton approach via ApiClient.getClientApi(). This promotes better resource management and maintainability by centralizing the API client initialization.

Also applies to: 269-269, 283-283, 296-296, 315-315, 333-333, 343-343, 351-351, 363-363, 374-374, 383-383, 395-395


320-321:

Details

✅ Verification successful

Method signature updated to include PIN for profile completion.

The method has been renamed from setPhotoAndName to setPhotoAndCompleteProfile with an additional pin parameter. The implementation properly passes this new parameter to the API endpoint, which has also been renamed from setProfile to completeProfile to reflect the semantic change.

Let's verify that all callers of this method have been updated to include the new PIN parameter:

Also applies to: 331-331, 334-334


🏁 Script executed:

#!/bin/bash
# Find all references to the setPhotoAndCompleteProfile method
rg -A 3 "setPhotoAndCompleteProfile" --type java

Length of output: 1152


Callers updated to include PIN parameter

Verified that all invocations of setPhotoAndCompleteProfile now pass connectUserRecord.getPin(), e.g. in:

  • app/src/org/commcare/fragments/personalId/PersonalIdPhotoCaptureFragment.java

No further changes required.

public static final String changePhoneNo = "/users/change_phone";
public static final String updateProfile = "/users/update_profile";
public static final String setProfile = "/users/set_profile";
public static final String completeProfile = "/users/complete_profile ";
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix trailing space in URL endpoint

There's an unintended trailing space in the URL string that could cause API failures.

-    public static final String completeProfile = "/users/complete_profile ";
+    public static final String completeProfile = "/users/complete_profile";
🤖 Prompt for AI Agents
In app/src/org/commcare/connect/network/connectId/ApiEndPoints.java at line 11,
remove the trailing space at the end of the completeProfile URL string to ensure
the endpoint is correct and prevent API call failures.

shubham1g5
shubham1g5 previously approved these changes May 22, 2025

public static Retrofit getClient() {
if (retrofit == null) {
public static ApiService getClientApi() {
Copy link
Contributor

Choose a reason for hiding this comment

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

yay, thanks for getting this in.

@Jignesh-dimagi Jignesh-dimagi merged commit 2f8a062 into master May 22, 2025
4 of 7 checks passed
@Jignesh-dimagi Jignesh-dimagi deleted the jignesh/changes/ccct_1275 branch May 22, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-integration-tests Skip android tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants