From 8d34bc9ad9992ca6c5ed54abca1d713044fab9a9 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 10 Apr 2023 22:36:18 -0400 Subject: [PATCH] SM-631: Allow Admins to Create and Edit Unassigned Secrets (#5052) * SM-631: Allow admins to edit and create unassigned secrets * SM-631: Fix OrganizationService import and refactor project selection logic in getSecretView --- .../secrets/dialog/secret-dialog.component.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/secrets/dialog/secret-dialog.component.ts b/bitwarden_license/bit-web/src/app/secrets-manager/secrets/dialog/secret-dialog.component.ts index f05a45b2d0..bb44b84bea 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/secrets/dialog/secret-dialog.component.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/secrets/dialog/secret-dialog.component.ts @@ -5,6 +5,7 @@ import { lastValueFrom, Subject } from "rxjs"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; +import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { DialogService } from "@bitwarden/components"; import { ProjectListView } from "../../models/view/project-list.view"; @@ -40,11 +41,10 @@ export class SecretDialogComponent implements OnInit { project: new FormControl("", [Validators.required]), }); + private destroy$ = new Subject(); private loading = true; projects: ProjectListView[]; - private destroy$ = new Subject(); - constructor( public dialogRef: DialogRef, @Inject(DIALOG_DATA) private data: SecretOperation, @@ -52,7 +52,8 @@ export class SecretDialogComponent implements OnInit { private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private projectService: ProjectService, - private dialogService: DialogService + private dialogService: DialogService, + private organizationService: OrganizationService ) {} async ngOnInit() { @@ -67,6 +68,11 @@ export class SecretDialogComponent implements OnInit { this.formGroup.get("project").setValue(this.data.projectId); } + if (this.organizationService.get(this.data.organizationId)?.isAdmin) { + this.formGroup.get("project").removeValidators(Validators.required); + this.formGroup.get("project").updateValueAndValidity(); + } + this.projects = await this.projectService .getProjects(this.data.organizationId) .then((projects) => projects.sort((a, b) => a.name.localeCompare(b.name))); @@ -157,7 +163,10 @@ export class SecretDialogComponent implements OnInit { secretView.name = this.formGroup.value.name; secretView.value = this.formGroup.value.value; secretView.note = this.formGroup.value.notes; - secretView.projects = [this.projects.find((p) => p.id == this.formGroup.value.project)]; + + const project = this.projects.find((p) => p.id == this.formGroup.value.project); + secretView.projects = project != undefined ? [project] : []; + return secretView; }