-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Jetpack REST connection: Finalize #22133
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
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
da347ce
Skip wp.com login if access token exists
nbradbury c95fa12
First pass at installing Jetpack
nbradbury f9dba6f
Second pass at installing Jetpack
nbradbury 03f85e7
First pass at handling error response
nbradbury 74f5f45
Return a pair for installJetpack and restored launch wpcom login from…
nbradbury a298f39
Added InstallJetpackResult to make it clear the second item in the pa…
nbradbury d15a2bb
Added InstallJetpackResult to make it clear the second item in the pa…
nbradbury 8d426ca
refresh the site before starting jetpack install
nbradbury ae6eaa3
Fixed detekt warnings, fetch site directly
nbradbury f72cc1f
Added/updated comments
nbradbury b2f520b
Merge branch 'trunk' of https://github.com/wordpress-mobile/WordPress…
nbradbury fe56a2e
Handle inactive Jetpack install, refresh site in init
nbradbury 1ee7396
Tweaked comments
nbradbury 1cc674f
Restored check for access token
nbradbury 2c1a58a
Check if we need to install or simply activate the jp plugin
nbradbury 1237bc9
Simplified JetpackInstaller to always install the plugin
nbradbury c171b36
Increased timeout
nbradbury d1b59a1
Fixed Detekt warnings
nbradbury 974941a
Merge branch 'trunk' into feature/jetpack-connect-install
nbradbury b5b7cbc
Simplified JetpackInstaller.kt
nbradbury a5ac0b4
Simplified JetpackInstaller.kt, p2
nbradbury 5e4aa19
Added log message
nbradbury fe48169
Get plugin status before activating
nbradbury 6af0b6c
Use correct names for slugs
nbradbury 6354253
Removed iOS commented code
nbradbury 8c4dca1
Reduced timeout from 60 to 45 seconds
nbradbury e19e769
Simplified installer
nbradbury ca4efc5
Code cleanup
nbradbury 2a163dd
Removed refreshSite
nbradbury 89ac854
Merge branch 'trunk' into feature/jetpack-connect-install
nbradbury d705d4c
Pass WpApiClient as a parameter
nbradbury f7f49ff
Added missing space
nbradbury 7d7d38b
Use a Result<PluginStatus> for installJetpack
nbradbury 4baf46d
Add a delay to wp.com login if already logged in
nbradbury bbccb48
Removed unnecessary launch
nbradbury b601a0c
Suppress TooGenericExceptionCaught
nbradbury b59b354
Merge branch 'trunk' into feature/jetpack-connect-install
nbradbury b6b0eb8
Moved JetpackConnectionHelper to its own helper class
nbradbury 2f25831
Connect Jetpack to site
nbradbury 61757f3
Handle failure
nbradbury 3f2aa5a
Added fun to connect user
nbradbury dc18965
Added error handling to connect user
nbradbury 9ee69c6
Updated error handling to connect user
nbradbury 615f0c9
Remove extra message from all errors except ErrorType.Unknown
nbradbury 860cd15
Throw exception on invalid authentication
nbradbury 078494b
Simplified JetpackConnectionHelper.kt
nbradbury 59676e7
Simplified JetpackConnector
nbradbury c94134f
Code tweaks
nbradbury eaa9003
Further simplified JetpackConnector.kt
nbradbury 7a2dcd1
Modified text & icon for user connection step
nbradbury b28a408
Merge branch 'trunk' into feature/jetpack-connect-site-and-user
nbradbury cdbe695
Clarified that REST credentials are required
nbradbury 086d881
Corrected ConnectUser step completion
nbradbury ff4f1fb
Corrected ConnectUser step failure
nbradbury 35e77b0
Removed unnecessary job?.cancel
nbradbury 6c03ee4
Merge branch 'trunk' of https://github.com/wordpress-mobile/WordPress…
nbradbury 328139a
Minor code cleanup
nbradbury 76734d0
Added skeleton for finalization
nbradbury 88d58dd
Handle Done click separately
nbradbury 1665a55
Remove "Simulated" from screen title
nbradbury ddbd8a1
Pass the connection source to the activity and retain it in the view …
nbradbury 6f68ccb
First pass at activating stats module
nbradbury 232433f
Second pass at activating stats module
nbradbury 69ace6a
Second pass at activating stats module
nbradbury a03cd69
Renamed stats helper to module helper
nbradbury 4f4cca0
Fixed JetpackModuleHelper
nbradbury 163941a
Fixed JetpackModuleHelper, p2
nbradbury 7d6ebac
Reload site before checking if module is activated
nbradbury 64fd886
Simplified JetpackModuleHelper.kt
nbradbury d3e5261
Ignore response in JetpackModuleHelper.kt
nbradbury ffceda9
Use isActiveModuleEnabled
nbradbury 2f55e53
Refetch sites before checking if module is activated
nbradbury 73db472
Added TODO
nbradbury 91638ef
Apply the connected site ID to the site
nbradbury be4abdd
Use more reliable isActiveModuleEnabled
nbradbury 3ff0556
Store site rather than call getSelectedSite everywhere
nbradbury 18c0e39
Removed unnecessary var
nbradbury c7f773a
Retain the REST passwords
nbradbury 67adc41
Reworded comment
nbradbury 54a00c4
Simplified copyRestPasswords
nbradbury 3ba69c3
Removed unused PREFS
nbradbury e55e551
Simplified JetpackModuleHelper
nbradbury ec1eafa
Defer copying passwords to a future PR
nbradbury 77802b9
Limit feature to Jetpack app
nbradbury 49bdb79
Merge branch 'trunk' into feature/jetpack-connect-finalize
nbradbury 05fd643
Fixed failing test
nbradbury 6fe83ba
First pass at rest connection from notifs
nbradbury c72efff
Second pass at rest connection from notifs
nbradbury ec8b6a8
Simplified starting the flow
nbradbury abc9c54
Fixed detekt warning
nbradbury 784ed28
Renamed class to clarify that it's solely about the stats module
nbradbury 4280ce0
Merge branch 'trunk' of https://github.com/wordpress-mobile/WordPress…
nbradbury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../src/main/java/org/wordpress/android/ui/jetpackrestconnection/JetpackStatsModuleHelper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.wordpress.android.ui.jetpackrestconnection | ||
|
||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.fluxc.store.JetpackStore | ||
import org.wordpress.android.fluxc.store.JetpackStore.ActivateStatsModulePayload | ||
import org.wordpress.android.fluxc.store.SiteStore | ||
import javax.inject.Inject | ||
|
||
class JetpackStatsModuleHelper @Inject constructor( | ||
private val jetpackStore: JetpackStore, | ||
private val siteStore: SiteStore | ||
) { | ||
suspend fun activateStatsModule(site: SiteModel): Result<Unit> { | ||
if (isStatsModuleActivated(site)) { | ||
return Result.success(Unit) | ||
} | ||
|
||
jetpackStore.activateStatsModule(ActivateStatsModulePayload(site)) | ||
|
||
// ignore the activation response as it's unreliable, instead just check if it's activated now | ||
return verifyStatsModuleActivation(site) | ||
} | ||
|
||
/** | ||
* Fetch Jetpack sites filtering for this site and check if the module is now activated. Note that fetching | ||
* the single site fails because of changes to it during the connection flow. | ||
*/ | ||
private suspend fun verifyStatsModuleActivation( | ||
site: SiteModel, | ||
): Result<Unit> { | ||
val payload = SiteStore.FetchSitesPayload( | ||
filters = listOf(SiteStore.SiteFilter.JETPACK) | ||
) | ||
return siteStore.fetchSites(payload).updatedSites.firstOrNull { | ||
it.siteId == site.siteId | ||
}?.let { updatedSite -> | ||
if (isStatsModuleActivated(updatedSite)) { | ||
Result.success(Unit) | ||
} else { | ||
Result.failure(Exception("Stats module not activated")) | ||
} | ||
} ?: Result.failure(Exception("Site not found")) | ||
nbradbury marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private fun isStatsModuleActivated(site: SiteModel) = | ||
site.isActiveModuleEnabled(STATS_MODULE_NAME) | ||
|
||
companion object { | ||
private const val STATS_MODULE_NAME = "stats" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.