Skip to content

Commit

Permalink
[pm-17763] Add limitItemDeletion property to UI. (#13162)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyVo16 authored Jan 30, 2025
1 parent a404729 commit 7a1121d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ <h1 bitTypography="h1" class="tw-mt-16 tw-pb-2.5">{{ "collectionManagement" | i1
<bit-label>{{ "limitCollectionDeletionDesc" | i18n }}</bit-label>
<input type="checkbox" bitCheckbox formControlName="limitCollectionDeletion" />
</bit-form-control>
<bit-form-control *ngIf="limitItemDeletionFeatureFlagIsEnabled">
<bit-label>{{ "limitItemDeletionDesc" | i18n }}</bit-label>
<input type="checkbox" bitCheckbox formControlName="limitItemDeletion" />
</bit-form-control>
<button
type="submit"
bitButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { OrganizationUpdateRequest } from "@bitwarden/common/admin-console/model
import { OrganizationResponse } from "@bitwarden/common/admin-console/models/response/organization.response";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
Expand Down Expand Up @@ -53,6 +55,8 @@ export class AccountComponent implements OnInit, OnDestroy {
org: OrganizationResponse;
taxFormPromise: Promise<unknown>;

limitItemDeletionFeatureFlagIsEnabled: boolean;

// FormGroup validators taken from server Organization domain object
protected formGroup = this.formBuilder.group({
orgName: this.formBuilder.control(
Expand All @@ -71,6 +75,7 @@ export class AccountComponent implements OnInit, OnDestroy {
protected collectionManagementFormGroup = this.formBuilder.group({
limitCollectionCreation: this.formBuilder.control({ value: false, disabled: false }),
limitCollectionDeletion: this.formBuilder.control({ value: false, disabled: false }),
limitItemDeletion: this.formBuilder.control({ value: false, disabled: false }),
allowAdminAccessToAllCollectionItems: this.formBuilder.control({
value: false,
disabled: false,
Expand All @@ -94,11 +99,17 @@ export class AccountComponent implements OnInit, OnDestroy {
private dialogService: DialogService,
private formBuilder: FormBuilder,
private toastService: ToastService,
private configService: ConfigService,
) {}

async ngOnInit() {
this.selfHosted = this.platformUtilsService.isSelfHost();

this.configService
.getFeatureFlag$(FeatureFlag.limitItemDeletion)
.pipe(takeUntil(this.destroy$))
.subscribe((isAble) => (this.limitItemDeletionFeatureFlagIsEnabled = isAble));

const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
this.route.params
.pipe(
Expand Down Expand Up @@ -143,9 +154,11 @@ export class AccountComponent implements OnInit, OnDestroy {
orgName: this.org.name,
billingEmail: this.org.billingEmail,
});

this.collectionManagementFormGroup.patchValue({
limitCollectionCreation: this.org.limitCollectionCreation,
limitCollectionDeletion: this.org.limitCollectionDeletion,
limitItemDeletion: this.org.limitItemDeletion,
allowAdminAccessToAllCollectionItems: this.org.allowAdminAccessToAllCollectionItems,
});

Expand Down Expand Up @@ -202,6 +215,7 @@ export class AccountComponent implements OnInit, OnDestroy {
this.collectionManagementFormGroup.value.limitCollectionDeletion;
request.allowAdminAccessToAllCollectionItems =
this.collectionManagementFormGroup.value.allowAdminAccessToAllCollectionItems;
request.limitItemDeletion = this.collectionManagementFormGroup.value.limitItemDeletion;

await this.organizationApiService.updateCollectionManagement(this.organizationId, request);

Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8646,6 +8646,9 @@
"limitCollectionDeletionDesc": {
"message": "Limit collection deletion to owners and admins"
},
"limitItemDeletionDesc": {
"message": "Limit item deletion to members with the Can manage permission"
},
"allowAdminAccessToAllCollectionItemsDesc": {
"message": "Owners and admins can manage all collections and items"
},
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/enums/feature-flag.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum FeatureFlag {
ResellerManagedOrgAlert = "PM-15814-alert-owners-of-reseller-managed-orgs",
NewDeviceVerification = "new-device-verification",
EnableRiskInsightsNotifications = "enable-risk-insights-notifications",
limitItemDeletion = "pm-15493-restrict-item-deletion-to-can-manage-permission",
}

export type AllowedFeatureFlagTypes = boolean | number | string;
Expand Down Expand Up @@ -106,6 +107,7 @@ export const DefaultFeatureFlagValue = {
[FeatureFlag.ResellerManagedOrgAlert]: FALSE,
[FeatureFlag.NewDeviceVerification]: FALSE,
[FeatureFlag.EnableRiskInsightsNotifications]: FALSE,
[FeatureFlag.limitItemDeletion]: FALSE,
} satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>;

export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;
Expand Down

0 comments on commit 7a1121d

Please sign in to comment.