diff --git a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessor.swift b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessor.swift index c9f28b78f..a5a827ca1 100644 --- a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessor.swift +++ b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessor.swift @@ -103,11 +103,7 @@ final class AccountSecurityProcessor: StateProcessor< private func appeared() async { do { if let policy = try await services.policyService.fetchTimeoutPolicyValues() { - // If the policy returns no timeout action, we present the user all timeout actions. - // If the policy returns a timeout action, it's the only one we show the user. - if policy.action != nil { - state.policyTimeoutAction = policy.action - } + state.isTimeoutActionPolicyEnabled = policy.action != nil state.policyTimeoutValue = policy.value state.isTimeoutPolicyEnabled = true diff --git a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessorTests.swift b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessorTests.swift index 2c94a284d..0b914a8ae 100644 --- a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessorTests.swift +++ b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessorTests.swift @@ -83,10 +83,10 @@ class AccountSecurityProcessorTests: BitwardenTestCase { // swiftlint:disable:th await subject.perform(.appeared) - XCTAssertEqual(subject.state.isTimeoutPolicyEnabled, true) - XCTAssertEqual(subject.state.policyTimeoutAction, .logout) + XCTAssertTrue(subject.state.isTimeoutPolicyEnabled) + XCTAssertTrue(subject.state.isTimeoutActionPolicyEnabled) + XCTAssertTrue(subject.state.isSessionTimeoutActionDisabled) XCTAssertEqual(subject.state.policyTimeoutValue, 60) - XCTAssertEqual(subject.state.availableTimeoutActions, [.logout]) XCTAssertEqual(subject.state.policyTimeoutHours, 1) XCTAssertEqual(subject.state.policyTimeoutMinutes, 0) XCTAssertEqual( @@ -110,9 +110,10 @@ class AccountSecurityProcessorTests: BitwardenTestCase { // swiftlint:disable:th await subject.perform(.appeared) - XCTAssertEqual(subject.state.isTimeoutPolicyEnabled, true) + XCTAssertFalse(subject.state.isTimeoutActionPolicyEnabled) + XCTAssertTrue(subject.state.isTimeoutPolicyEnabled) + XCTAssertFalse(subject.state.isSessionTimeoutActionDisabled) XCTAssertEqual(subject.state.policyTimeoutValue, 61) - XCTAssertEqual(subject.state.availableTimeoutActions, [.lock, .logout]) XCTAssertEqual(subject.state.policyTimeoutHours, 1) XCTAssertEqual(subject.state.policyTimeoutMinutes, 1) XCTAssertEqual( diff --git a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityState.swift b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityState.swift index 1a93e7432..e93626c5c 100644 --- a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityState.swift +++ b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityState.swift @@ -177,22 +177,15 @@ struct AccountSecurityState: Equatable { /// Whether the user has a master password. var hasMasterPassword = true - /// Whether the maximum timeout value policy is in effect. - var isTimeoutPolicyEnabled: Bool = false + /// Whether the timeout policy specifies a timeout action. + var isTimeoutActionPolicyEnabled = false + + /// Whether the timeout policy is in effect. + var isTimeoutPolicyEnabled = false /// Whether the unlock with pin code toggle is on. var isUnlockWithPINCodeOn: Bool = false - /// The maximum vault timeout policy action. - /// - /// When set, this is the only action option available to users. - var policyTimeoutAction: SessionTimeoutAction? = .lock { - didSet { - availableTimeoutActions = SessionTimeoutAction.allCases - .filter { $0 == policyTimeoutAction } - } - } - /// The policy's maximum vault timeout value. /// /// When set, all timeout values greater than this are no longer shown. @@ -245,9 +238,9 @@ struct AccountSecurityState: Equatable { hasUnlockMethod } - /// Whether the session timeout row/picker should be disabled. - var isSessionTimeoutDisabled: Bool { - !hasUnlockMethod + /// Whether the session timeout action row/picker should be disabled. + var isSessionTimeoutActionDisabled: Bool { + !hasUnlockMethod || isTimeoutActionPolicyEnabled } /// Whether or not the custom session timeout field is shown. diff --git a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityView.swift b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityView.swift index fd4297d0e..ab60e4262 100644 --- a/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityView.swift +++ b/BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityView.swift @@ -168,7 +168,7 @@ struct AccountSecurityView: View { send: AccountSecurityAction.sessionTimeoutActionChanged ) ) - .disabled(store.state.isSessionTimeoutDisabled) + .disabled(store.state.isSessionTimeoutActionDisabled) } .clipShape(RoundedRectangle(cornerRadius: 10)) }