Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1168] Update access policy selector to disable on submit #8519

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form [formGroup]="formGroup" [bitSubmit]="submit">
<form [formGroup]="formGroup" [bitSubmit]="submit" *ngIf="!loading; else spinner">
<div class="tw-w-2/5">
<p class="tw-mt-8" *ngIf="!loading">
{{ "projectPeopleDescription" | i18n }}
Expand All @@ -19,3 +19,9 @@
</button>
</div>
</form>

<ng-template #spinner>
<div class="tw-items-center tw-justify-center tw-pt-64 tw-text-center">
<i class="bwi bwi-spinner bwi-spin bwi-3x"></i>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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";

Check warning on line 4 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L4

Added line #L4 was not covered by tests

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand Down Expand Up @@ -37,11 +37,9 @@
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 () => {
await this.router.navigate(["/sm", this.organizationId, "projects"]);
return [];

Check warning on line 42 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L40-L42

Added lines #L40 - L42 were not covered by tests
}),
);

Expand Down Expand Up @@ -99,25 +97,28 @@
if (this.formGroup.invalid) {
return;
}
const formValues = this.formGroup.value.accessPolicies;
this.formGroup.disable();

Check warning on line 101 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L100-L101

Added lines #L100 - L101 were not covered by tests

const showAccessRemovalWarning =
await this.accessPolicySelectorService.showAccessRemovalWarning(
this.organizationId,
this.formGroup.value.accessPolicies,
formValues,
);

if (showAccessRemovalWarning) {
const confirmed = await this.showWarning();
if (!confirmed) {
this.setSelected(this.currentAccessPolicies);
this.formGroup.enable();

Check warning on line 113 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L113

Added line #L113 was not covered by tests
return;
}
}

try {
const projectPeopleView = convertToProjectPeopleAccessPoliciesView(
this.projectId,
this.formGroup.value.accessPolicies,
formValues,
);
const peoplePoliciesViews = await this.accessPolicyService.putProjectPeopleAccessPolicies(
this.projectId,
Expand All @@ -126,9 +127,7 @@
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"]);

Check warning on line 130 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L130

Added line #L130 was not covered by tests
}
this.platformUtilsService.showToast(
"success",
Expand All @@ -139,6 +138,7 @@
this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies);
}
this.formGroup.enable();

Check warning on line 141 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-people.component.ts#L141

Added line #L141 was not covered by tests
};

private setSelected(policiesToSelect: ApItemViewType[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form [formGroup]="formGroup" [bitSubmit]="submit">
<form [formGroup]="formGroup" [bitSubmit]="submit" *ngIf="!loading; else spinner">
<div class="tw-w-2/5">
<p class="tw-mt-8" *ngIf="!loading">
{{ "machineAccountPeopleDescription" | i18n }}
Expand All @@ -20,3 +20,9 @@
</button>
</div>
</form>

<ng-template #spinner>
<div class="tw-items-center tw-justify-center tw-pt-64 tw-text-center">
<i class="bwi bwi-spinner bwi-spin bwi-3x"></i>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { combineLatest, Subject, switchMap, takeUntil } from "rxjs";

Check warning on line 4 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts#L4

Added line #L4 was not covered by tests

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand Down Expand Up @@ -40,12 +40,6 @@
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;
}),
);

private potentialGrantees$ = combineLatest([this.route.params]).pipe(
Expand Down Expand Up @@ -101,29 +95,32 @@
if (this.isFormInvalid()) {
return;
}
const formValues = this.formGroup.value.accessPolicies;
this.formGroup.disable();

Check warning on line 99 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts#L98-L99

Added lines #L98 - L99 were not covered by tests

const showAccessRemovalWarning =
await this.accessPolicySelectorService.showAccessRemovalWarning(
this.organizationId,
this.formGroup.value.accessPolicies,
formValues,
);

if (
await this.handleAccessRemovalWarning(showAccessRemovalWarning, this.currentAccessPolicies)
) {
this.formGroup.enable();

Check warning on line 110 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts#L110

Added line #L110 was not covered by tests
return;
}

try {
const peoplePoliciesViews = await this.updateServiceAccountPeopleAccessPolicies(
this.serviceAccountId,
this.formGroup.value.accessPolicies,
formValues,
);

await this.handleAccessTokenAvailableWarning(
showAccessRemovalWarning,
this.currentAccessPolicies,
this.formGroup.value.accessPolicies,
formValues,
);

this.currentAccessPolicies = convertToAccessPolicyItemViews(peoplePoliciesViews);
Expand All @@ -137,6 +134,7 @@
this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies);
}
this.formGroup.enable();

Check warning on line 137 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts#L137

Added line #L137 was not covered by tests
};

private setSelected(policiesToSelect: ApItemViewType[]) {
Expand Down Expand Up @@ -198,9 +196,7 @@
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"]);

Check warning on line 199 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/people/service-account-people.component.ts#L199

Added line #L199 was not covered by tests
} else if (
this.accessPolicySelectorService.isAccessRemoval(currentAccessPolicies, selectedPolicies)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
bitIconButton="bwi-close"
buttonType="main"
size="default"
[disabled]="disabled"
[attr.title]="'remove' | i18n"
[attr.aria-label]="'remove' | i18n"
(click)="selectionList.deselectItem(item.id); handleBlur()"
Expand Down Expand Up @@ -84,7 +85,14 @@
</bit-form-field>

<div class="tw-ml-3 tw-mt-7 tw-shrink-0">
<button type="button" bitButton buttonType="secondary" (click)="addButton()">
<button
type="button"
bitButton
buttonType="secondary"
[loading]="loading"
[disabled]="disabled"
(click)="addButton()"
>
{{ "add" | i18n }}
</button>
</div>
Expand Down