Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append "+testing" to feedback form email for Automatticians #23804

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions WordPress/Classes/Utility/ZendeskUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ protocol ZendeskUtilsProtocol {
/// as well as displaying views for the Help Center, new tickets, and ticket list.
///
@objc class ZendeskUtils: NSObject, ZendeskUtilsProtocol {

// MARK: - Public Properties

static var sharedInstance: ZendeskUtils = ZendeskUtils(contextManager: ContextManager.shared)
Expand All @@ -63,7 +62,15 @@ protocol ZendeskUtilsProtocol {
private var sourceTag: WordPressSupportSourceTag?

private var userName: String?
private var userEmail: String?
private var userEmail: String? {
set {
_userEmail = newValue.map(ZendeskUtils.a8cTestEmail(_:))
}
get {
_userEmail
}
}
private var _userEmail: String?
private var userNameConfirmed = false

private var deviceID: String?
Expand Down Expand Up @@ -1201,3 +1208,26 @@ extension ZendeskUtils {
}
}
}

extension ZendeskUtils {
static var automatticEmails = ["@automattic.com", "@a8c.com"]

/// Insert "+testing" to Automattic email address.
/// - SeeAlso: https://github.com/wordpress-mobile/WordPress-iOS/issues/23794
static func a8cTestEmail(_ email: String) -> String {
guard let suffix = ZendeskUtils.automatticEmails.first(where: { email.lowercased().hasSuffix($0) }) else {
return email
}

let atSymbolIndex = email.index(email.endIndex, offsetBy: -suffix.count)

// Do nothing if the email is already an "alias email".
if email[email.startIndex..<atSymbolIndex].contains("+") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return email
}

var newEmail = email
newEmail.insert(contentsOf: "+testing", at: atSymbolIndex)
return newEmail
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private extension SupportTableViewController {
///
func checkForAutomatticEmail() {
guard let email = ZendeskUtils.userSupportEmail(),
(Constants.automatticEmails.first { email.contains($0) }) != nil else {
(ZendeskUtils.automatticEmails.first { email.contains($0) }) != nil else {
return
}

Expand Down Expand Up @@ -526,7 +526,6 @@ private extension SupportTableViewController {
static let jetpackMigrationFAQURL = URL(string: "https://jetpack.com/support/switch-to-the-jetpack-app/")

static let forumsURL = URL(string: "https://wordpress.org/support/forum/mobile/")
static let automatticEmails = ["@automattic.com", "@a8c.com"]
}
}

Expand Down
4 changes: 4 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
4A2C73E42A943DEA00ACE79E /* TaggedManagedObjectIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2C73E32A943DEA00ACE79E /* TaggedManagedObjectIDTests.swift */; };
4A2C73F72A9585B000ACE79E /* PostRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2C73F62A9585B000ACE79E /* PostRepositoryTests.swift */; };
4A5598852B05AC180083C220 /* PagesListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A5598842B05AC180083C220 /* PagesListTests.swift */; };
4A5EDD812CE58B9900A605FC /* ZendeskUtilsTests+A8CEmail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A5EDD802CE58B9900A605FC /* ZendeskUtilsTests+A8CEmail.swift */; };
4A690C152BA791B100A8E0C5 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4A690C142BA790BC00A8E0C5 /* PrivacyInfo.xcprivacy */; };
4A690C162BA791B200A8E0C5 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4A690C142BA790BC00A8E0C5 /* PrivacyInfo.xcprivacy */; };
4A690C182BA794C800A8E0C5 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4A690C172BA794C300A8E0C5 /* PrivacyInfo.xcprivacy */; };
Expand Down Expand Up @@ -2329,6 +2330,7 @@
4A2C73F62A9585B000ACE79E /* PostRepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostRepositoryTests.swift; sourceTree = "<group>"; };
4A2F746A2C2198CB00E72117 /* WordPressAuthenticatorTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WordPressAuthenticatorTests.xcconfig; sourceTree = "<group>"; };
4A5598842B05AC180083C220 /* PagesListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagesListTests.swift; sourceTree = "<group>"; };
4A5EDD802CE58B9900A605FC /* ZendeskUtilsTests+A8CEmail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ZendeskUtilsTests+A8CEmail.swift"; sourceTree = "<group>"; };
4A690C142BA790BC00A8E0C5 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4A690C172BA794C300A8E0C5 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4A690C1A2BA7958F00A8E0C5 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4733,6 +4735,7 @@
isa = PBXGroup;
children = (
3F751D452491A93D0008A2B1 /* ZendeskUtilsTests+Plans.swift */,
4A5EDD802CE58B9900A605FC /* ZendeskUtilsTests+A8CEmail.swift */,
);
name = Zendesk;
sourceTree = "<group>";
Expand Down Expand Up @@ -10085,6 +10088,7 @@
D81C2F6620F8ACCD002AE1F1 /* FormattableContentFormatterTests.swift in Sources */,
08AA640C2A8511FB0076E38D /* DashboardGoogleDomainsViewModelTests.swift in Sources */,
83EF3D7F2937F08C000AF9BF /* SharedDataIssueSolverTests.swift in Sources */,
4A5EDD812CE58B9900A605FC /* ZendeskUtilsTests+A8CEmail.swift in Sources */,
8070EB3E28D807CB005C6513 /* InMemoryUserDefaults.swift in Sources */,
F93735F822D53C3B00A3C312 /* LoggingURLRedactorTests.swift in Sources */,
C738CB1128626606001BE107 /* QRLoginVerifyCoordinatorTests.swift in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions WordPress/WordPressTest/ZendeskUtilsTests+A8CEmail.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation
import Testing

@testable import WordPress

@Suite
struct ZendeskUtilsA8CEmailTests {

@Test(
arguments: [
("[email protected]", "[email protected]"),
("[email protected]", "[email protected]"),
("[email protected]", "[email protected]"),
("[email protected]", "[email protected]"),
]
)
func insertTesting(email: String, expected: String) {
let result = ZendeskUtils.a8cTestEmail(email)
#expect(result == expected)
}

@Test(
arguments: [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
)
func keepOriginalEmail(email: String) {
let result = ZendeskUtils.a8cTestEmail(email)
#expect(result == email)
}

}