From 88bdaa2ce8a2857f5109a4cb3ef7f725fcf5aed9 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 21 Jan 2025 11:22:08 +0700 Subject: [PATCH 1/6] Update SessionManager to accept credentials as input --- WooCommerce/Classes/System/SessionManager.swift | 4 ++-- Yosemite/Yosemite/Base/SessionManagerProtocol.swift | 10 +++++++++- Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/WooCommerce/Classes/System/SessionManager.swift b/WooCommerce/Classes/System/SessionManager.swift index 29e786728d9..ee9403da812 100644 --- a/WooCommerce/Classes/System/SessionManager.swift +++ b/WooCommerce/Classes/System/SessionManager.swift @@ -219,9 +219,9 @@ final class SessionManager: SessionManagerProtocol { /// Deletes application password /// - func deleteApplicationPassword() { + func deleteApplicationPassword(using credentials: Credentials?) { let useCase: ApplicationPasswordUseCase? = { - switch loadCredentials() { + switch credentials ?? loadCredentials() { case let .wporg(username, password, siteAddress): return try? DefaultApplicationPasswordUseCase(username: username, password: password, diff --git a/Yosemite/Yosemite/Base/SessionManagerProtocol.swift b/Yosemite/Yosemite/Base/SessionManagerProtocol.swift index d8881ba7b39..20560e3f597 100644 --- a/Yosemite/Yosemite/Base/SessionManagerProtocol.swift +++ b/Yosemite/Yosemite/Base/SessionManagerProtocol.swift @@ -51,5 +51,13 @@ public protocol SessionManagerProtocol { /// Deletes application password /// - func deleteApplicationPassword() + func deleteApplicationPassword(using credentials: Credentials?) +} + +/// Helper methods +public extension SessionManagerProtocol { + /// Let the session manager figure out the credentials by itself + func deleteApplicationPassword() { + deleteApplicationPassword(using: nil) + } } diff --git a/Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift b/Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift index 98b4c34d5fe..833e34fd7bc 100644 --- a/Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift +++ b/Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift @@ -43,7 +43,7 @@ public struct MockSessionManager: SessionManagerProtocol { // Do nothing } - public func deleteApplicationPassword() { + public func deleteApplicationPassword(using credentials: Credentials?) { // Do nothing } } From a46b24c0ee7fc142060b1c41b452bf24c28ed5bb Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 21 Jan 2025 11:22:28 +0700 Subject: [PATCH 2/6] Delete application password using previous credentials after Jetpack setup --- .../ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift index 044648c2546..3e6f43eba3d 100644 --- a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift @@ -261,7 +261,7 @@ private extension JetpackSetupCoordinator { guard let self else { return } switch result { case .success(let site): - self.stores.sessionManager.deleteApplicationPassword() + self.stores.sessionManager.deleteApplicationPassword(using: previousCredentials) self.stores.updateDefaultStore(storeID: site.siteID) self.stores.synchronizeEntities { [weak self] in self?.stores.updateDefaultStore(site) From ed36716d4fd93a48f4a3c58a33537e7c629386a4 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Thu, 23 Jan 2025 23:20:46 +0700 Subject: [PATCH 3/6] Check for Jetpack plugin before authenticating user --- .../ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift index 3e6f43eba3d..70e7485a6dc 100644 --- a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift @@ -222,7 +222,7 @@ private extension JetpackSetupCoordinator { /// WPCom credentials to authenticate the user in the Jetpack connection web view automatically let credentials: Credentials = .wpcom(username: username, authToken: authToken, siteAddress: site.url) - guard jetpackConnectedEmail == nil else { + guard jetpackConnectedEmail == nil || !site.isJetpackThePluginInstalled else { // authenticate user immediately return authenticateUserAndRefreshSite(with: credentials) } From 5b43549205190353075495526dbdbd70cc6fc5d1 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 24 Jan 2025 09:05:02 +0700 Subject: [PATCH 4/6] Switch to me/sites to check for site connection of JCP sites --- .../JetpackSetup/JetpackSetupCoordinator.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift index 70e7485a6dc..41437f29855 100644 --- a/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/JetpackSetup/JetpackSetupCoordinator.swift @@ -222,7 +222,7 @@ private extension JetpackSetupCoordinator { /// WPCom credentials to authenticate the user in the Jetpack connection web view automatically let credentials: Credentials = .wpcom(username: username, authToken: authToken, siteAddress: site.url) - guard jetpackConnectedEmail == nil || !site.isJetpackThePluginInstalled else { + guard jetpackConnectedEmail == nil else { // authenticate user immediately return authenticateUserAndRefreshSite(with: credentials) } @@ -257,7 +257,7 @@ private extension JetpackSetupCoordinator { let progressView = InProgressViewController(viewProperties: .init(title: Localization.syncingData, message: "")) rootViewController.topmostPresentedViewController.present(progressView, animated: true) - let action = SiteAction.syncSiteByDomain(domain: site.url.trimHTTPScheme()) { [weak self] result in + let resultHandler: (Result) -> Void = { [weak self] result in guard let self else { return } switch result { case .success(let site): @@ -289,7 +289,12 @@ private extension JetpackSetupCoordinator { } } - stores.dispatch(action) + + if site.isJetpackCPConnected { + stores.dispatch(AccountAction.synchronizeSitesAndReturnSelectedSiteInfo(siteAddress: site.url, onCompletion: resultHandler)) + } else { + stores.dispatch(SiteAction.syncSiteByDomain(domain: site.url.trimHTTPScheme(), completion: resultHandler)) + } } func registerForPushNotifications() { From 00170602dcab45205ee452918c89cbab6f01d9c0 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 24 Jan 2025 10:05:52 +0700 Subject: [PATCH 5/6] Add missing protocol conformance --- .../WooCommerceTests/Yosemite/StoresManagerTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift b/WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift index 4c0cdebdad8..80682444bc8 100644 --- a/WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift +++ b/WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift @@ -535,6 +535,10 @@ final class MockSessionManager: SessionManagerProtocol { // Do nothing } + func deleteApplicationPassword(using credentials: Credentials?) { + deleteApplicationPasswordInvoked = true + } + func deleteApplicationPassword() { deleteApplicationPasswordInvoked = true } From aa05cb4cca50dae699ef54c4c11f9c1c44c32bc1 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 24 Jan 2025 10:07:44 +0700 Subject: [PATCH 6/6] Update release notes --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 89521f4eebd..cf6d669c8f7 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -5,6 +5,7 @@ - [Internal] [*] Improved handling of the navigation to the Woo Installation screen post Jetpack setup [https://github.com/woocommerce/woocommerce-ios/pull/14837] - [*] Receipts: Email receipts can now be sent to customers after failed payments using WooCommerce Stripe 9.1.0+. [https://github.com/woocommerce/woocommerce-ios/pull/14864]. - [*] Dashboard: Updated the drag gesture on the Performance chart to show stats instantly. [https://github.com/woocommerce/woocommerce-ios/pull/14906] +- [*] Jetpack Setup: Fix issue setting up Jetpack for JCP sites when authenticated without WPCom and removing application password after completion [https://github.com/woocommerce/woocommerce-ios/pull/14929] - [Internal] Removed feedback survey for Store Setup feature [https://github.com/woocommerce/woocommerce-ios/pull/14888] - [Internal] Removed feedback survey for shipping label creation [https://github.com/woocommerce/woocommerce-ios/pull/14889] - [Internal] Removed feedback survey for product creation AI [https://github.com/woocommerce/woocommerce-ios/pull/14890]