Skip to content

Commit

Permalink
BIT-2359: Disable session timeout action picker when policy is enabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-livefront authored Jun 13, 2024
1 parent 8cba062 commit 574e1d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct AccountSecurityView: View {
send: AccountSecurityAction.sessionTimeoutActionChanged
)
)
.disabled(store.state.isSessionTimeoutDisabled)
.disabled(store.state.isSessionTimeoutActionDisabled)
}
.clipShape(RoundedRectangle(cornerRadius: 10))
}
Expand Down

0 comments on commit 574e1d3

Please sign in to comment.