Skip to content

Commit 574e1d3

Browse files
BIT-2359: Disable session timeout action picker when policy is enabled (#671)
1 parent 8cba062 commit 574e1d3

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessor.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ final class AccountSecurityProcessor: StateProcessor<
103103
private func appeared() async {
104104
do {
105105
if let policy = try await services.policyService.fetchTimeoutPolicyValues() {
106-
// If the policy returns no timeout action, we present the user all timeout actions.
107-
// If the policy returns a timeout action, it's the only one we show the user.
108-
if policy.action != nil {
109-
state.policyTimeoutAction = policy.action
110-
}
106+
state.isTimeoutActionPolicyEnabled = policy.action != nil
111107

112108
state.policyTimeoutValue = policy.value
113109
state.isTimeoutPolicyEnabled = true

BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityProcessorTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class AccountSecurityProcessorTests: BitwardenTestCase { // swiftlint:disable:th
8383

8484
await subject.perform(.appeared)
8585

86-
XCTAssertEqual(subject.state.isTimeoutPolicyEnabled, true)
87-
XCTAssertEqual(subject.state.policyTimeoutAction, .logout)
86+
XCTAssertTrue(subject.state.isTimeoutPolicyEnabled)
87+
XCTAssertTrue(subject.state.isTimeoutActionPolicyEnabled)
88+
XCTAssertTrue(subject.state.isSessionTimeoutActionDisabled)
8889
XCTAssertEqual(subject.state.policyTimeoutValue, 60)
89-
XCTAssertEqual(subject.state.availableTimeoutActions, [.logout])
9090
XCTAssertEqual(subject.state.policyTimeoutHours, 1)
9191
XCTAssertEqual(subject.state.policyTimeoutMinutes, 0)
9292
XCTAssertEqual(
@@ -110,9 +110,10 @@ class AccountSecurityProcessorTests: BitwardenTestCase { // swiftlint:disable:th
110110

111111
await subject.perform(.appeared)
112112

113-
XCTAssertEqual(subject.state.isTimeoutPolicyEnabled, true)
113+
XCTAssertFalse(subject.state.isTimeoutActionPolicyEnabled)
114+
XCTAssertTrue(subject.state.isTimeoutPolicyEnabled)
115+
XCTAssertFalse(subject.state.isSessionTimeoutActionDisabled)
114116
XCTAssertEqual(subject.state.policyTimeoutValue, 61)
115-
XCTAssertEqual(subject.state.availableTimeoutActions, [.lock, .logout])
116117
XCTAssertEqual(subject.state.policyTimeoutHours, 1)
117118
XCTAssertEqual(subject.state.policyTimeoutMinutes, 1)
118119
XCTAssertEqual(

BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityState.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,15 @@ struct AccountSecurityState: Equatable {
177177
/// Whether the user has a master password.
178178
var hasMasterPassword = true
179179

180-
/// Whether the maximum timeout value policy is in effect.
181-
var isTimeoutPolicyEnabled: Bool = false
180+
/// Whether the timeout policy specifies a timeout action.
181+
var isTimeoutActionPolicyEnabled = false
182+
183+
/// Whether the timeout policy is in effect.
184+
var isTimeoutPolicyEnabled = false
182185

183186
/// Whether the unlock with pin code toggle is on.
184187
var isUnlockWithPINCodeOn: Bool = false
185188

186-
/// The maximum vault timeout policy action.
187-
///
188-
/// When set, this is the only action option available to users.
189-
var policyTimeoutAction: SessionTimeoutAction? = .lock {
190-
didSet {
191-
availableTimeoutActions = SessionTimeoutAction.allCases
192-
.filter { $0 == policyTimeoutAction }
193-
}
194-
}
195-
196189
/// The policy's maximum vault timeout value.
197190
///
198191
/// When set, all timeout values greater than this are no longer shown.
@@ -245,9 +238,9 @@ struct AccountSecurityState: Equatable {
245238
hasUnlockMethod
246239
}
247240

248-
/// Whether the session timeout row/picker should be disabled.
249-
var isSessionTimeoutDisabled: Bool {
250-
!hasUnlockMethod
241+
/// Whether the session timeout action row/picker should be disabled.
242+
var isSessionTimeoutActionDisabled: Bool {
243+
!hasUnlockMethod || isTimeoutActionPolicyEnabled
251244
}
252245

253246
/// Whether or not the custom session timeout field is shown.

BitwardenShared/UI/Platform/Settings/Settings/AccountSecurity/AccountSecurityView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct AccountSecurityView: View {
168168
send: AccountSecurityAction.sessionTimeoutActionChanged
169169
)
170170
)
171-
.disabled(store.state.isSessionTimeoutDisabled)
171+
.disabled(store.state.isSessionTimeoutActionDisabled)
172172
}
173173
.clipShape(RoundedRectangle(cornerRadius: 10))
174174
}

0 commit comments

Comments
 (0)