10000 [PM-10915] Ownership does not default to the organization you are in when creating a new item by LRNcardozoWDF · Pull Request #1333 · bitwarden/ios · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[PM-10915] Ownership does not default to the organization you are in when creating a new item #1333

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

Merged
Merged
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions BitwardenShared/UI/Vault/Vault/VaultCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ final class VaultCoordinator: Coordinator, HasStackNavigator { // swiftlint:disa
switch route {
case .addAccount:
delegate?.didTapAddAccount()
case let .addItem(allowTypeSelection, group, newCipherOptions):
case let .addItem(allowTypeSelection, group, newCipherOptions, organizationId):
Task {
let hasPremium = try? await services.vaultRepository.doesActiveAccountHavePremium()
showVaultItem(
route: .addItem(
allowTypeSelection: allowTypeSelection,
group: group,
hasPremium: hasPremium ?? false,
newCipherOptions: newCipherOptions
newCipherOptions: newCipherOptions,
organizationId: organizationId
),
delegate: context as? CipherItemOperationDelegate
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ final class VaultListProcessor: StateProcessor<
switch action {
case .addItemPressed:
setProfileSwitcher(visible: false)
coordinator.navigate(to: .addItem())
switch state.vaultFilterType {
case let .organization(organization):
coordinator.navigate(to: .addItem(organizationId: organization.id))
default:
coordinator.navigate(to: .addItem())
}
reviewPromptTask?.cancel()
case .clearURL:
state.url = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,17 @@ class VaultListProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
XCTAssertTrue(subject.reviewPromptTask!.isCancelled)
}

/// `receive(_:)` with `.addItemPressed` when an organization was selected in the filter navigates
/// to the `.addItem` route with the corresponding organization id.
@MainActor
func test_receive_addItemPressed_organizationSelected() {
subject.state.vaultFilterType = .organization(Organization.fixture())

subject.receive(.addItemPressed)

XCTAssertEqual(coordinator.routes.last, .addItem(organizationId: "organization-1"))
}

/// `receive(_:)` with `.clearURL` clears the url in the state.
@MainActor
func test_receive_clearURL() {
Expand Down
4 changes: 3 additions & 1 deletion BitwardenShared/UI/Vault/Vault/VaultRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public enum VaultRoute: Equatable, Hashable {
/// - allowTypeSelection: Whether the user should be able to select the type of item to add.
/// - group: An optional `VaultListGroup` that the user wants to add an item for.
/// - newCipherOptions: Options that can be used to pre-populate the add item screen.
/// - organizationId: The organization id in case an organization was selected in the vault filter.
///
case addItem(
allowTypeSelection: Bool = true,
group: VaultListGroup? = nil,
newCipherOptions: NewCipherOptions? = nil
newCipherOptions: NewCipherOptions? = nil,
organizationId: String? = nil
)

/// A route to the autofill list screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ class VaultItemCoordinator: NSObject, Coordinator, HasStackNavigator { // swiftl
allowTypeSelection,
group,
hasPremium,
newCipherOptions
newCipherOptions,
organizationId
):
showAddItem(
for: group,
allowTypeSelection: allowTypeSelection,
hasPremium: hasPremium,
newCipherOptions: newCipherOptions,
organizationId: organizationId,
delegate: context as? CipherItemOperationDelegate
)
case let .attachments(cipher):
Expand Down Expand Up @@ -152,6 +154,7 @@ class VaultItemCoordinator: NSObject, Coordinator, HasStackNavigator { // swiftl
/// - allowTypeSelection: Whether the user should be able to select the type of item to add.
/// - hasPremium: Whether the user has premium,
/// - newCipherOptions: Options that can be used to pre-populate the add item screen.
/// - organizationId: The organization id in case an organization was selected in the vault filter.
/// - delegate: A `CipherItemOperationDelegate` delegate that is notified when specific circumstances
/// in the add/edit/delete item view have occurred.
///
Expand All @@ -160,6 +163,7 @@ class VaultItemCoordinator: NSObject, Coordinator, HasStackNavigator { // swiftl
allowTypeSelection: Bool,
hasPremium: Bool,
newCipherOptions: NewCipherOptions?,
organizationId: String?,
delegate: CipherItemOperationDelegate?
) {
let state = CipherItemState(
Expand All @@ -169,7 +173,7 @@ class VaultItemCoordinator: NSObject, Coordinator, HasStackNavigator { // swiftl
folderId: group?.folderId,
hasPremium: hasPremium,
name: newCipherOptions?.name,
organizationId: group?.organizationId,
organizationId: organizationId ?? group?.organizationId,
password: newCipherOptions?.password,
totpKeyString: newCipherOptions?.totpKey,
uri: newCipherOptions?.uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ class VaultItemCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this t
XCTAssertEqual(view.store.state.folderId, "12345")
}

/// `navigate(to:)` with `.addItem` with an organization ID, pushes the add item view onto the
/// stack navigator and sets organization's ID on the new item.
@MainActor
func test_navigateTo_addItem_withOrganizationId() throws {
subject.navigate(
to: .addItem(
organizationId: "org-12345"
)
)

let action = try XCTUnwrap(stackNavigator.actions.last)
XCTAssertEqual(action.type, .replaced)
XCTAssertTrue(action.view is AddEditItemView)

let view = try XCTUnwrap(action.view as? AddEditItemView)
XCTAssertEqual(view.store.state.type, .login)
XCTAssertEqual(view.store.state.organizationId, "org-12345")
}

/// `navigate(to:)` with `.cloneItem()` triggers the show clone item flow.
@MainActor
func test_navigateTo_cloneItem_nonPremium() throws {
Expand Down
4 changes: 3 additions & 1 deletion BitwardenShared/UI/Vault/VaultItem/VaultItemRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ enum VaultItemRoute: Equatable, Hashable {
/// - group: An optional `VaultListGroup` that the user wants to add an item for.
/// - hasPremium: Whether the user has premium.
/// - newCipherOptions: Optional options for creating a new cipher.
/// - organizationId: The organization id in case an organization was selected in the vault filter.
///
case addItem(
allowTypeSelection: Bool = true,
group: VaultListGroup? = nil,
hasPremium: Bool = false,
newCipherOptions: NewCipherOptions? = nil
newCipherOptions: NewCipherOptions? = nil,
organizationId: String? = nil
)

/// A route to view the attachments.
Expand Down
0