Skip to content
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

[AC-1757] ConfigService dependency fix #6686

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
[showGroups]="showGroups"
[organizations]="allOrganizations"
[groups]="allGroups"
[canDeleteCollection]="canDeleteCollection(item.collection) | async"
[canDeleteCollection]="canDeleteCollection(item.collection)"
[canEditCollection]="canEditCollection(item.collection)"
[checked]="selection.isSelected(item)"
(checkedToggled)="selection.toggle(item)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SelectionModel } from "@angular/cdk/collections";
import { Component, EventEmitter, Input, Output } from "@angular/core";

import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
Expand All @@ -28,6 +29,8 @@ const MaxSelectionCount = 500;
export class VaultItemsComponent {
protected RowHeight = RowHeight;

private flexibleCollectionsEnabled: boolean;

@Input() disabled: boolean;
@Input() showOwner: boolean;
@Input() showCollections: boolean;
Expand Down Expand Up @@ -70,6 +73,12 @@ export class VaultItemsComponent {

constructor(private configService: ConfigServiceAbstraction) {}

async ngOnInit() {
this.flexibleCollectionsEnabled = await this.configService.getFeatureFlag(
FeatureFlag.FlexibleCollections
);
}

get showExtraColumn() {
return this.showCollections || this.showGroups || this.showOwner;
}
Expand Down Expand Up @@ -100,14 +109,14 @@ export class VaultItemsComponent {
return collection.canEdit(organization);
}

protected async canDeleteCollection(collection: CollectionView): Promise<boolean> {
protected canDeleteCollection(collection: CollectionView): boolean {
// Only allow allow deletion if collection editing is enabled and not deleting "Unassigned"
if (collection.id === Unassigned) {
return false;
}

const organization = this.allOrganizations.find((o) => o.id === collection.organizationId);
return await collection.canDelete(organization, this.configService);
return collection.canDelete(organization, this.flexibleCollectionsEnabled);
}

protected toggleAll() {
Expand Down
9 changes: 2 additions & 7 deletions apps/web/src/app/vault/core/views/collection-admin.view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { CollectionAccessDetailsResponse } from "@bitwarden/common/src/vault/models/response/collection.response";
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";

Expand Down Expand Up @@ -37,11 +35,8 @@ export class CollectionAdminView extends CollectionView {
return org?.canEditAnyCollection || (org?.canEditAssignedCollections && this.assigned);
}

override async canDelete(
org: Organization,
configService: ConfigServiceAbstraction
): Promise<boolean> {
if (await configService.getFeatureFlag(FeatureFlag.FlexibleCollections)) {
override canDelete(org: Organization, flexibleCollectionsEnabled: boolean): boolean {
if (flexibleCollectionsEnabled) {
return org?.canDeleteAnyCollection;
} else {
return org?.canDeleteAnyCollection || (org?.canDeleteAssignedCollections && this.assigned);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ <h1 class="tw-mb-0 tw-mt-1 tw-flex tw-items-center tw-space-x-2">
aria-hidden="true"
></i>
<span>{{ title }}</span>
<ng-container
*ngIf="collection !== undefined && (canEditCollection || canDeleteCollection())"
>
<ng-container *ngIf="collection !== undefined && (canEditCollection || canDeleteCollection)">
<button
bitIconButton="bwi-angle-down"
[bitMenuTriggerFor]="editCollectionMenu"
Expand Down Expand Up @@ -59,7 +57,7 @@ <h1 class="tw-mb-0 tw-mt-1 tw-flex tw-items-center tw-space-x-2">
</button>
<button
type="button"
*ngIf="canDeleteCollection()"
*ngIf="canDeleteCollection"
bitMenuItem
(click)="deleteCollection()"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from "@angular/core";

import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { TreeNode } from "@bitwarden/common/models/domain/tree-node";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
Expand All @@ -23,6 +24,8 @@ export class VaultHeaderComponent {
protected All = All;
protected CollectionDialogTabType = CollectionDialogTabType;

private flexibleCollectionsEnabled: boolean;

/**
* Boolean to determine the loading state of the header.
* Shows a loading spinner if set to true
Expand Down Expand Up @@ -58,6 +61,12 @@ export class VaultHeaderComponent {

constructor(private i18nService: I18nService, private configService: ConfigServiceAbstraction) {}

async ngOnInit() {
this.flexibleCollectionsEnabled = await this.configService.getFeatureFlag(
FeatureFlag.FlexibleCollections
);
}

/**
* The id of the organization that is currently being filtered on.
* This can come from a collection filter or organization filter, if applied.
Expand Down Expand Up @@ -141,7 +150,7 @@ export class VaultHeaderComponent {
this.onEditCollection.emit({ tab });
}

async canDeleteCollection(): Promise<boolean> {
get canDeleteCollection(): boolean {
// Only delete collections if not deleting "Unassigned"
if (this.collection === undefined) {
return false;
Expand All @@ -152,7 +161,7 @@ export class VaultHeaderComponent {
(o) => o.id === this.collection?.node.organizationId
);

return await this.collection.node.canDelete(organization, this.configService);
return this.collection.node.canDelete(organization, this.flexibleCollectionsEnabled);
}

deleteCollection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ <h1 class="tw-mb-0 tw-mt-1 tw-flex tw-items-center tw-space-x-2">
aria-hidden="true"
></i>
<span>{{ title }}</span>
<ng-container
*ngIf="collection !== undefined && (canEditCollection || canDeleteCollection())"
>
<ng-container *ngIf="collection !== undefined && (canEditCollection || canDeleteCollection)">
<button
bitIconButton="bwi-angle-down"
[bitMenuTriggerFor]="editCollectionMenu"
Expand Down Expand Up @@ -58,7 +56,7 @@ <h1 class="tw-mb-0 tw-mt-1 tw-flex tw-items-center tw-space-x-2">
</button>
<button
type="button"
*ngIf="canDeleteCollection()"
*ngIf="canDeleteCollection"
bitMenuItem
(click)="deleteCollection()"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { firstValueFrom } from "rxjs";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { ProductType } from "@bitwarden/common/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { TreeNode } from "@bitwarden/common/models/domain/tree-node";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
Expand Down Expand Up @@ -57,6 +58,8 @@ export class VaultHeaderComponent {
protected CollectionDialogTabType = CollectionDialogTabType;
protected organizations$ = this.organizationService.organizations$;

private flexibleCollectionsEnabled: boolean;

constructor(
private organizationService: OrganizationService,
private i18nService: I18nService,
Expand All @@ -66,6 +69,12 @@ export class VaultHeaderComponent {
private configService: ConfigServiceAbstraction
) {}

async ngOnInit() {
this.flexibleCollectionsEnabled = await this.configService.getFeatureFlag(
FeatureFlag.FlexibleCollections
);
}

get title() {
if (this.collection !== undefined) {
return this.collection.node.name;
Expand Down Expand Up @@ -166,14 +175,14 @@ export class VaultHeaderComponent {
this.onEditCollection.emit({ tab });
}

async canDeleteCollection(): Promise<boolean> {
get canDeleteCollection(): boolean {
// Only delete collections if not deleting "Unassigned"
if (this.collection === undefined) {
return false;
}

// Otherwise, check if we can delete the specified collection
return await this.collection.node.canDelete(this.organization, this.configService);
return this.collection.node.canDelete(this.organization, this.flexibleCollectionsEnabled);
}

deleteCollection() {
Expand Down
6 changes: 2 additions & 4 deletions libs/common/src/vault/models/view/collection.view.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Organization } from "../../../admin-console/models/domain/organization";
import { FeatureFlag } from "../../../enums/feature-flag.enum";
import { ITreeNodeObject } from "../../../models/domain/tree-node";
import { View } from "../../../models/view/view";
import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/config.service.abstraction";
import { Collection } from "../domain/collection";
import { CollectionAccessDetailsResponse } from "../response/collection.response";

Expand Down Expand Up @@ -44,14 +42,14 @@ export class CollectionView implements View, ITreeNodeObject {
}

// For deleting a collection, not the items within it.
async canDelete(org: Organization, configService: ConfigServiceAbstraction): Promise<boolean> {
canDelete(org: Organization, flexibleCollectionsEnabled: boolean): boolean {
if (org.id !== this.organizationId) {
throw new Error(
"Id of the organization provided does not match the org id of the collection."
);
}

if (await configService.getFeatureFlag(FeatureFlag.FlexibleCollections)) {
if (flexibleCollectionsEnabled) {
return org?.canDeleteAnyCollection || (!org?.limitCollectionCreationDeletion && this.manage);
} else {
return org?.canDeleteAnyCollection || org?.canDeleteAssignedCollections;
Expand Down