-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12640 from woocommerce/issue/12146-enable-for-jet…
…pack-plugin Issue/12146 enable for jetpack plugin
- Loading branch information
Showing
3 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
21 changes: 18 additions & 3 deletions
21
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/IsBlazeEnabled.kt
This file contains 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 |
---|---|---|
@@ -1,17 +1,32 @@ | ||
package com.woocommerce.android.ui.blaze | ||
|
||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.tools.SiteConnectionType | ||
import com.woocommerce.android.tools.SiteConnectionType.Jetpack | ||
import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled | ||
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_BLAZE | ||
import javax.inject.Inject | ||
|
||
class IsBlazeEnabled @Inject constructor( | ||
private val selectedSite: SelectedSite, | ||
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled, | ||
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled | ||
) { | ||
companion object { | ||
private const val BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG = "blaze-ads" | ||
} | ||
|
||
suspend operator fun invoke(): Boolean = selectedSite.getIfExists()?.isAdmin ?: false && | ||
selectedSite.connectionType == SiteConnectionType.Jetpack && | ||
hasAValidJetpackConnectionForBlaze() && | ||
selectedSite.getIfExists()?.canBlaze ?: false && | ||
isRemoteFeatureFlagEnabled(WOO_BLAZE) | ||
|
||
/** | ||
* In order for Blaze to work, the site requires the Jetpack Sync module to be enabled. This means not all | ||
* Jetpack connection will work. For now, Blaze will only be enabled for sites with Jetpack plugin installed and | ||
* active, or for sites with Blaze for WooCommerce plugin installed and connected. | ||
*/ | ||
private fun hasAValidJetpackConnectionForBlaze() = | ||
selectedSite.connectionType == Jetpack || isBlazeForWooCommercePluginActive() | ||
|
||
private fun isBlazeForWooCommercePluginActive(): Boolean = | ||
selectedSite.get().activeJetpackConnectionPlugins?.contains(BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG) == true | ||
} |
This file contains 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