1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-secrets.component.ts
cd-bitwarden 6fa12fea49 Removing hanging promises, and adding a guard to projects routing (#8891)
* Removing hanging promises, and adding a guard to projects routing

* Additional logging

* adding tests

* Trying to get Jest tests working

* coltons suggested changes
2024-06-04 14:59:43 +00:00

128 lines
4.2 KiB
TypeScript

import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatest, combineLatestWith, filter, Observable, startWith, switchMap } from "rxjs";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components";
import { ProjectView } from "../../models/view/project.view";
import { SecretListView } from "../../models/view/secret-list.view";
import {
SecretDeleteDialogComponent,
SecretDeleteOperation,
} from "../../secrets/dialog/secret-delete.component";
import {
OperationType,
SecretDialogComponent,
SecretOperation,
} from "../../secrets/dialog/secret-dialog.component";
import { SecretService } from "../../secrets/secret.service";
import { SecretsListComponent } from "../../shared/secrets-list.component";
import { ProjectService } from "../project.service";
@Component({
selector: "sm-project-secrets",
templateUrl: "./project-secrets.component.html",
})
export class ProjectSecretsComponent {
secrets$: Observable<SecretListView[]>;
private organizationId: string;
private projectId: string;
protected project$: Observable<ProjectView>;
private organizationEnabled: boolean;
constructor(
private route: ActivatedRoute,
private projectService: ProjectService,
private secretService: SecretService,
private dialogService: DialogService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private organizationService: OrganizationService,
private logService: LogService,
) {}
ngOnInit() {
// Refresh list if project is edited
const currentProjectEdited = this.projectService.project$.pipe(
filter((p) => p?.id === this.projectId),
startWith(null),
);
this.project$ = combineLatest([this.route.params, currentProjectEdited]).pipe(
switchMap(([params, _]) => {
return this.projectService.getByProjectId(params.projectId);
}),
);
this.secrets$ = this.secretService.secret$.pipe(
startWith(null),
combineLatestWith(this.route.params, currentProjectEdited),
switchMap(async ([_, params]) => {
this.organizationId = params.organizationId;
this.projectId = params.projectId;
this.organizationEnabled = (
await this.organizationService.get(params.organizationId)
)?.enabled;
return await this.getSecretsByProject();
}),
);
}
private async getSecretsByProject(): Promise<SecretListView[]> {
return await this.secretService.getSecretsByProject(this.organizationId, this.projectId);
}
openEditSecret(secretId: string) {
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Edit,
secretId: secretId,
organizationEnabled: this.organizationEnabled,
},
});
}
openDeleteSecret(event: SecretListView[]) {
this.dialogService.open<unknown, SecretDeleteOperation>(SecretDeleteDialogComponent, {
data: {
secrets: event,
},
});
}
openNewSecretDialog() {
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Add,
projectId: this.projectId,
organizationEnabled: this.organizationEnabled,
},
});
}
copySecretName(name: string) {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
async copySecretValue(id: string) {
await SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService,
this.logService,
);
}
copySecretUuid(id: string) {
SecretsListComponent.copySecretUuid(id, this.platformUtilsService, this.i18nService);
}
}