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
This commit is contained in:
Colton Hurst 2023-04-10 22:36:18 -04:00 committed by GitHub
parent c3e87a55d6
commit 8d34bc9ad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -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<void>();
private loading = true;
projects: ProjectListView[];
private destroy$ = new Subject<void>();
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;
}