Skip to content
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
3 changes: 3 additions & 0 deletions apple/TablePro/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -32994,6 +32994,9 @@
"Ask the SSH server's administrator to turn on a method TablePro supports." : {
"extractionState" : "manual",
"generatesSymbol" : false
},
"Ask your administrator about a feature your organization's license does not include." : {

},
"Ask your administrator about it." : {

Expand Down
29 changes: 19 additions & 10 deletions apple/TablePro/Views/Components/LicenseNoticeControls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,34 @@ internal enum LicenseGateAlert {
static func present(for feature: ProFeature, in window: NSWindow?, access: FeatureAccess = .shared) {
guard let notice = LicensePresentation.gate(for: feature, state: access.state) else { return }
Telemetry.shared.featureGateShown(feature, access: access.check(feature))
let actions = [notice.action, notice.alternative].compactMap { $0 }
// A state with no way out of its own opens the pane that explains it.
guard !actions.isEmpty else {
WindowOpener.shared.openSettings(tab: .account)
return
let actions = Self.actions(for: notice)
AlertHelper.present(makeAlert(for: notice), in: window) { response in
let index = response.rawValue - NSApplication.ModalResponse.alertFirstButtonReturn.rawValue
guard actions.indices.contains(index) else { return }
actions[index].perform(referrer: .featureGate(feature))
}
}

static func actions(for notice: LicenseNotice) -> [LicenseNoticeAction] {
[notice.action, notice.alternative].compactMap { $0 }
}

// A notice with no way out, such as a feature a company's license leaves out, still says why: the Account pane
// never explains it, so opening it instead left the person with no reason.
static func makeAlert(for notice: LicenseNotice) -> NSAlert {
let alert = NSAlert()
alert.alertStyle = .informational
alert.messageText = notice.title
alert.informativeText = notice.message
let actions = Self.actions(for: notice)
guard !actions.isEmpty else {
alert.addButton(withTitle: String(localized: "OK"))
return alert
}
for action in actions {
alert.addButton(withTitle: action.title)
}
AlertHelper.addCancelButton(to: alert, title: String(localized: "Cancel"))
AlertHelper.present(alert, in: window) { response in
let index = response.rawValue - NSApplication.ModalResponse.alertFirstButtonReturn.rawValue
guard actions.indices.contains(index) else { return }
actions[index].perform(referrer: .featureGate(feature))
}
return alert
}
}
28 changes: 17 additions & 11 deletions apple/TablePro/Views/Settings/Account/AccountFeaturesSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ internal struct AccountFeaturesPage: View {
Form {
Section {
ForEach(ProFeature.allCases, id: \.self) { feature in
AccountFeatureRow(feature: feature, isIncluded: access.isAvailable(feature))
AccountFeatureRow(feature: feature, gate: LicensePresentation.gate(for: feature, state: access.state))
}
} footer: {
if let footnote = LicensePresentation.featuresFootnote(state: access.state) {
Text(footnote)
}
}

Expand Down Expand Up @@ -48,7 +52,8 @@ internal struct AccountFeaturesPage: View {

private struct AccountFeatureRow: View {
let feature: ProFeature
let isIncluded: Bool
// nil when the feature is included; otherwise what its gate says, so a company's license never reads as a plan to buy.
let gate: LicenseNotice?

var body: some View {
HStack(spacing: 10) {
Expand All @@ -68,24 +73,25 @@ private struct AccountFeatureRow: View {

Spacer(minLength: 12)

if isIncluded {
if let gate {
Label {
Text("Included")
.foregroundStyle(.secondary)
Text("Not included")
} icon: {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.green)
Image(systemName: "lock.fill")
}
.foregroundStyle(.secondary)
.fixedSize()
.help(gate.title)
.accessibilityLabel(Text(gate.title))
} else {
Label {
Text("Not included")
Text("Included")
.foregroundStyle(.secondary)
} icon: {
Image(systemName: "lock.fill")
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.green)
}
.foregroundStyle(.secondary)
.fixedSize()
.accessibilityLabel(Text(feature.paidPlanRequirement))
}
}
.accessibilityElement(children: .combine)
Expand Down
28 changes: 20 additions & 8 deletions apple/TablePro/Views/Settings/Account/LicensePresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,7 @@ internal enum LicensePresentation {
action: .openAccountSettings(page: .accountDevices)
)
}
guard sellsPlans else {
return LicenseNotice(
title: String(format: String(localized: "%@ is not part of your organization's license"), feature.displayName),
message: String(localized: "Ask your administrator about it."),
action: nil
)
}
return LicenseNotice(title: feature.paidPlanRequirement, message: feature.featureDescription, action: .upgrade)
return notIncluded(feature, sellsPlans: sellsPlans)
// The core reads a failed refresh first; an entitlement that carried the feature has lapsed either way.
case .expired, .refreshFailed:
if let entitlement = state.entitlement, entitlement.features.contains(feature.rawValue) {
Expand All @@ -78,6 +71,25 @@ internal enum LicensePresentation {
}
}

static func notIncluded(_ feature: ProFeature, sellsPlans: Bool) -> LicenseNotice {
guard sellsPlans else {
return LicenseNotice(
title: String(format: String(localized: "%@ is not part of your organization's license"), feature.displayName),
message: String(localized: "Ask your administrator about it."),
action: nil
)
}
return LicenseNotice(title: feature.paidPlanRequirement, message: feature.featureDescription, action: .upgrade)
}

// The Features page names the reason per row; who to ask is the same for every row a company's license leaves out.
static func featuresFootnote(state: AccountState) -> String? {
guard !state.server.isProduction,
ProFeature.allCases.contains(where: { gate(for: $0, state: state) == notIncluded($0, sellsPlans: false) })
else { return nil }
return String(localized: "Ask your administrator about a feature your organization's license does not include.")
}

// The pane's first notice, then Sign In for a Mac with no account. A canceling plan stays in the pane: the person
// chose it, and the pane shows the date it ends.
static func welcomeLine(state: AccountState, now: Date) -> LicenseNotice? {
Expand Down
59 changes: 59 additions & 0 deletions apple/TableProTests/Views/Settings/LicensePresentationTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AppKit
import Foundation
@testable import TablePro
import Testing
Expand Down Expand Up @@ -152,6 +153,64 @@ struct LicensePresentationTests {
#expect(without?.title != ProFeature.teamLibrary.paidPlanRequirement)
}

private static let companyWithoutFeatures = AccountState(
isSignedIn: true, entitlement: Self.entitlement(features: [], licenses: []), server: AccountSettingsContentTests.companyServer
)
private static let personalFree = AccountState(isSignedIn: true, entitlement: Self.entitlement(features: [], licenses: []))

@Test("A company license without a feature names the organization, and the Features page says who to ask")
func companyLicenseWithoutTheFeature() throws {
let state = AccountSettingsContentTests.withCoreGate(Self.companyWithoutFeatures)
let gate = try #require(LicensePresentation.gate(for: .iCloudSync, state: state))

#expect(gate.title == String(format: String(localized: "%@ is not part of your organization's license"), ProFeature.iCloudSync.displayName))
#expect(gate.message == String(localized: "Ask your administrator about it."))
#expect(LicensePresentation.featuresFootnote(state: state) != nil)
}

@Test("A personal free plan keeps the paid-plan wording, with no footnote about an administrator")
func personalFreePlan() throws {
let state = AccountSettingsContentTests.withCoreGate(Self.personalFree)
let gate = try #require(LicensePresentation.gate(for: .iCloudSync, state: state))

#expect(gate.title == ProFeature.iCloudSync.paidPlanRequirement)
#expect(LicensePresentation.featuresFootnote(state: state) == nil)
}

@Test("A company license that includes every feature has nothing to explain on the Features page")
func companyLicenseWithEveryFeature() {
let state = AccountSettingsContentTests.withCoreGate(AccountState(
isSignedIn: true, entitlement: Self.entitlement(), server: AccountSettingsContentTests.companyServer
))
#expect(LicensePresentation.featuresFootnote(state: state) == nil)
}

@MainActor
@Test("A gate with no way out still shows its reason, with OK alone")
func gateAlertWithoutAction() throws {
let gate = try #require(Self.gate(.iCloudSync, Self.companyWithoutFeatures))
let alert = LicenseGateAlert.makeAlert(for: gate)

let buttons = alert.buttons.map { $0.title }

#expect(LicenseGateAlert.actions(for: gate).isEmpty)
#expect(alert.messageText == gate.title)
#expect(alert.informativeText == gate.message)
#expect(buttons == [String(localized: "OK")])
}

@MainActor
@Test("A gate with a way out offers it, with Cancel beside it")
func gateAlertWithAction() throws {
let gate = try #require(Self.gate(.iCloudSync, Self.personalFree))
let alert = LicenseGateAlert.makeAlert(for: gate)

let buttons = alert.buttons.map { $0.title }

#expect(LicenseGateAlert.actions(for: gate) == [.upgrade])
#expect(buttons == [LicenseNoticeAction.upgrade.title, String(localized: "Cancel")])
}

@Test("Welcome offers sign-in to a Mac with no account")
func welcomeOffersSignIn() {
#expect(Self.welcomeLine(AccountState())?.action == .signIn)
Expand Down
1 change: 1 addition & 0 deletions apple/changelog.d/4694.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Choosing a feature your organization's license does not include opened Account settings without saying why.
Loading