Skip to content

Storing api root url from discovery process #22005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 11, 2025

Conversation

adalpari
Copy link
Contributor

Description

This PR stores the API_ROOT_URL from the discovery process in advance of waiting for the sites fetch to get it.
This is done this way to be sure we are using the result from the RS discovery in cases where there is no access to the current XML-RPC endpoints.
In addition, some refactor has been done and now we are using SiteStore directly instead of some SQL calls.

Testing instructions

  1. Log into a self-hosted site
  2. Enable Application Password and follow the login process
  • Verify it works as expected
  • Open the DB -> SiteModel and verify the credential fields and the WP_API_REST_URL one are filled
Screenshot 2025-07-10 at 13 03 36

@adalpari adalpari requested a review from Copilot July 10, 2025 11:04
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 10, 2025

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the way application password credentials are stored by switching from direct SQL persistence to using the Flux dispatcher and SiteStore, and ensures the API root URL from discovery is saved. It also updates related tests and refines error logging.

  • Refactor persistence: replace SiteSqlUtils calls with SiteStore and a new DispatcherWrapper
  • Save wpApiRestUrl from the discovery result when storing credentials
  • Update tests to mock and verify against siteStore and DispatcherWrapper

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/test/java/org/wordpress/android/ui/accounts/login/ApplicationPasswordLoginHelperTest.kt Tests updated to mock SiteStore and DispatcherWrapper instead of SiteSqlUtils
src/main/java/org/wordpress/android/ui/accounts/login/ApplicationPasswordLoginHelper.kt Replaced persistence with dispatcher actions, added API root URL capture, and wrapped dispatcher
src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModel.kt Adjusted log statements to use exception messages instead of raw stack trace arrays

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 10, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr22005-2e71c07
Commit2e71c07
Direct Downloadjetpack-prototype-build-pr22005-2e71c07.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 10, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr22005-2e71c07
Commit2e71c07
Direct Downloadwordpress-prototype-build-pr22005-2e71c07.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 61.90476% with 24 lines in your changes missing coverage. Please review.

Project coverage is 39.02%. Comparing base (f393c90) to head (2e71c07).
Report is 1 commits behind head on trunk.

Files with missing lines Patch % Lines
...ava/org/wordpress/android/fluxc/store/SiteStore.kt 0.00% 11 Missing ⚠️
...i/accounts/login/ApplicationPasswordLoginHelper.kt 77.77% 4 Missing and 2 partials ⚠️
...roid/fluxc/network/xmlrpc/site/SiteXMLRPCClient.kt 20.00% 4 Missing ⚠️
...ationpassword/ApplicationPasswordLoginViewModel.kt 85.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #22005   +/-   ##
=======================================
  Coverage   39.02%   39.02%           
=======================================
  Files        2153     2153           
  Lines      101494   101494           
  Branches    15585    15585           
=======================================
  Hits        39613    39613           
  Misses      58384    58384           
  Partials     3497     3497           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adalpari adalpari marked this pull request as ready for review July 10, 2025 11:41
@adalpari adalpari requested a review from nbradbury July 10, 2025 11:41
@nbradbury nbradbury self-assigned this Jul 10, 2025
@nbradbury
Copy link
Contributor

@adalpari When I follow the testing steps using the same Jurassic Ninja site I shared with you on Slack earlier, I first see a toast saying the credentials were stored and then see another saying there was an error saving credentials:

apppass.mp4

Checking the SiteModel table for this site, I see this:

db

@adalpari
Copy link
Contributor Author

@nbradbury I think there might be a race condition. I've now changed the approach. Could you give it another try?

Copy link
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

I think there might be a race condition. I've now changed the approach. Could you give it another try?

That seems to have fixed the problem 🎉 Unfortunately, this PR is failing CI now. I'll go ahead and approve it and you can merge once that's addressed.

@adalpari
Copy link
Contributor Author

adalpari commented Jul 11, 2025

I think there might be a race condition. I've now changed the approach. Could you give it another try?

That seems to have fixed the problem 🎉 Unfortunately, this PR is failing CI now. I'll go ahead and approve it and you can merge once that's addressed.

Yes, I broke some tests, so I am fixing them right now. Thanks!

@adalpari adalpari enabled auto-merge (squash) July 11, 2025 11:05
Copy link

@adalpari adalpari merged commit 55cd920 into trunk Jul 11, 2025
24 of 26 checks passed
@adalpari adalpari deleted the internal/storing-api-root-url-from-discovery-process branch July 11, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants