Skip to content

Show the site selector and set up my site screen after the application password login #21968

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

Conversation

adalpari
Copy link
Contributor

@adalpari adalpari commented Jun 23, 2025

Description

This PR is showing the site selector screen after the user log into the app by using the Application Password flow

Testing instructions

Regular login

  1. Log into the app using a self-hosted site
  • Verify the log and the functionality works as expected (test any feature inside the app)
  1. Enable the Application Password experimental feature
  2. Open MySite page
  3. Click on the Application Password card, and follow the login form
  • Verify it works as expected and the functionalities work as well
  1. Uninstall the app
  2. Modify ExperimentalFeatures.isEnabled() as follows to force the login in a new installation
    fun isEnabled(feature: Feature) : Boolean {
        if (feature == Feature.EXPERIMENTAL_APPLICATION_PASSWORD_FEATURE) {
            return true
        }
        return appPrefsWrapper.getExperimentalFeatureConfig(feature.prefKey)
    }
  1. Log into the self-hosted site again
  • Verify you now see the Application Password (webview) flow
  • Verify you see the Site selection screen after the login
  • Verify the functionalities work
Screen.Recording.2025-06-23.at.16.42.46.mov

adalpari and others added 18 commits June 19, 2025 20:25
…-the-site-selector-and-set-up-MySite-screen-after-the-Application-Login

# Conflicts:
#	WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginActivity.kt
#	WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModel.kt
@dangermattic
Copy link
Collaborator

dangermattic commented Jun 23, 2025

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

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jun 23, 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
Versionpr21968-495bc0c
Commit495bc0c
Direct Downloadjetpack-prototype-build-pr21968-495bc0c.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jun 23, 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
Versionpr21968-495bc0c
Commit495bc0c
Direct Downloadwordpress-prototype-build-pr21968-495bc0c.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.10%. Comparing base (1ea4458) to head (495bc0c).
Report is 2 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #21968   +/-   ##
=======================================
  Coverage   39.10%   39.10%           
=======================================
  Files        2150     2150           
  Lines      101026   101026           
  Branches    15521    15521           
=======================================
  Hits        39504    39504           
  Misses      58034    58034           
  Partials     3488     3488           

☔ 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 requested a review from Copilot June 23, 2025 14:43
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 enables a new flow after application password login by displaying the site selector or post-signup interstitial, depending on various credential and site configuration outcomes. Key changes include:

  • Updates to the ApplicationPasswordLoginViewModel to support different navigation outcomes through a NavigationActionData object.
  • Refactoring of test cases in ApplicationPasswordLoginViewModelTest for improved clarity and naming.
  • Adjustments to the ApplicationPasswordLoginHelper and ApplicationPasswordLoginActivity to support the new site selection and profile fetching flow.

Reviewed Changes

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

File Description
WordPress/src/test/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModelTest.kt Updated test names and assertions to use NavigationActionData and variable renaming from uriLogin to urlLogin
WordPress/src/main/java/org/wordpress/android/ui/accounts/login/ApplicationPasswordLoginHelper.kt Introduced URL normalization before comparing sites
WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModel.kt Reworked setupSite flow, error handling, and added EventBus subscribers for site changes and profile fetches
WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginActivity.kt Refactored navigation logic in openMainActivity to handle different navigation actions
Comments suppressed due to low confidence (2)

WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModel.kt:138

  • In the fetchSites function's catch block, the logged message 'Error storing credentials' is misleading because the function is responsible for fetching sites. Consider updating the log message to 'Error fetching sites' to clearly indicate the operation in error.
            }

WordPress/src/main/java/org/wordpress/android/ui/accounts/applicationpassword/ApplicationPasswordLoginViewModel.kt:125

  • In the fetchSites function, the error log 'Cannot store credentials: rawData is empty' should be rephrased to reflect the actual context. A message like 'Insufficient login data for fetching sites' would more accurately describe the error condition.
                emitErrorFetching(urlLogin)

@adalpari adalpari marked this pull request as ready for review June 23, 2025 14:44
@adalpari adalpari requested a review from nbradbury June 23, 2025 14:44
@nbradbury nbradbury self-assigned this Jun 23, 2025
/**
* This method is called to set up the site with the provided raw data.
*
* @param rawData The raw data containing the callback data from the application password login.
*/
fun setupSite(rawData: String) {
viewModelScope.launch {
if (rawData.isEmpty()) {
Log.e(TAG, "Cannot store credentials: rawData is empty")
Copy link
Contributor

Choose a reason for hiding this comment

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

NP: I think we want to use appLogWrapper for logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity: what's the purpose of using that wrapper? I don't see it taking any extra action like sending the log to crashlytics or similar, plus I see a couple of disadvantages:

  1. We need to use a set of predefined tags. Which is ok, but creates a big logs scope when debugging
  2. We can not include a stacktrace as an extra argument

Screenshot 2025-06-24 at 09 44 42

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, I don't have any context about this class other than it seems to have been created to enable mocking for tests. Including a stack trace would be simple to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, related question: do we have any logger to send the logs to crashlytics or sentry?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure AppLog does this. It also enables users to view the app log if needed via AppLogViewerActivity (Me > Help & Support > Logs).

val isError: Boolean
)

class AppPrefsWrapper @Inject constructor() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this. We already have an AppPrefsWrapper class with shouldShowPostSignupInterstitial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I didn't realise there was already a wrapper. I created a new internal one to be able to inject it in tests instead of using the static access to the Android sdk
Done: 4dab50b

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.

@adalpari This tested fine and overall looks good, but I think we'll want to address the AppPrefsWrapper issue.

adalpari added 6 commits June 24, 2025 09:46
…e-screen-after-the-Application-Login' of https://github.com/wordpress-mobile/WordPress-Android into feature/CMM-519-Show-the-site-selector-and-set-up-MySite-screen-after-the-Application-Login
…set-up-MySite-screen-after-the-Application-Login
…set-up-MySite-screen-after-the-Application-Login
…e-screen-after-the-Application-Login' of https://github.com/wordpress-mobile/WordPress-Android into feature/CMM-519-Show-the-site-selector-and-set-up-MySite-screen-after-the-Application-Login
@adalpari adalpari requested a review from nbradbury June 24, 2025 14:30
…set-up-MySite-screen-after-the-Application-Login
Copy link

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.

All good! :shipit:

@adalpari adalpari enabled auto-merge (squash) June 25, 2025 12:47
@adalpari adalpari merged commit acb1161 into trunk Jun 25, 2025
26 checks passed
@adalpari adalpari deleted the feature/CMM-519-Show-the-site-selector-and-set-up-MySite-screen-after-the-Application-Login branch June 25, 2025 12:58
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