-
Notifications
You must be signed in to change notification settings - Fork 136
Description
Describe the bug
When a logged user role is changed from wc-core to a role different from Administrator or ShopManager, the next time the App is opened from scratch (app has been killed) the app should display the following screen:
Right now the app needs to be killed twice in order to for it to properly refresh the user eligibility state and display the expected error screen.
The reason for this bug is that in MainActivity, the code that checks user eligibility (checks a persisted flag) runs before we fetch and refresh the actual user role from the API that is triggered in the AppInitializer.
Essentially, this code from MainActivity.kt runs before:
if (selectedSite.exists() && !presenter.isUserEligible()) {
showUserEligibilityErrorScreen()
return
}this other code from AppInitializer.kt that refreshes the status of user eligibility.
override fun onFirstActivityResumed() {
// App is completely restarted
if (networkStatus.isConnected()) {
if (accountStore.hasAccessToken()) {
// Update the WPCom account if the user is signed in using a WPCom account
dispatcher.dispatch(AccountActionBuilder.newFetchAccountAction())
dispatcher.dispatch(AccountActionBuilder.newFetchSettingsAction())
}
// Update the list of sites
appCoroutineScope.launch {
wooCommerceStore.fetchWooCommerceSites()
// Added to fix this crash
// https://github.com/woocommerce/woocommerce-android/issues/4842
if (selectedSite.getSelectedSiteId() != -1 &&
!selectedSite.exists() &&
ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(STARTED)
) {
// The previously selected site is not connected anymore, take the user to the site picker
WooLog.i(DASHBOARD, "Selected site no longer exists, showing site picker")
openMainActivity()
}
}
// Update the user info
if (selectedSite.exists()) {
userEligibilityFetcher.fetchUserEligibility()
}
}
}Ideally whenever we refresh user eligibility state fetching fresh data from the API we should trigger an event to show the expected error screen if the user is not eligible anymore. If this turns out to be complex we can also ensure that AppInitializer.kt triggers opening MainActivity again once user role state has been updated and is not eligible anymore.
