Skip to content

Commit

Permalink
Jetpack Setup: Fix issue removing application password (#14929)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo authored Jan 24, 2025
2 parents 65a7b39 + aa05cb4 commit ab53700
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [*] 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].
- [*] Order Creation: orders are always created using the store's currency, not the user's [https://github.com/woocommerce/woocommerce-ios/pull/14907]
- [*] 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]
Expand Down
4 changes: 2 additions & 2 deletions WooCommerce/Classes/System/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ 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<Site, Error>) -> Void = { [weak self] result in
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)
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ final class MockSessionManager: SessionManagerProtocol {
// Do nothing
}

func deleteApplicationPassword(using credentials: Credentials?) {
deleteApplicationPasswordInvoked = true
}

func deleteApplicationPassword() {
deleteApplicationPasswordInvoked = true
}
Expand Down
10 changes: 9 additions & 1 deletion Yosemite/Yosemite/Base/SessionManagerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Model/Mocks/MockSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct MockSessionManager: SessionManagerProtocol {
// Do nothing
}

public func deleteApplicationPassword() {
public func deleteApplicationPassword(using credentials: Credentials?) {
// Do nothing
}
}

0 comments on commit ab53700

Please sign in to comment.