Skip to content

Commit b2acdf2

Browse files
committed
pm-19305 Fix pr comments
1 parent b81b871 commit b2acdf2

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

BitwardenKit/Core/Platform/Models/Domain/SessionTimeoutPolicy.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ public struct SessionTimeoutPolicy {
1414

1515
// MARK: Initialization
1616

17-
/// Initialize `EnvironmentURLData` with the specified URLs.
17+
/// Initialize `SessionTimeoutPolicy` with the specified values.
1818
///
1919
/// - Parameters:
20-
/// - api: The URL for the API.
20+
/// - timeoutAction: The action to perform on session timeout.
21+
/// - timeoutType: The type of session timeout.
22+
/// - timeoutValue: The session timeout value.
2123
public init(
2224
timeoutAction: SessionTimeoutAction?,
2325
timeoutType: SessionTimeoutType?,

BitwardenResources/Localizations/en.lproj/Localizable.strings

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,4 +1278,3 @@
12781278
"ThisSettingIsManagedByYourOrganization" = "This setting is managed by your organization.";
12791279
"YourOrganizationHasSetTheDefaultSessionTimeoutToX" = "Your organization has set the default session timeout to %1$@.";
12801280
"YourOrganizationHasSetTheDefaultSessionTimeoutToXAndY" = "Your organization has set the default session timeout to %1$@ and %2$@.";
1281-
"XMinutes" = "%1$@ minute(s)";

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

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ struct AccountSecurityState: Equatable {
7272
var availableTimeoutActions: [SessionTimeoutAction] = SessionTimeoutAction.allCases
7373

7474
/// The timeout options to show when the policy for maximum timeout value is in effect.
75-
var availableTimeoutOptions: [SessionTimeoutValue] = SessionTimeoutValue.allCases
75+
var availableTimeoutOptions: [SessionTimeoutValue] {
76+
computeAvailableTimeoutOptions(
77+
type: policyTimeoutType,
78+
value: policyTimeoutValue,
79+
)
80+
}
7681

7782
/// The state of the badges in the settings tab.
7883
var badgeState: SettingsBadgeState?
@@ -97,36 +102,9 @@ struct AccountSecurityState: Equatable {
97102

98103
/// Whether the unlock with pin code toggle is on.
99104
var isUnlockWithPINCodeOn: Bool = false
100-
105+
101106
/// The policy's maximum vault timeout value.
102-
/// When set, all timeout values greater than this are no longer shown.
103-
var policyTimeoutValue: Int = 0 {
104-
didSet {
105-
availableTimeoutOptions = SessionTimeoutValue.allCases.filter { option in
106-
switch policyTimeoutType {
107-
case .never:
108-
return true
109-
case .onAppRestart:
110-
return option != .never
111-
case .immediately:
112-
return option == .immediately
113-
case .custom:
114-
if option.isCustomPlaceholder { return true }
115-
guard let time = option.minutesValue else { return false }
116-
return time <= policyTimeoutValue
117-
case nil,
118-
.predefined:
119-
if policyTimeoutValue > 0 {
120-
if option.isCustomPlaceholder { return true }
121-
guard let time = option.minutesValue else { return false }
122-
return time <= policyTimeoutValue
123-
} else {
124-
return true
125-
}
126-
}
127-
}
128-
}
129-
}
107+
var policyTimeoutValue: Int = 0
130108

131109
/// The policy's timeout action, if set.
132110
var policyTimeoutAction: SessionTimeoutAction?
@@ -278,4 +256,38 @@ struct AccountSecurityState: Equatable {
278256
)
279257
}
280258
}
259+
260+
/// Returns the available timeout options based on policy type and value.
261+
///
262+
/// - Parameters:
263+
/// - type: The policy's timeout type, if set.
264+
/// - value: The policy's maximum vault timeout value.
265+
/// - Returns: Filtered array of available session timeout values.
266+
private func computeAvailableTimeoutOptions(
267+
type: SessionTimeoutType?,
268+
value: Int
269+
) -> [SessionTimeoutValue] {
270+
SessionTimeoutValue.allCases.filter { option in
271+
switch type {
272+
case .never:
273+
return true
274+
case .onAppRestart:
275+
return option != .never
276+
case .immediately:
277+
return option == .immediately
278+
case .custom:
279+
if option.isCustomPlaceholder { return true }
280+
guard let time = option.minutesValue else { return false }
281+
return time <= value
282+
case nil, .predefined:
283+
if value > 0 {
284+
if option.isCustomPlaceholder { return true }
285+
guard let time = option.minutesValue else { return false }
286+
return time <= value
287+
} else {
288+
return true
289+
}
290+
}
291+
}
292+
}
281293
}

0 commit comments

Comments
 (0)