mirror of
https://github.com/bitwarden/android.git
synced 2026-05-10 16:45:43 -05:00
Compare commits
6 Commits
release/20
...
pm-18451/e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
924427bdcd | ||
|
|
09cb26e743 | ||
|
|
329753d9dc | ||
|
|
790c70936f | ||
|
|
ffc3784bbb | ||
|
|
d63d6bd33c |
@@ -93,13 +93,21 @@ class PolicyManagerImpl(
|
||||
organization: SyncResponseJson.Profile.Organization,
|
||||
policyType: PolicyTypeJson,
|
||||
): Boolean =
|
||||
if (policyType == PolicyTypeJson.MAXIMUM_VAULT_TIMEOUT) {
|
||||
organization.type == OrganizationType.OWNER
|
||||
} else if (policyType == PolicyTypeJson.PASSWORD_GENERATOR) {
|
||||
false
|
||||
} else {
|
||||
(organization.type == OrganizationType.OWNER ||
|
||||
organization.type == OrganizationType.ADMIN) ||
|
||||
organization.permissions.shouldManagePolicies
|
||||
when (policyType) {
|
||||
PolicyTypeJson.MAXIMUM_VAULT_TIMEOUT -> {
|
||||
organization.type == OrganizationType.OWNER
|
||||
}
|
||||
|
||||
PolicyTypeJson.PASSWORD_GENERATOR,
|
||||
PolicyTypeJson.REMOVE_UNLOCK_WITH_PIN,
|
||||
-> {
|
||||
false
|
||||
}
|
||||
|
||||
else -> {
|
||||
(organization.type == OrganizationType.OWNER ||
|
||||
organization.type == OrganizationType.ADMIN) ||
|
||||
organization.permissions.shouldManagePolicies
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,31 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
mutableRemovePinPolicyFlow.emit(
|
||||
listOf(
|
||||
createMockPolicy(
|
||||
isEnabled = true,
|
||||
type = PolicyTypeJson.REMOVE_UNLOCK_WITH_PIN,
|
||||
organizationId = "organizationUser",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
removeUnlockWithPinPolicyEnabled = true,
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `remove pin policy is true when user role is ADMIN`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
mutableRemovePinPolicyFlow.emit(
|
||||
listOf(
|
||||
createMockPolicy(
|
||||
organizationId = "organizationAdmin",
|
||||
isEnabled = true,
|
||||
type = PolicyTypeJson.REMOVE_UNLOCK_WITH_PIN,
|
||||
),
|
||||
@@ -195,31 +219,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `remove pin policy is false when user role is ADMIN`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
mutableRemovePinPolicyFlow.emit(
|
||||
listOf(
|
||||
createMockPolicy(
|
||||
organizationId = "organizationAdmin",
|
||||
isEnabled = true,
|
||||
type = PolicyTypeJson.REMOVE_UNLOCK_WITH_PIN,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
removeUnlockWithPinPolicyEnabled = false,
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `remove pin policy is false when user role is OWNER`() = runTest {
|
||||
fun `remove pin policy is true when user role is OWNER`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
mutableRemovePinPolicyFlow.emit(
|
||||
@@ -235,7 +235,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
removeUnlockWithPinPolicyEnabled = false,
|
||||
removeUnlockWithPinPolicyEnabled = true,
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
@@ -243,7 +243,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `remove pin policy is false when user role is CUSTOM with manage policies`() = runTest {
|
||||
fun `remove pin policy is true when user role is CUSTOM with manage policies`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
mutableRemovePinPolicyFlow.emit(
|
||||
@@ -259,7 +259,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
removeUnlockWithPinPolicyEnabled = false,
|
||||
removeUnlockWithPinPolicyEnabled = true,
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
@@ -988,7 +988,6 @@ private val DEFAULT_USER_STATE = UserState(
|
||||
Organization(
|
||||
id = "organizationUser",
|
||||
name = "Organization User",
|
||||
shouldManagePolicies = false,
|
||||
shouldUseKeyConnector = false,
|
||||
shouldManageResetPassword = false,
|
||||
role = OrganizationType.USER,
|
||||
@@ -996,7 +995,6 @@ private val DEFAULT_USER_STATE = UserState(
|
||||
Organization(
|
||||
id = "organizationAdmin",
|
||||
name = "Organization Admin",
|
||||
shouldManagePolicies = false,
|
||||
shouldUseKeyConnector = false,
|
||||
shouldManageResetPassword = false,
|
||||
role = OrganizationType.ADMIN,
|
||||
@@ -1004,7 +1002,6 @@ private val DEFAULT_USER_STATE = UserState(
|
||||
Organization(
|
||||
id = "organizationOwner",
|
||||
name = "Organization Owner",
|
||||
shouldManagePolicies = false,
|
||||
shouldUseKeyConnector = false,
|
||||
shouldManageResetPassword = false,
|
||||
role = OrganizationType.OWNER,
|
||||
@@ -1012,7 +1009,6 @@ private val DEFAULT_USER_STATE = UserState(
|
||||
Organization(
|
||||
id = "organizationCustom",
|
||||
name = "Organization Owner",
|
||||
shouldManagePolicies = true,
|
||||
shouldUseKeyConnector = false,
|
||||
shouldManageResetPassword = false,
|
||||
role = OrganizationType.CUSTOM,
|
||||
|
||||
Reference in New Issue
Block a user