Skip to content

Commit 4a4023d

Browse files
authored
Show information about application passwords when enabling the feature toggle (#24684)
* Show information about application passwords when enabling the feature toggle * Fix a compiling issue
1 parent 513153a commit 4a4023d

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Foundation
2+
import SwiftUI
3+
import DesignSystem
4+
5+
struct ApplicationPasswordsInfoView: View {
6+
@Environment(\.dismiss) private var dismiss
7+
8+
var body: some View {
9+
VStack(alignment: .leading, spacing: 16) {
10+
Text(Strings.allInfo)
11+
.font(.body)
12+
13+
Spacer()
14+
15+
DSButton(
16+
title: Strings.gotItButton,
17+
style: DSButtonStyle(emphasis: .primary, size: .large)
18+
) {
19+
dismiss()
20+
}
21+
}
22+
.padding()
23+
.navigationTitle(Strings.title)
24+
.navigationBarTitleDisplayMode(.inline)
25+
}
26+
}
27+
28+
private enum Strings {
29+
static let title = NSLocalizedString(
30+
"applicationPassword.info.title",
31+
value: "About Application Passwords",
32+
comment: "Title for the application passwords information view"
33+
)
34+
35+
static let allInfo = NSLocalizedString(
36+
"applicationPassword.info.content",
37+
value: "Application passwords are a more secure way for this app to access your site content without using your actual account password.\n\nWhen you add sites to the app, application passwords will be created automatically as needed.\n\nYou can view and manage these passwords in your user profile within your WordPress site's admin panel.\n\nPlease note that revoking application passwords used by the app will terminate the app's access to your site. Be cautious when revoking application passwords created by the app.",
38+
comment: "Complete information about application passwords with security benefits, creation process, management instructions, and revocation warning"
39+
)
40+
41+
static let gotItButton = NSLocalizedString(
42+
"applicationPassword.info.gotIt.button",
43+
value: "Got it",
44+
comment: "Button to dismiss the application password information view"
45+
)
46+
}

WordPress/Classes/System/Root View/WordPressAuthenticatorProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension WordPressAuthenticator: WordPressAuthenticatorProtocol {
4747
}
4848

4949
private static func selfHostedSiteLogin(_ viewController: UIViewController) -> Bool {
50-
guard FeatureFlag.authenticateUsingApplicationPassword.enabled else { return false }
50+
guard FeatureFlag.allowApplicationPasswords.enabled else { return false }
5151
guard let navigationController = viewController.navigationController else { return false }
5252

5353
let view = LoginWithUrlView(presenter: viewController) { [weak viewController] blogID in

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum FeatureFlag: Int, CaseIterable {
1919
case compliancePopover
2020
case googleDomainsCard
2121
case voiceToContent
22-
case authenticateUsingApplicationPassword
22+
case allowApplicationPasswords
2323
case newGutenbergThemeStyles
2424
case selfHostedSiteUserManagement
2525
case readerGutenbergCommentComposer
@@ -68,7 +68,7 @@ public enum FeatureFlag: Int, CaseIterable {
6868
return false
6969
case .voiceToContent:
7070
return app == .jetpack && BuildConfiguration.current.isInternal
71-
case .authenticateUsingApplicationPassword:
71+
case .allowApplicationPasswords:
7272
return false
7373
case .newGutenbergThemeStyles:
7474
return false
@@ -118,7 +118,7 @@ extension FeatureFlag {
118118
case .compliancePopover: "Compliance Popover"
119119
case .googleDomainsCard: "Google Domains Promotional Card"
120120
case .voiceToContent: "Voice to Content"
121-
case .authenticateUsingApplicationPassword: "Application Passwords for self-hosted sites"
121+
case .allowApplicationPasswords: "Allow creating Application Passwords"
122122
case .newGutenbergThemeStyles: "Experimental Block Editor Styles"
123123
case .selfHostedSiteUserManagement: "Self-hosted Site User Management"
124124
case .pluginManagementOverhaul: "Plugin Management Overhaul"
@@ -136,7 +136,16 @@ extension FeatureFlag: OverridableFlag {
136136
}
137137

138138
var key: String {
139-
return "ff-override-\(String(describing: self))"
139+
let key: String
140+
switch self {
141+
case .allowApplicationPasswords:
142+
// This feature toggle description is already shipped and used in the production.
143+
// We want to keep using the same key, but change the description.
144+
key = "Application Passwords for self-hosted sites"
145+
default:
146+
key = String(describing: self)
147+
}
148+
return "ff-override-\(key)"
140149
}
141150
}
142151

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ extension BlogDetailsViewController {
351351
}
352352

353353
@objc public func checkApplicationPasswordEligibility() {
354-
guard FeatureFlag.authenticateUsingApplicationPassword.enabled else { return }
354+
guard FeatureFlag.allowApplicationPasswords.enabled else { return }
355355

356356
// We have already got an application token for this site, no need to ask for another one.
357357
guard (try? blog.getApplicationToken()) == nil, let url = blog.url else { return }

WordPress/Classes/ViewRelated/Blog/Site Picker/AddSiteController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct AddSiteController {
3333
}
3434

3535
func showSelfHostedSiteLoginScreen() {
36-
guard FeatureFlag.authenticateUsingApplicationPassword.enabled else {
36+
guard FeatureFlag.allowApplicationPasswords.enabled else {
3737
WordPressAuthenticator.showLoginForSelfHostedSite(viewController)
3838
return
3939
}

WordPress/Classes/ViewRelated/Me/App Settings/ExperimentalFeaturesDataProvider.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Foundation
22
import WordPressUI
33
import UIKit
4+
import SwiftUI
45

56
class ExperimentalFeaturesDataProvider: ExperimentalFeaturesViewModel.DataProvider {
67

78
let flags: [OverridableFlag] = [
8-
FeatureFlag.authenticateUsingApplicationPassword,
9+
FeatureFlag.allowApplicationPasswords,
910
RemoteFeatureFlag.newGutenberg,
1011
FeatureFlag.newGutenbergThemeStyles,
1112
]
@@ -42,6 +43,16 @@ class ExperimentalFeaturesDataProvider: ExperimentalFeaturesViewModel.DataProvid
4243
}))
4344

4445
self.presentViewController(alert)
46+
47+
return
48+
}
49+
50+
if feature.key == FeatureFlag.allowApplicationPasswords.key && newValue {
51+
let view = NavigationStack {
52+
ApplicationPasswordsInfoView()
53+
}
54+
self.presentViewController(UIHostingController(rootView: view))
55+
return
4556
}
4657
}
4758

0 commit comments

Comments
 (0)