-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-11304] Ownership Not Defaulting To Org and Collection #4254
Changes from 14 commits
96a3aa9
ad055f3
a52588f
b185412
96f118e
9213ad2
3dc7657
c70ff9b
4aef4dd
0387f0b
a0e3ae0
fdae12e
b2c3323
7bb0eb2
e722c55
2ecd65e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,12 @@ | |
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2RegisterCredentialResult | ||
import com.x8bit.bitwarden.data.autofill.fido2.model.UserVerificationRequirement | ||
import com.x8bit.bitwarden.data.autofill.util.isActiveWithFido2Credentials | ||
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager | ||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager | ||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager | ||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager | ||
import com.x8bit.bitwarden.data.platform.manager.event.OrganizationEventManager | ||
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey | ||
import com.x8bit.bitwarden.data.platform.manager.model.OrganizationEvent | ||
import com.x8bit.bitwarden.data.platform.manager.util.toAutofillSaveItemOrNull | ||
import com.x8bit.bitwarden.data.platform.manager.util.toAutofillSelectionDataOrNull | ||
|
@@ -101,12 +103,14 @@ | |
private val resourceManager: ResourceManager, | ||
private val clock: Clock, | ||
private val organizationEventManager: OrganizationEventManager, | ||
private val featureFlagManager: FeatureFlagManager, | ||
) : BaseViewModel<VaultAddEditState, VaultAddEditEvent, VaultAddEditAction>( | ||
// We load the state from the savedStateHandle for testing purposes. | ||
initialState = savedStateHandle[KEY_STATE] | ||
?: run { | ||
val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType | ||
val selectedFolderId = VaultAddEditArgs(savedStateHandle).selectedFolderId | ||
val selectedCollectionId = VaultAddEditArgs(savedStateHandle).selectedCollectionId | ||
val isIndividualVaultDisabled = policyManager | ||
.getActivePolicies(type = PolicyTypeJson.PERSONAL_OWNERSHIP) | ||
.any() | ||
|
@@ -147,12 +151,11 @@ | |
attestationOptions = fido2AttestationOptions, | ||
isIndividualVaultDisabled = isIndividualVaultDisabled, | ||
) | ||
?: totpData?.toDefaultAddTypeContent( | ||
isIndividualVaultDisabled = isIndividualVaultDisabled, | ||
) | ||
?: totpData?.toDefaultAddTypeContent(isIndividualVaultDisabled) | ||
?: VaultAddEditState.ViewState.Content( | ||
common = VaultAddEditState.ViewState.Content.Common( | ||
selectedFolderId = selectedFolderId, | ||
selectedCollectionId = selectedCollectionId, | ||
), | ||
isIndividualVaultDisabled = isIndividualVaultDisabled, | ||
type = vaultAddEditType.vaultItemCipherType.toItemType(), | ||
|
@@ -167,7 +170,11 @@ | |
// Set special conditions for autofill and fido2 save | ||
shouldShowCloseButton = autofillSaveItem == null && fido2AttestationOptions == null, | ||
shouldExitOnSave = shouldExitOnSave, | ||
supportedItemTypes = getSupportedItemTypeOptions(), | ||
supportedItemTypes = getSupportedItemTypeOptions( | ||
isSshKeyVaultItemSupported = featureFlagManager.getFeatureFlag( | ||
key = FlagKey.SshKeyCipherItems, | ||
), | ||
), | ||
) | ||
}, | ||
) { | ||
|
@@ -209,6 +216,12 @@ | |
} | ||
.onEach(::sendAction) | ||
.launchIn(viewModelScope) | ||
|
||
featureFlagManager | ||
.getFeatureFlagFlow(FlagKey.SshKeyCipherItems) | ||
.map { VaultAddEditAction.Internal.SshKeyCipherItemsFeatureFlagReceive(it) } | ||
.onEach(::sendAction) | ||
.launchIn(viewModelScope) | ||
} | ||
|
||
override fun handleAction(action: VaultAddEditAction) { | ||
|
@@ -1082,7 +1095,9 @@ | |
updateLoginContent { loginType -> | ||
loginType.copy( | ||
uriList = loginType.uriList + UriItem( | ||
id = UUID.randomUUID().toString(), | ||
id = UUID | ||
.randomUUID() | ||
.toString(), | ||
uri = "", | ||
match = null, | ||
checksum = null, | ||
|
@@ -1435,6 +1450,10 @@ | |
is VaultAddEditAction.Internal.ValidateFido2PinResultReceive -> { | ||
handleValidateFido2PinResultReceive(action) | ||
} | ||
|
||
is VaultAddEditAction.Internal.SshKeyCipherItemsFeatureFlagReceive -> { | ||
handleSshKeyCipherItemsFeatureFlagReceive(action) | ||
Check warning on line 1455 in app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt Codecov / codecov/patchapp/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt#L1454-L1455
|
||
} | ||
} | ||
} | ||
|
||
|
@@ -1769,6 +1788,19 @@ | |
|
||
getRequestAndRegisterCredential() | ||
} | ||
|
||
private fun handleSshKeyCipherItemsFeatureFlagReceive( | ||
action: VaultAddEditAction.Internal.SshKeyCipherItemsFeatureFlagReceive, | ||
) { | ||
mutableStateFlow.update { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test for this action There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was actually a merge mistake, I've already reverted it. Thanks for catching that! |
||
it.copy( | ||
supportedItemTypes = getSupportedItemTypeOptions( | ||
isSshKeyVaultItemSupported = action.enabled, | ||
Check warning on line 1798 in app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt Codecov / codecov/patchapp/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt#L1795-L1798
|
||
), | ||
) | ||
Check warning on line 1800 in app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt Codecov / codecov/patchapp/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt#L1800
|
||
} | ||
} | ||
|
||
//endregion Internal Type Handlers | ||
|
||
//region Utility Functions | ||
|
@@ -2113,6 +2145,7 @@ | |
val favorite: Boolean = false, | ||
val customFieldData: List<Custom> = emptyList(), | ||
val notes: String = "", | ||
val selectedCollectionId: String? = null, | ||
val selectedFolderId: String? = null, | ||
val availableFolders: List<Folder> = emptyList(), | ||
val selectedOwnerId: String? = null, | ||
|
@@ -2171,7 +2204,9 @@ | |
val canEditItem: Boolean = true, | ||
val uriList: List<UriItem> = listOf( | ||
UriItem( | ||
id = UUID.randomUUID().toString(), | ||
id = UUID | ||
.randomUUID() | ||
.toString(), | ||
uri = "", | ||
match = null, | ||
checksum = null, | ||
|
@@ -3083,6 +3118,13 @@ | |
val generatorResult: GeneratorResult, | ||
) : Internal() | ||
|
||
/** | ||
* Indicates that the the SSH key vault item feature flag state has been received. | ||
*/ | ||
data class SshKeyCipherItemsFeatureFlagReceive( | ||
val enabled: Boolean, | ||
) : Internal() | ||
Check warning on line 3126 in app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt Codecov / codecov/patchapp/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt#L3125-L3126
|
||
|
||
/** | ||
* Indicates that the vault item data has been received. | ||
*/ | ||
|
@@ -3137,10 +3179,7 @@ | |
} | ||
} | ||
|
||
/** | ||
* Returns a list of item type options that can be selected during item creation. | ||
* | ||
* TODO: [PM-10413] Allow SSH key creation when the SDK supports it. | ||
*/ | ||
private fun getSupportedItemTypeOptions() = VaultAddEditState.ItemTypeOption.entries | ||
.filter { it != VaultAddEditState.ItemTypeOption.SSH_KEYS } | ||
private fun getSupportedItemTypeOptions( | ||
isSshKeyVaultItemSupported: Boolean, | ||
) = VaultAddEditState.ItemTypeOption.entries | ||
.filter { isSshKeyVaultItemSupported || it != VaultAddEditState.ItemTypeOption.SSH_KEYS } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to make this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that should not happen as part of the formatter. To be clear, there is nothing wrong with this change but the regular auto-formatter does not normally do this. ๐ค
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated to match yours, thanks