-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow activating subscription for internal users via debug menu (#3117)
Task/Issue URL: https://app.asana.com/0/72649045549333/1207811184536020/f Description: Add to debug menu option to start the subscription activation flow. This option is to allow access to the flow even when the purchase is disallowed in given region (App Store build for non-US user). Additional changes are renaming and cleanup of obsolete items in the "Subscription" debug menu.
- Loading branch information
Showing
7 changed files
with
122 additions
and
37 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
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
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
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
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
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 |
---|---|---|
|
@@ -35,27 +35,27 @@ import NetworkProtection | |
|
||
private let titles = [ | ||
Sections.authorization: "Authentication", | ||
Sections.subscription: "Subscription", | ||
Sections.api: "Make API Call", | ||
Sections.appstore: "App Store", | ||
Sections.environment: "Environment", | ||
] | ||
|
||
enum Sections: Int, CaseIterable { | ||
case authorization | ||
case subscription | ||
case api | ||
case appstore | ||
case environment | ||
} | ||
|
||
enum AuthorizationRows: Int, CaseIterable { | ||
case showAccountDetails | ||
case restoreSubscription | ||
case clearAuthData | ||
case injectCredentials | ||
case showAccountDetails | ||
} | ||
|
||
enum SubscriptionRows: Int, CaseIterable { | ||
case validateToken | ||
case getEntitlements | ||
case checkEntitlements | ||
case getSubscription | ||
} | ||
|
||
|
@@ -87,18 +87,29 @@ import NetworkProtection | |
|
||
case .authorization: | ||
switch AuthorizationRows(rawValue: indexPath.row) { | ||
case .restoreSubscription: | ||
cell.textLabel?.text = "I Have a Subscription" | ||
case .clearAuthData: | ||
cell.textLabel?.text = "Clear Authorization Data (Sign out)" | ||
cell.textLabel?.text = "Remove Subscription From This Device" | ||
case .showAccountDetails: | ||
cell.textLabel?.text = "Show Account Details" | ||
case .injectCredentials: | ||
cell.textLabel?.text = "Simulate Authentication (Inject Fake token)" | ||
case .none: | ||
break | ||
} | ||
|
||
case.none: | ||
break | ||
case .api: | ||
switch SubscriptionRows(rawValue: indexPath.row) { | ||
case .validateToken: | ||
cell.textLabel?.text = "Validate Token" | ||
case .checkEntitlements: | ||
cell.textLabel?.text = "Check Entitlements" | ||
case .getSubscription: | ||
cell.textLabel?.text = "Get Subscription Details" | ||
|
||
case .none: | ||
break | ||
} | ||
|
||
|
||
case .appstore: | ||
switch AppStoreRows(rawValue: indexPath.row) { | ||
|
@@ -107,18 +118,6 @@ import NetworkProtection | |
case .none: | ||
break | ||
} | ||
|
||
case .subscription: | ||
switch SubscriptionRows(rawValue: indexPath.row) { | ||
case .validateToken: | ||
cell.textLabel?.text = "Validate Token" | ||
case .getSubscription: | ||
cell.textLabel?.text = "Get subscription details" | ||
case .getEntitlements: | ||
cell.textLabel?.text = "Get Entitlements" | ||
case .none: | ||
break | ||
} | ||
|
||
case .environment: | ||
let currentEnv = subscriptionManager.currentEnvironment.serviceEnvironment | ||
|
@@ -132,14 +131,18 @@ import NetworkProtection | |
case .none: | ||
break | ||
} | ||
|
||
case.none: | ||
break | ||
} | ||
|
||
return cell | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
switch Sections(rawValue: section) { | ||
case .authorization: return AuthorizationRows.allCases.count | ||
case .subscription: return SubscriptionRows.allCases.count | ||
case .api: return SubscriptionRows.allCases.count | ||
case .appstore: return AppStoreRows.allCases.count | ||
case .environment: return EnvironmentRows.allCases.count | ||
case .none: return 0 | ||
|
@@ -151,21 +154,21 @@ import NetworkProtection | |
switch Sections(rawValue: indexPath.section) { | ||
case .authorization: | ||
switch AuthorizationRows(rawValue: indexPath.row) { | ||
case .restoreSubscription: openSubscriptionRestoreFlow() | ||
case .clearAuthData: clearAuthData() | ||
case .showAccountDetails: showAccountDetails() | ||
case .injectCredentials: injectCredentials() | ||
default: break | ||
} | ||
case .appstore: | ||
switch AppStoreRows(rawValue: indexPath.row) { | ||
case .syncAppStoreAccount: syncAppleIDAccount() | ||
default: break | ||
} | ||
case .subscription: | ||
case .api: | ||
switch SubscriptionRows(rawValue: indexPath.row) { | ||
case .validateToken: validateToken() | ||
case .getSubscription: getSubscription() | ||
case .getEntitlements: getEntitlements() | ||
case .checkEntitlements: checkEntitlements() | ||
case .getSubscription: getSubscriptionDetails() | ||
default: break | ||
} | ||
case .environment: | ||
|
@@ -221,18 +224,30 @@ import NetworkProtection | |
// func showAlert(title: String, message: String, alternativeAction) | ||
|
||
// MARK: Account Status Actions | ||
|
||
private func openSubscriptionRestoreFlow() { | ||
guard let mainVC = view.window?.rootViewController as? MainViewController else { return } | ||
|
||
|
||
if let navigationController = mainVC.presentedViewController as? UINavigationController { | ||
|
||
navigationController.popToRootViewController { | ||
if navigationController.viewControllers.first is SettingsHostingController { | ||
mainVC.segueToSubscriptionRestoreFlow() | ||
} else { | ||
navigationController.dismiss(animated: true, completion: { | ||
mainVC.segueToSubscriptionRestoreFlow() | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func clearAuthData() { | ||
subscriptionManager.accountManager.signOut() | ||
showAlert(title: "Data cleared!") | ||
} | ||
|
||
private func injectCredentials() { | ||
subscriptionManager.accountManager.storeAccount(token: "a-fake-token", | ||
email: "[email protected]", | ||
externalID: "666") | ||
showAccountDetails() | ||
} | ||
|
||
private func showAccountDetails() { | ||
let title = subscriptionManager.accountManager.isUserAuthenticated ? "Authenticated" : "Not Authenticated" | ||
let message = subscriptionManager.accountManager.isUserAuthenticated ? | ||
|
@@ -271,7 +286,7 @@ import NetworkProtection | |
} | ||
} | ||
|
||
private func getSubscription() { | ||
private func getSubscriptionDetails() { | ||
Task { | ||
guard let token = subscriptionManager.accountManager.accessToken else { | ||
showAlert(title: "Not authenticated", message: "No authenticated user found! - Subscription not available") | ||
|
@@ -287,7 +302,7 @@ import NetworkProtection | |
} | ||
} | ||
|
||
private func getEntitlements() { | ||
private func checkEntitlements() { | ||
Task { | ||
var results: [String] = [] | ||
guard subscriptionManager.accountManager.accessToken != nil else { | ||
|
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// UINavigationControllerExtension.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UINavigationController { | ||
|
||
func popToRootViewController(animated: Bool = true, completion: @escaping () -> Void) { | ||
CATransaction.begin() | ||
CATransaction.setCompletionBlock(completion) | ||
self.popToRootViewController(animated: animated) | ||
CATransaction.commit() | ||
} | ||
|
||
func popViewControllerWithHandler(animated: Bool = true, completion: @escaping () -> Void) { | ||
CATransaction.begin() | ||
CATransaction.setCompletionBlock(completion) | ||
self.popViewController(animated: animated) | ||
CATransaction.commit() | ||
} | ||
|
||
func pushViewController(viewController: UIViewController, animated: Bool = true, completion: @escaping () -> Void) { | ||
CATransaction.begin() | ||
CATransaction.setCompletionBlock(completion) | ||
self.pushViewController(viewController, animated: animated) | ||
CATransaction.commit() | ||
} | ||
|
||
} |