Skip to content

Commit 8da648c

Browse files
authored
Merge pull request #8171 from woocommerce/task/add-ssr-to-zd
Add System Status Report to ZenDesk support requests
2 parents 0a69904 + d58376f commit 8da648c

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

WooCommerce/Classes/Tools/Zendesk/ZendeskManager.swift

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import WordPressShared
88
import CoreTelephony
99
import SafariServices
1010
import Yosemite
11+
import Experiments
1112

1213
extension NSNotification.Name {
1314
static let ZDPNReceived = NSNotification.Name(rawValue: "ZDPNReceived")
@@ -41,6 +42,7 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
4142
func showTicketListIfPossible(from controller: UIViewController)
4243
func showSupportEmailPrompt(from controller: UIViewController, completion: @escaping onUserInformationCompletion)
4344
func getTags(supportSourceTag: String?) -> [String]
45+
func fetchSystemStatusReport()
4446
func initialize()
4547
func reset()
4648
}
@@ -92,6 +94,10 @@ struct NoZendeskManager: ZendeskManagerProtocol {
9294
[]
9395
}
9496

97+
func fetchSystemStatusReport() {
98+
// no-op
99+
}
100+
95101
func initialize() {
96102
// no-op
97103
}
@@ -146,6 +152,8 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
146152
private let stores = ServiceLocator.stores
147153
private let storageManager = ServiceLocator.storageManager
148154

155+
private let isSSRFeatureFlagEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.systemStatusReportInSupportRequest)
156+
149157
/// Controller for fetching site plugins from Storage
150158
///
151159
private lazy var pluginResultsController: ResultsController<StorageSitePlugin> = createPluginResultsController()
@@ -202,6 +210,25 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
202210
return ippTags.map { $0.rawValue }
203211
}
204212

