This commit is contained in:
cd-bitwarden 2024-04-25 16:30:49 -05:00 committed by GitHub
commit d0e08c8ae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 70 additions and 80 deletions

View File

@ -17,6 +17,7 @@ import {
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";
@ -94,6 +95,7 @@ export class OverviewComponent implements OnInit, OnDestroy {
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private smOnboardingTasksService: SMOnboardingTasksService,
private logService: LogService,
) {}
ngOnInit() {
@ -297,12 +299,13 @@ export class OverviewComponent implements OnInit, OnDestroy {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
copySecretValue(id: string) {
SecretsListComponent.copySecretValue(
async copySecretValue(id: string) {
await SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService,
this.logService,
);
}
@ -310,11 +313,9 @@ export class OverviewComponent implements OnInit, OnDestroy {
SecretsListComponent.copySecretUuid(id, this.platformUtilsService, this.i18nService);
}
protected hideOnboarding() {
protected async hideOnboarding() {
this.showOnboarding = false;
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.saveCompletedTasks(this.organizationId, {
await this.saveCompletedTasks(this.organizationId, {
importSecrets: true,
createSecret: true,
createProject: true,

View File

@ -82,9 +82,7 @@ export class ProjectDialogComponent implements OnInit {
const projectView = this.getProjectView();
if (this.data.operation === OperationType.Add) {
const newProject = await this.createProject(projectView);
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["sm", this.data.organizationId, "projects", newProject.id]);
await this.router.navigate(["sm", this.data.organizationId, "projects", newProject.id]);
} else {
projectView.id = this.data.projectId;
await this.updateProject(projectView);

View File

@ -0,0 +1,21 @@
import { inject } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router";
import { ProjectService } from "../project.service";
/**
* Redirects to service accounts page if the user doesn't have access to service account.
*/
export const projectAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => {
const projectService = inject(ProjectService);
try {
const project = await projectService.getByProjectId(route.params.projectId);
if (project) {
return true;
}
} catch {
return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]);
}
return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]);
};

View File

@ -1,9 +1,10 @@
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from "@angular/core";
import { FormControl, FormGroup } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
import { combineLatest, Subject, switchMap, takeUntil, catchError, EMPTY } from "rxjs";
import { combineLatest, Subject, switchMap, takeUntil, catchError } from "rxjs";
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 { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { DialogService } from "@bitwarden/components";
@ -37,11 +38,10 @@ export class ProjectPeopleComponent implements OnInit, OnDestroy {
return convertToAccessPolicyItemViews(policies);
}),
),
catchError(() => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/sm", this.organizationId, "projects"]);
return EMPTY;
catchError(async () => {
this.logService.info("Error fetching project people access policies.");
await this.router.navigate(["/sm", this.organizationId, "projects"]);
return undefined;
}),
);
@ -72,6 +72,7 @@ export class ProjectPeopleComponent implements OnInit, OnDestroy {
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private accessPolicySelectorService: AccessPolicySelectorService,
private logService: LogService,
) {}
ngOnInit(): void {
@ -126,9 +127,7 @@ export class ProjectPeopleComponent implements OnInit, OnDestroy {
this.currentAccessPolicies = convertToAccessPolicyItemViews(peoplePoliciesViews);
if (showAccessRemovalWarning) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["sm", this.organizationId, "projects"]);
await this.router.navigate(["sm", this.organizationId, "projects"]);
}
this.platformUtilsService.showToast(
"success",

View File

@ -4,6 +4,7 @@ import { combineLatest, combineLatestWith, filter, Observable, startWith, switch
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";
@ -42,6 +43,7 @@ export class ProjectSecretsComponent {
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private organizationService: OrganizationService,
private logService: LogService,
) {}
ngOnInit() {
@ -109,12 +111,13 @@ export class ProjectSecretsComponent {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
copySecretValue(id: string) {
SecretsListComponent.copySecretValue(
async copySecretValue(id: string) {
await SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService,
this.logService,
);
}

View File

@ -1,9 +1,7 @@
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import {
catchError,
combineLatest,
EMPTY,
filter,
Observable,
startWith,
@ -58,18 +56,6 @@ export class ProjectComponent implements OnInit, OnDestroy {
this.project$ = combineLatest([this.route.params, currentProjectEdited]).pipe(
switchMap(([params, _]) => this.projectService.getByProjectId(params.projectId)),
catchError(() => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/sm", this.organizationId, "projects"]).then(() => {
this.platformUtilsService.showToast(
"error",
null,
this.i18nService.t("notFound", this.i18nService.t("project")),
);
});
return EMPTY;
}),
);
const projectId$ = this.route.params.pipe(map((p) => p.projectId));

View File

@ -1,6 +1,7 @@
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { projectAccessGuard } from "./guards/project-access.guard";
import { ProjectPeopleComponent } from "./project/project-people.component";
import { ProjectSecretsComponent } from "./project/project-secrets.component";
import { ProjectServiceAccountsComponent } from "./project/project-service-accounts.component";
@ -15,6 +16,7 @@ const routes: Routes = [
{
path: ":projectId",
component: ProjectComponent,
canActivate: [projectAccessGuard],
children: [
{
path: "",

View File

@ -199,7 +199,7 @@ export class SecretDialogComponent implements OnInit {
return await this.projectService.create(this.data.organizationId, projectView);
}
protected openDeleteSecretDialog() {
protected async openDeleteSecretDialog() {
const secretListView: SecretListView[] = this.getSecretListView();
const dialogRef = this.dialogService.open<unknown, SecretDeleteOperation>(
@ -212,9 +212,7 @@ export class SecretDialogComponent implements OnInit {
);
// If the secret is deleted, chain close this dialog after the delete dialog
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
lastValueFrom(dialogRef.closed).then(
await lastValueFrom(dialogRef.closed).then(
(closeData) => closeData !== undefined && this.dialogRef.close(),
);
}

View File

@ -4,6 +4,7 @@ import { combineLatestWith, 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";
@ -39,6 +40,7 @@ export class SecretsComponent implements OnInit {
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private organizationService: OrganizationService,
private logService: LogService,
) {}
ngOnInit() {
@ -97,12 +99,13 @@ export class SecretsComponent implements OnInit {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
copySecretValue(id: string) {
SecretsListComponent.copySecretValue(
async copySecretValue(id: string) {
await SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService,
this.logService,
);
}

View File

@ -47,9 +47,7 @@ export class ServiceAccountDialogComponent {
async ngOnInit() {
if (this.data.operation == OperationType.Edit) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.loadData();
await this.loadData();
}
}

View File

@ -1,9 +1,10 @@
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from "@angular/core";
import { FormControl, FormGroup } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
import { catchError, combineLatest, EMPTY, Subject, switchMap, takeUntil } from "rxjs";
import { catchError, combineLatest, Subject, switchMap, takeUntil } from "rxjs";
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 { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { DialogService } from "@bitwarden/components";
@ -40,11 +41,10 @@ export class ServiceAccountPeopleComponent implements OnInit, OnDestroy {
return convertToAccessPolicyItemViews(policies);
}),
),
catchError(() => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/sm", this.organizationId, "machine-accounts"]);
return EMPTY;
catchError(async () => {
this.logService.info("Error fetching service account people access policies.");
await this.router.navigate(["/sm", this.organizationId, "machine-accounts"]);
return undefined;
}),
);
@ -76,6 +76,7 @@ export class ServiceAccountPeopleComponent implements OnInit, OnDestroy {
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private accessPolicySelectorService: AccessPolicySelectorService,
private logService: LogService,
) {}
ngOnInit(): void {
@ -198,9 +199,7 @@ export class ServiceAccountPeopleComponent implements OnInit, OnDestroy {
selectedPolicies: ApItemValueType[],
): Promise<void> {
if (showAccessRemovalWarning) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["sm", this.organizationId, "machine-accounts"]);
await this.router.navigate(["sm", this.organizationId, "machine-accounts"]);
} else if (
this.accessPolicySelectorService.isAccessRemoval(currentAccessPolicies, selectedPolicies)
) {

View File

@ -1,15 +1,6 @@
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import {
EMPTY,
Subject,
catchError,
combineLatest,
filter,
startWith,
switchMap,
takeUntil,
} from "rxjs";
import { Subject, combineLatest, filter, startWith, switchMap, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
@ -42,18 +33,6 @@ export class ServiceAccountComponent implements OnInit, OnDestroy {
params.organizationId,
),
),
catchError(() => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/sm", this.organizationId, "machine-accounts"]).then(() => {
this.platformUtilsService.showToast(
"error",
null,
this.i18nService.t("notFound", this.i18nService.t("machineAccount")),
);
});
return EMPTY;
}),
);
constructor(

View File

@ -3,6 +3,7 @@ import { Component, EventEmitter, Input, OnDestroy, Output } from "@angular/core
import { Subject, takeUntil } from "rxjs";
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 { TableDataSource } from "@bitwarden/components";
@ -134,22 +135,24 @@ export class SecretsListComponent implements OnDestroy {
/**
* TODO: Refactor to smart component and remove
*/
static copySecretValue(
static async copySecretValue(
id: string,
platformUtilsService: PlatformUtilsService,
i18nService: I18nService,
secretService: SecretService,
logService: LogService,
) {
const value = secretService.getBySecretId(id).then((secret) => secret.value);
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
SecretsListComponent.copyToClipboardAsync(value, platformUtilsService).then(() => {
try {
const value = await secretService.getBySecretId(id).then((secret) => secret.value);
platformUtilsService.copyToClipboard(value);
platformUtilsService.showToast(
"success",
null,
i18nService.t("valueCopied", i18nService.t("value")),
);
});
} catch {
logService.info("Error fetching secret value.");
}
}
static copySecretUuid(