Skip to content

Commit 7546298

Browse files
Tag support requests when app passwords are enabled for Jetpack sites
1 parent c5653a0 commit 7546298

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.woocommerce.android.applicationpasswords
2+
3+
import org.wordpress.android.fluxc.model.SiteModel
4+
import org.wordpress.android.fluxc.network.rest.wpapi.applicationpasswords.ApplicationPasswordsConfiguration
5+
import org.wordpress.android.fluxc.network.rest.wpapi.applicationpasswords.JetpackApplicationPasswordsSupport
6+
import javax.inject.Inject
7+
8+
class IsAppPasswordsSupportedForJetpackSite @Inject constructor(
9+
private val applicationPasswordsConfiguration: ApplicationPasswordsConfiguration,
10+
private val jetpackApplicationPasswordsSupport: JetpackApplicationPasswordsSupport
11+
) {
12+
suspend operator fun invoke(site: SiteModel): Boolean {
13+
return applicationPasswordsConfiguration.isEnabledForJetpackAccess()
14+
&& jetpackApplicationPasswordsSupport.supportsAppPasswords(site)
15+
}
16+
}

WooCommerce/src/main/kotlin/com/woocommerce/android/support/zendesk/ZendeskTicketRepository.kt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.woocommerce.android.support.zendesk
22

33
import android.content.Context
44
import android.os.Parcelable
5+
import com.woocommerce.android.applicationpasswords.IsAppPasswordsSupportedForJetpackSite
56
import com.woocommerce.android.extensions.formatResult
67
import com.woocommerce.android.support.help.HelpOrigin
78
import com.woocommerce.android.support.zendesk.RequestConstants.requestCreationIdentityNotSetErrorMessage
@@ -35,7 +36,8 @@ class ZendeskTicketRepository @Inject constructor(
3536
private val siteStore: SiteStore,
3637
private val dispatchers: CoroutineDispatchers,
3738
private val wooLog: WooLog,
38-
private val ssrFetcher: WCSSRModelCachingFetcher
39+
private val ssrFetcher: WCSSRModelCachingFetcher,
40+
private val isAppPasswordsSupportedForJetpackSite: IsAppPasswordsSupportedForJetpackSite
3941
) {
4042
/**
4143
* This function creates a new customer Support Request through the Zendesk API Providers.
@@ -140,16 +142,21 @@ class ZendeskTicketRepository @Inject constructor(
140142
* This is a helper function which returns a set of pre-defined tags depending on some conditions. It accepts a list of
141143
* custom tags to be added for special cases.
142144
*/
143-
private fun buildZendeskTags(
145+
private suspend fun buildZendeskTags(
144146
selectedSite: SiteModel?,
145147
allSites: List<SiteModel>?,
146148
origin: HelpOrigin,
147149
extraTags: List<String>
148150
): List<String> {
149151
val tags = ArrayList<String>()
150-
if (selectedSite?.connectionType == SiteConnectionType.ApplicationPasswords) {
151-
tags.add(ZendeskTags.applicationPasswordAuthenticated)
152+
selectedSite?.let {
153+
if (selectedSite.connectionType == SiteConnectionType.ApplicationPasswords) {
154+
tags.add(ZendeskTags.applicationPasswordAuthenticated)
155+
} else if (isAppPasswordsSupportedForJetpackSite(it)) {
156+
tags.add(ZendeskTags.jetpackSiteUsingAppPasswords)
157+
}
152158
}
159+
153160
allSites?.let { it ->
154161
// Add wpcom tag if at least one site is WordPress.com site
155162
if (it.any { it.isWPCom }) {
@@ -181,14 +188,16 @@ sealed class TicketType(
181188
val tags: List<String> = emptyList(),
182189
val excludedTags: List<String> = emptyList()
183190
) : Parcelable {
184-
@Parcelize object MobileApp : TicketType(
191+
@Parcelize
192+
object MobileApp : TicketType(
185193
form = TicketCustomField.wooMobileFormID,
186194
categoryName = ZendeskConstants.mobileAppCategory,
187195
subcategoryName = ZendeskConstants.mobileSubcategoryValue,
188196
tags = listOf(ZendeskTags.mobileApp)
189197
)
190198

191-
@Parcelize object InPersonPayments : TicketType(
199+
@Parcelize
200+
object InPersonPayments : TicketType(
192201
form = TicketCustomField.wooMobileFormID,
193202
categoryName = ZendeskConstants.mobileAppCategory,
194203
subcategoryName = ZendeskConstants.mobileSubcategoryValue,
@@ -198,7 +207,8 @@ sealed class TicketType(
198207
)
199208
)
200209

201-
@Parcelize object Payments : TicketType(
210+
@Parcelize
211+
object Payments : TicketType(
202212
form = TicketCustomField.wooFormID,
203213
categoryName = ZendeskConstants.supportCategory,
204214
subcategoryName = ZendeskConstants.paymentsSubcategoryValue,
@@ -212,7 +222,8 @@ sealed class TicketType(
212222
excludedTags = listOf(ZendeskTags.jetpackTag)
213223
)
214224

215-
@Parcelize object WooPlugin : TicketType(
225+
@Parcelize
226+
object WooPlugin : TicketType(
216227
form = TicketCustomField.wooFormID,
217228
categoryName = ZendeskConstants.supportCategory,
218229
subcategoryName = "",
@@ -224,7 +235,8 @@ sealed class TicketType(
224235
excludedTags = listOf(ZendeskTags.jetpackTag)
225236
)
226237

227-
@Parcelize object OtherPlugins : TicketType(
238+
@Parcelize
239+
object OtherPlugins : TicketType(
228240
form = TicketCustomField.wooFormID,
229241
categoryName = ZendeskConstants.supportCategory,
230242
subcategoryName = ZendeskConstants.storeSubcategoryValue,
@@ -267,6 +279,7 @@ object TicketCustomField {
267279

268280
object ZendeskTags {
269281
const val applicationPasswordAuthenticated = "application_password_authenticated"
282+
const val jetpackSiteUsingAppPasswords = "jetpack_site_using_app_passwords"
270283
const val mobileApp = "mobile_app"
271284
const val woocommerceCore = "woocommerce_core"
272285
const val paymentsProduct = "woocommerce_payments"

0 commit comments

Comments
 (0)