213+
/// Instantiates the SystemStatusReportViewModel as soon as the Zendesk instance needs it
214+
/// This generally happens in the SettingsViewModel if we need to fetch the site's System Status Report
215+
///
216+
private lazy var systemStatusReportViewModel: SystemStatusReportViewModel = SystemStatusReportViewModel(
217+
siteID: ServiceLocator.stores.sessionManager.defaultSite?.siteID ?? 0
218+
)
219+
220+
/// Formatted system status report to be displayed on-screen
221+
///
222+
private var systemStatusReport: String {
223+
systemStatusReportViewModel.statusReport
224+
}
225+
226+
/// Handles fetching the site's System Status Report
227+
///
228+
func fetchSystemStatusReport() {
229+
systemStatusReportViewModel.fetchReport()
230+
}
231+
205232
func showNewRequestIfPossible(from controller: UIViewController) {
206233
showNewRequestIfPossible(from: controller, with: nil)
207234
}
@@ -638,11 +665,23 @@ private extension ZendeskManager {
638665
/// Without it, the tickets won't appear in the correct view(s) in the web portal and they won't contain all the metadata needed to solve a ticket.
639666
///
640667
func createRequest(supportSourceTag: String?) -> RequestUiConfiguration {
668+
669+
var logsFieldID: Int64 = TicketFieldIDs.legacyLogs
670+
var systemStatusReportFieldID: Int64 = 0
671+
if isSSRFeatureFlagEnabled {
672+
/// If the feature flag is enabled, `legacyLogs` Field ID is used to send the SSR logs,
673+
/// and `logs` Field ID is used to send the logs.
674+
///
675+
logsFieldID = TicketFieldIDs.logs
676+
systemStatusReportFieldID = TicketFieldIDs.legacyLogs
677+
}
678+
641679
let ticketFields = [
642680
CustomField(fieldId: TicketFieldIDs.appVersion, value: Bundle.main.version),
643681
CustomField(fieldId: TicketFieldIDs.deviceFreeSpace, value: getDeviceFreeSpace()),
644682
CustomField(fieldId: TicketFieldIDs.networkInformation, value: getNetworkInformation()),
645-
CustomField(fieldId: TicketFieldIDs.logs, value: getLogFile()),
683+
CustomField(fieldId: logsFieldID, value: getLogFile()),
684+
CustomField(fieldId: systemStatusReportFieldID, value: systemStatusReport),
646685
CustomField(fieldId: TicketFieldIDs.currentSite, value: getCurrentSiteDescription()),
647686
CustomField(fieldId: TicketFieldIDs.sourcePlatform, value: Constants.sourcePlatform),
648687
CustomField(fieldId: TicketFieldIDs.appLanguage, value: Locale.preferredLanguage),
@@ -657,12 +696,23 @@ private extension ZendeskManager {
657696

658697
func createWCPayRequest(supportSourceTag: String?) -> RequestUiConfiguration {
659698

699+
var logsFieldID: Int64 = TicketFieldIDs.legacyLogs
700+
var systemStatusReportFieldID: Int64 = 0
701+
if isSSRFeatureFlagEnabled {
702+
/// If the feature flag is enabled, `legacyLogs` Field ID is used to send the SSR logs,
703+
/// and `logs` Field ID is used to send the logs.
704+
///
705+
logsFieldID = TicketFieldIDs.logs
706+
systemStatusReportFieldID = TicketFieldIDs.legacyLogs
707+
}
708+
660709
// Set form field values
661710
let ticketFields = [
662711
CustomField(fieldId: TicketFieldIDs.appVersion, value: Bundle.main.version),
663712
CustomField(fieldId: TicketFieldIDs.deviceFreeSpace, value: getDeviceFreeSpace()),
664713
CustomField(fieldId: TicketFieldIDs.networkInformation, value: getNetworkInformation()),
665-
CustomField(fieldId: TicketFieldIDs.logs, value: getLogFile()),
714+
CustomField(fieldId: logsFieldID, value: getLogFile()),
715+
CustomField(fieldId: systemStatusReportFieldID, value: systemStatusReport),
666716
CustomField(fieldId: TicketFieldIDs.currentSite, value: getCurrentSiteDescription()),
667717
CustomField(fieldId: TicketFieldIDs.sourcePlatform, value: Constants.sourcePlatform),
668718
CustomField(fieldId: TicketFieldIDs.appLanguage, value: Locale.preferredLanguage),
@@ -1087,7 +1137,8 @@ private extension ZendeskManager {
10871137
static let allBlogs: Int64 = 360000087183
10881138
static let deviceFreeSpace: Int64 = 360000089123
10891139
static let networkInformation: Int64 = 360000086966
1090-
static let logs: Int64 = 22871957
1140+
static let legacyLogs: Int64 = 22871957
1141+
static let logs: Int64 = 10901699622036
10911142
static let currentSite: Int64 = 360000103103
10921143
static let sourcePlatform: Int64 = 360009311651
10931144
static let appLanguage: Int64 = 360008583691

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewModel.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ final class SettingsViewModel: SettingsViewModelOutput, SettingsViewModelActions
110110
configuration: upsellCardReadersCampaign.configuration)
111111
}
112112

113+
/// Reference to the Zendesk shared instance
114+
///
115+
private let zendeskShared: ZendeskManagerProtocol = ZendeskProvider.shared
116+
113117
init(stores: StoresManager = ServiceLocator.stores,
114118
storageManager: StorageManagerType = ServiceLocator.storageManager,
115119
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService,
@@ -141,6 +145,11 @@ final class SettingsViewModel: SettingsViewModelOutput, SettingsViewModelActions
141145
let action = SystemStatusAction.synchronizeSystemPlugins(siteID: siteID, onCompletion: { _ in })
142146
stores.dispatch(action)
143147
}
148+
149+
/// Fetch System Status Report from Zendesk
150+
/// so it will be ready to be attached to a a support request when needed
151+
///
152+
zendeskShared.fetchSystemStatusReport()
144153
}
145154

146155
/// Sets up the view model and loads the settings.

WooCommerce/WooCommerceTests/Testing/MockZendeskManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ final class MockZendeskManager: ZendeskManagerProtocol {
7171
func observeStoreSwitch() {
7272
// no-op
7373
}
74+
75+
func fetchSystemStatusReport() {
76+
// no-op
77+
}
7478
}
7579

7680
extension MockZendeskManager: SupportManagerAdapter {

0 commit comments

Comments
 (0)