Skip to content

[PM-13428] Remove ownership option #1405

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ final class AddEditItemProcessor: StateProcessor<// swiftlint:disable:this type_

state.isPersonalOwnershipDisabled = isPersonalOwnershipDisabled
state.ownershipOptions = ownershipOptions
state.hasOrganizations = state.ownershipOptions.contains { !$0.isPersonal }
if isPersonalOwnershipDisabled, state.organizationId == nil {
// Only set the owner if personal ownership is disabled and there isn't already an
// organization owner set. This prevents overwriting a preset owner when adding a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protocol AddEditItemState: Sendable {
var guidedTourViewState: GuidedTourViewState { get set }

/// Whether the user belongs to any organization.
var hasOrganizations: Bool { get set }
var hasOrganizations: Bool { get }

/// The state for a identity type item.
var identityState: IdentityItemState { get set }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
CipherOwner.personal(email: "user@bitwarden.com"),
organizationOwner,
]
processor.state.hasOrganizations = true
let menu = try subject.inspect().find(bitwardenMenuField: Localizations.owner)
try menu.select(newValue: organizationOwner)
XCTAssertEqual(processor.dispatchedActions.last, .ownerChanged(organizationOwner))
Expand Down Expand Up @@ -682,7 +681,6 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
processor.state.ownershipOptions.append(.organization(id: "1", name: "Organization"))
processor.state.owner = .organization(id: "1", name: "Organization")
processor.state.collectionIds = ["2"]
processor.state.hasOrganizations = true

assertSnapshot(of: subject.navStackWrapped, as: .tallPortrait)
}
Expand All @@ -691,7 +689,6 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
func test_snapshot_add_login_collectionsNone() {
processor.state.ownershipOptions.append(.organization(id: "1", name: "Organization"))
processor.state.owner = .organization(id: "1", name: "Organization")
processor.state.hasOrganizations = true

assertSnapshot(of: subject.navStackWrapped, as: .tallPortrait)
}
Expand Down Expand Up @@ -762,7 +759,6 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
func test_snapshot_add_personalOwnershipPolicy() {
processor.state.ownershipOptions.append(.organization(id: "1", name: "Organization"))
processor.state.owner = .organization(id: "1", name: "Organization")
processor.state.hasOrganizations = true
processor.state.isPersonalOwnershipDisabled = true
processor.state.allUserCollections = [
.fixture(id: "1", name: "Default collection", organizationId: "1"),
Expand Down
13 changes: 4 additions & 9 deletions BitwardenShared/UI/Vault/VaultItem/CipherItemState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
]
)

/// Whether the user has organizations.
var hasOrganizations: Bool

/// The base url used to fetch icons.
var iconBaseURL: URL?

Expand Down Expand Up @@ -140,6 +137,10 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
self
}

var hasOrganizations: Bool {
cipher.organizationId != nil || ownershipOptions.contains { !$0.isPersonal }
}
Comment on lines +140 to +142
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โ›๏ธ Add tests.


/// Whether or not this item can be assigned to collections.
var canAssignToCollection: Bool {
guard !collectionIds.isEmpty else { return true }
Expand Down Expand Up @@ -271,7 +272,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
configuration: Configuration,
customFields: [CustomFieldState],
folderId: String?,
hasOrganizations: Bool,
iconBaseURL: URL?,
identityState: IdentityItemState,
isFavoriteOn: Bool,
Expand All @@ -292,7 +292,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
allUserCollections = []
customFieldsState = AddEditCustomFieldsState(cipherType: type, customFields: customFields)
self.folderId = folderId
self.hasOrganizations = hasOrganizations
self.iconBaseURL = iconBaseURL
self.identityState = identityState
self.isFavoriteOn = isFavoriteOn
Expand All @@ -317,7 +316,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
collectionIds: [String] = [],
customFields: [CustomFieldState] = [],
folderId: String? = nil,
hasOrganizations: Bool = false,
hasPremium: Bool,
name: String? = nil,
organizationId: String? = nil,
Expand All @@ -333,7 +331,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
configuration: .add,
customFields: customFields,
folderId: folderId,
hasOrganizations: hasOrganizations,
iconBaseURL: nil,
identityState: .init(),
isFavoriteOn: false,
Expand Down Expand Up @@ -364,7 +361,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
configuration: .add,
customFields: cipherView.customFields,
folderId: cipherView.folderId,
hasOrganizations: cipherView.organizationId != nil,
iconBaseURL: nil,
identityState: cipherView.identityItemState(),
isFavoriteOn: cipherView.favorite,
Expand Down Expand Up @@ -396,7 +392,6 @@ struct CipherItemState: Equatable { // swiftlint:disable:this type_body_length
configuration: .existing(cipherView: cipherView),
customFields: cipherView.customFields,
folderId: cipherView.folderId,
hasOrganizations: cipherView.organizationId != nil,
iconBaseURL: iconBaseURL,
identityState: cipherView.identityItemState(),
isFavoriteOn: cipherView.favorite,
Expand Down
Loading