1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

migrate secrets manager toasts to CL toastService (#10677)

This commit is contained in:
Jordan Aasen 2024-08-23 09:13:25 -07:00 committed by GitHub
parent 0d75b71ea9
commit 2ee51589ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 194 additions and 114 deletions

View File

@ -10,7 +10,7 @@ import {
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { ProjectListView } from "../../models/view/project-list.view"; import { ProjectListView } from "../../models/view/project-list.view";
import { import {
@ -39,6 +39,7 @@ export class ProjectDeleteDialogComponent implements OnInit {
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private dialogService: DialogService, private dialogService: DialogService,
private toastService: ToastService,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -84,7 +85,11 @@ export class ProjectDeleteDialogComponent implements OnInit {
} }
const message = this.data.projects.length === 1 ? "deleteProjectToast" : "deleteProjectsToast"; const message = this.data.projects.length === 1 ? "deleteProjectToast" : "deleteProjectsToast";
this.platformUtilsService.showToast("success", null, this.i18nService.t(message)); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
} }
openBulkStatusDialog(bulkStatusResults: BulkOperationStatus[]) { openBulkStatusDialog(bulkStatusResults: BulkOperationStatus[]) {

View File

@ -5,7 +5,7 @@ import { Router } from "@angular/router";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { BitValidators } from "@bitwarden/components"; import { BitValidators, ToastService } from "@bitwarden/components";
import { ProjectView } from "../../models/view/project.view"; import { ProjectView } from "../../models/view/project.view";
import { ProjectService } from "../../projects/project.service"; import { ProjectService } from "../../projects/project.service";
@ -41,6 +41,7 @@ export class ProjectDialogComponent implements OnInit {
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private router: Router, private router: Router,
private toastService: ToastService,
) {} ) {}
async ngOnInit() { async ngOnInit() {
@ -65,11 +66,11 @@ export class ProjectDialogComponent implements OnInit {
submit = async () => { submit = async () => {
if (!this.data.organizationEnabled) { if (!this.data.organizationEnabled) {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
null, title: null,
this.i18nService.t("projectsCannotCreate"), message: this.i18nService.t("projectsCannotCreate"),
); });
return; return;
} }
@ -92,13 +93,21 @@ export class ProjectDialogComponent implements OnInit {
private async createProject(projectView: ProjectView) { private async createProject(projectView: ProjectView) {
const newProject = await this.projectService.create(this.data.organizationId, projectView); const newProject = await this.projectService.create(this.data.organizationId, projectView);
this.platformUtilsService.showToast("success", null, this.i18nService.t("projectCreated")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("projectCreated"),
});
return newProject; return newProject;
} }
private async updateProject(projectView: ProjectView) { private async updateProject(projectView: ProjectView) {
await this.projectService.update(this.data.organizationId, projectView); await this.projectService.update(this.data.organizationId, projectView);
this.platformUtilsService.showToast("success", null, this.i18nService.t("projectSaved")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("projectSaved"),
});
} }
private getProjectView() { private getProjectView() {

View File

@ -7,7 +7,7 @@ import { MockProxy, mock } from "jest-mock-extended";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { ToastService } from "@bitwarden/components";
import { RouterService } from "../../../../../../../apps/web/src/app/core/router.service"; import { RouterService } from "../../../../../../../apps/web/src/app/core/router.service";
import { ProjectView } from "../../models/view/project.view"; import { ProjectView } from "../../models/view/project.view";
@ -30,7 +30,7 @@ describe("Project Redirect Guard", () => {
let routerService: MockProxy<RouterService>; let routerService: MockProxy<RouterService>;
let projectServiceMock: MockProxy<ProjectService>; let projectServiceMock: MockProxy<ProjectService>;
let i18nServiceMock: MockProxy<I18nService>; let i18nServiceMock: MockProxy<I18nService>;
let platformUtilsService: MockProxy<PlatformUtilsService>; let toastService: MockProxy<ToastService>;
let router: Router; let router: Router;
const smOrg1 = { id: "123", canAccessSecretsManager: true } as Organization; const smOrg1 = { id: "123", canAccessSecretsManager: true } as Organization;
@ -49,7 +49,7 @@ describe("Project Redirect Guard", () => {
routerService = mock<RouterService>(); routerService = mock<RouterService>();
projectServiceMock = mock<ProjectService>(); projectServiceMock = mock<ProjectService>();
i18nServiceMock = mock<I18nService>(); i18nServiceMock = mock<I18nService>();
platformUtilsService = mock<PlatformUtilsService>(); toastService = mock<ToastService>();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
@ -74,7 +74,7 @@ describe("Project Redirect Guard", () => {
{ provide: RouterService, useValue: routerService }, { provide: RouterService, useValue: routerService },
{ provide: ProjectService, useValue: projectServiceMock }, { provide: ProjectService, useValue: projectServiceMock },
{ provide: I18nService, useValue: i18nServiceMock }, { provide: I18nService, useValue: i18nServiceMock },
{ provide: PlatformUtilsService, useValue: platformUtilsService }, { provide: ToastService, useValue: toastService },
], ],
}); });
@ -114,7 +114,11 @@ describe("Project Redirect Guard", () => {
// Act // Act
await router.navigateByUrl("sm/123/projects/123"); await router.navigateByUrl("sm/123/projects/123");
// Assert // Assert
expect(platformUtilsService.showToast).toHaveBeenCalledWith("error", null, "Project not found"); expect(toastService.showToast).toHaveBeenCalledWith({
variant: "error",
title: null,
message: "Project not found",
});
expect(router.url).toBe("/sm/123/projects"); expect(router.url).toBe("/sm/123/projects");
}); });
}); });

View File

@ -2,7 +2,7 @@ import { inject } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router"; import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { ToastService } from "@bitwarden/components";
import { ProjectService } from "../project.service"; import { ProjectService } from "../project.service";
@ -11,7 +11,7 @@ import { ProjectService } from "../project.service";
*/ */
export const projectAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => { export const projectAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => {
const projectService = inject(ProjectService); const projectService = inject(ProjectService);
const platformUtilsService = inject(PlatformUtilsService); const toastService = inject(ToastService);
const i18nService = inject(I18nService); const i18nService = inject(I18nService);
try { try {
@ -20,11 +20,11 @@ export const projectAccessGuard: CanActivateFn = async (route: ActivatedRouteSna
return true; return true;
} }
} catch { } catch {
platformUtilsService.showToast( toastService.showToast({
"error", variant: "error",
null, title: null,
i18nService.t("notFound", i18nService.t("project")), message: i18nService.t("notFound", i18nService.t("project")),
); });
return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]); return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]);
} }
return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]); return createUrlTreeFromSnapshot(route, ["/sm", route.params.organizationId, "projects"]);

View File

@ -7,7 +7,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { AccessPolicySelectorService } from "../../shared/access-policies/access-policy-selector/access-policy-selector.service"; import { AccessPolicySelectorService } from "../../shared/access-policies/access-policy-selector/access-policy-selector.service";
import { import {
@ -73,6 +73,7 @@ export class ProjectPeopleComponent implements OnInit, OnDestroy {
private i18nService: I18nService, private i18nService: I18nService,
private accessPolicySelectorService: AccessPolicySelectorService, private accessPolicySelectorService: AccessPolicySelectorService,
private logService: LogService, private logService: LogService,
private toastService: ToastService,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -129,11 +130,11 @@ export class ProjectPeopleComponent implements OnInit, OnDestroy {
if (showAccessRemovalWarning) { if (showAccessRemovalWarning) {
await this.router.navigate(["sm", this.organizationId, "projects"]); await this.router.navigate(["sm", this.organizationId, "projects"]);
} }
this.platformUtilsService.showToast( this.toastService.showToast({
"success", variant: "success",
null, title: null,
this.i18nService.t("projectAccessUpdated"), message: this.i18nService.t("projectAccessUpdated"),
); });
} catch (e) { } catch (e) {
this.validationService.showError(e); this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies); this.setSelected(this.currentAccessPolicies);

View File

@ -6,6 +6,7 @@ import { combineLatest, Subject, switchMap, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { ToastService } from "@bitwarden/components";
import { ProjectServiceAccountsAccessPoliciesView } from "../../models/view/access-policies/project-service-accounts-access-policies.view"; import { ProjectServiceAccountsAccessPoliciesView } from "../../models/view/access-policies/project-service-accounts-access-policies.view";
import { import {
@ -64,6 +65,7 @@ export class ProjectServiceAccountsComponent implements OnInit, OnDestroy {
private accessPolicyService: AccessPolicyService, private accessPolicyService: AccessPolicyService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService, private i18nService: I18nService,
private toastService: ToastService,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -104,11 +106,11 @@ export class ProjectServiceAccountsComponent implements OnInit, OnDestroy {
this.items = this.getItems(this.potentialGrantees, updatedView); this.items = this.getItems(this.potentialGrantees, updatedView);
this.setSelected(updatedView); this.setSelected(updatedView);
this.platformUtilsService.showToast( this.toastService.showToast({
"success", variant: "success",
null, title: null,
this.i18nService.t("projectAccessUpdated"), message: this.i18nService.t("projectAccessUpdated"),
); });
} catch (e) { } catch (e) {
this.validationService.showError(e); this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies); this.setSelected(this.currentAccessPolicies);

View File

@ -3,7 +3,7 @@ import { Component, Inject } from "@angular/core";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { SecretListView } from "../../models/view/secret-list.view"; import { SecretListView } from "../../models/view/secret-list.view";
import { import {
@ -28,6 +28,7 @@ export class SecretDeleteDialogComponent {
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
@Inject(DIALOG_DATA) private data: SecretDeleteOperation, @Inject(DIALOG_DATA) private data: SecretDeleteOperation,
private dialogService: DialogService, private dialogService: DialogService,
private toastService: ToastService,
) {} ) {}
showSoftDeleteSecretWarning = this.data.secrets.length === 1; showSoftDeleteSecretWarning = this.data.secrets.length === 1;
@ -51,7 +52,11 @@ export class SecretDeleteDialogComponent {
const message = const message =
this.data.secrets.length === 1 ? "softDeleteSuccessToast" : "softDeletesSuccessToast"; this.data.secrets.length === 1 ? "softDeleteSuccessToast" : "softDeletesSuccessToast";
this.platformUtilsService.showToast("success", null, this.i18nService.t(message)); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
this.dialogRef.close(true); this.dialogRef.close(true);
}; };

View File

@ -7,7 +7,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { DialogService, BitValidators } from "@bitwarden/components"; import { DialogService, BitValidators, ToastService } from "@bitwarden/components";
import { SecretAccessPoliciesView } from "../../models/view/access-policies/secret-access-policies.view"; import { SecretAccessPoliciesView } from "../../models/view/access-policies/secret-access-policies.view";
import { ProjectListView } from "../../models/view/project-list.view"; import { ProjectListView } from "../../models/view/project-list.view";
@ -97,6 +97,7 @@ export class SecretDialogComponent implements OnInit, OnDestroy {
private organizationService: OrganizationService, private organizationService: OrganizationService,
private accessPolicyService: AccessPolicyService, private accessPolicyService: AccessPolicyService,
private accessPolicySelectorService: AccessPolicySelectorService, private accessPolicySelectorService: AccessPolicySelectorService,
private toastService: ToastService,
) {} ) {}
get title() { get title() {
@ -139,7 +140,11 @@ export class SecretDialogComponent implements OnInit, OnDestroy {
submit = async () => { submit = async () => {
if (!this.data.organizationEnabled) { if (!this.data.organizationEnabled) {
this.platformUtilsService.showToast("error", null, this.i18nService.t("secretsCannotCreate")); this.toastService.showToast({
variant: "error",
title: null,
message: this.i18nService.t("secretsCannotCreate"),
});
return; return;
} }
@ -318,7 +323,11 @@ export class SecretDialogComponent implements OnInit, OnDestroy {
secretAccessPoliciesView: SecretAccessPoliciesView, secretAccessPoliciesView: SecretAccessPoliciesView,
) { ) {
await this.secretService.create(this.data.organizationId, secretView, secretAccessPoliciesView); await this.secretService.create(this.data.organizationId, secretView, secretAccessPoliciesView);
this.platformUtilsService.showToast("success", null, this.i18nService.t("secretCreated")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("secretCreated"),
});
} }
private getNewProjectView() { private getNewProjectView() {
@ -333,7 +342,11 @@ export class SecretDialogComponent implements OnInit, OnDestroy {
secretAccessPoliciesView: SecretAccessPoliciesView, secretAccessPoliciesView: SecretAccessPoliciesView,
) { ) {
await this.secretService.update(this.data.organizationId, secretView, secretAccessPoliciesView); await this.secretService.update(this.data.organizationId, secretView, secretAccessPoliciesView);
this.platformUtilsService.showToast("success", null, this.i18nService.t("secretEdited")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("secretEdited"),
});
} }
private getSecretView() { private getSecretView() {
@ -417,11 +430,14 @@ export class SecretDialogComponent implements OnInit, OnDestroy {
this.formGroup.markAllAsTouched(); this.formGroup.markAllAsTouched();
if (this.formGroup.invalid && this.tabIndex !== SecretDialogTabType.NameValuePair) { if (this.formGroup.invalid && this.tabIndex !== SecretDialogTabType.NameValuePair) {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
null, title: null,
this.i18nService.t("fieldOnTabRequiresAttention", this.i18nService.t("nameValuePair")), message: this.i18nService.t(
); "fieldOnTabRequiresAttention",
this.i18nService.t("nameValuePair"),
),
});
} }
return this.formGroup.invalid; return this.formGroup.invalid;

View File

@ -12,7 +12,7 @@ import {
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { openUserVerificationPrompt } from "@bitwarden/web-vault/app/auth/shared/components/user-verification"; import { openUserVerificationPrompt } from "@bitwarden/web-vault/app/auth/shared/components/user-verification";
import { ServiceAccountView } from "../../models/view/service-account.view"; import { ServiceAccountView } from "../../models/view/service-account.view";
@ -39,6 +39,7 @@ export class AccessTokenComponent implements OnInit, OnDestroy {
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService, private i18nService: I18nService,
private serviceAccountService: ServiceAccountService, private serviceAccountService: ServiceAccountService,
private toastService: ToastService,
) {} ) {}
ngOnInit() { ngOnInit() {
@ -74,11 +75,11 @@ export class AccessTokenComponent implements OnInit, OnDestroy {
protected async revoke(tokens: AccessTokenView[]) { protected async revoke(tokens: AccessTokenView[]) {
if (!tokens?.length) { if (!tokens?.length) {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
null, title: null,
this.i18nService.t("noAccessTokenSelected"), message: this.i18nService.t("noAccessTokenSelected"),
); });
return; return;
} }
@ -91,7 +92,11 @@ export class AccessTokenComponent implements OnInit, OnDestroy {
tokens.map((t) => t.id), tokens.map((t) => t.id),
); );
this.platformUtilsService.showToast("success", null, this.i18nService.t("accessTokenRevoked")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("accessTokenRevoked"),
});
} }
protected openNewAccessTokenDialog() { protected openNewAccessTokenDialog() {

View File

@ -10,7 +10,7 @@ import {
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { ServiceAccountView } from "../../models/view/service-account.view"; import { ServiceAccountView } from "../../models/view/service-account.view";
import { import {
@ -39,6 +39,7 @@ export class ServiceAccountDeleteDialogComponent {
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private dialogService: DialogService, private dialogService: DialogService,
private toastService: ToastService,
) {} ) {}
get title() { get title() {
@ -81,7 +82,11 @@ export class ServiceAccountDeleteDialogComponent {
this.data.serviceAccounts.length === 1 this.data.serviceAccounts.length === 1
? "deleteMachineAccountToast" ? "deleteMachineAccountToast"
: "deleteMachineAccountsToast"; : "deleteMachineAccountsToast";
this.platformUtilsService.showToast("success", null, this.i18nService.t(message)); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
} }
openBulkStatusDialog(bulkStatusResults: BulkOperationStatus[]) { openBulkStatusDialog(bulkStatusResults: BulkOperationStatus[]) {

View File

@ -4,7 +4,7 @@ import { FormControl, FormGroup, Validators } from "@angular/forms";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { BitValidators } from "@bitwarden/components"; import { BitValidators, ToastService } from "@bitwarden/components";
import { ServiceAccountView } from "../../models/view/service-account.view"; import { ServiceAccountView } from "../../models/view/service-account.view";
import { ServiceAccountService } from "../service-account.service"; import { ServiceAccountService } from "../service-account.service";
@ -43,6 +43,7 @@ export class ServiceAccountDialogComponent implements OnInit {
private serviceAccountService: ServiceAccountService, private serviceAccountService: ServiceAccountService,
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
) {} ) {}
async ngOnInit() { async ngOnInit() {
@ -64,11 +65,11 @@ export class ServiceAccountDialogComponent implements OnInit {
submit = async () => { submit = async () => {
if (!this.data.organizationEnabled) { if (!this.data.organizationEnabled) {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
null, title: null,
this.i18nService.t("machineAccountsCannotCreate"), message: this.i18nService.t("machineAccountsCannotCreate"),
); });
return; return;
} }
@ -93,7 +94,11 @@ export class ServiceAccountDialogComponent implements OnInit {
serviceAccountMessage = this.i18nService.t("machineAccountUpdated"); serviceAccountMessage = this.i18nService.t("machineAccountUpdated");
} }
this.platformUtilsService.showToast("success", null, serviceAccountMessage); this.toastService.showToast({
variant: "success",
title: null,
message: serviceAccountMessage,
});
this.dialogRef.close(); this.dialogRef.close();
}; };

View File

@ -7,7 +7,7 @@ import { MockProxy, mock } from "jest-mock-extended";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { ToastService } from "@bitwarden/components";
import { RouterService } from "../../../../../../../../clients/apps/web/src/app/core/router.service"; import { RouterService } from "../../../../../../../../clients/apps/web/src/app/core/router.service";
import { ServiceAccountView } from "../../models/view/service-account.view"; import { ServiceAccountView } from "../../models/view/service-account.view";
@ -30,7 +30,7 @@ describe("Service account Redirect Guard", () => {
let routerService: MockProxy<RouterService>; let routerService: MockProxy<RouterService>;
let serviceAccountServiceMock: MockProxy<ServiceAccountService>; let serviceAccountServiceMock: MockProxy<ServiceAccountService>;
let i18nServiceMock: MockProxy<I18nService>; let i18nServiceMock: MockProxy<I18nService>;
let platformUtilsService: MockProxy<PlatformUtilsService>; let toastService: MockProxy<ToastService>;
let router: Router; let router: Router;
const smOrg1 = { id: "123", canAccessSecretsManager: true } as Organization; const smOrg1 = { id: "123", canAccessSecretsManager: true } as Organization;
@ -45,7 +45,7 @@ describe("Service account Redirect Guard", () => {
routerService = mock<RouterService>(); routerService = mock<RouterService>();
serviceAccountServiceMock = mock<ServiceAccountService>(); serviceAccountServiceMock = mock<ServiceAccountService>();
i18nServiceMock = mock<I18nService>(); i18nServiceMock = mock<I18nService>();
platformUtilsService = mock<PlatformUtilsService>(); toastService = mock<ToastService>();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
@ -70,7 +70,7 @@ describe("Service account Redirect Guard", () => {
{ provide: RouterService, useValue: routerService }, { provide: RouterService, useValue: routerService },
{ provide: ServiceAccountService, useValue: serviceAccountServiceMock }, { provide: ServiceAccountService, useValue: serviceAccountServiceMock },
{ provide: I18nService, useValue: i18nServiceMock }, { provide: I18nService, useValue: i18nServiceMock },
{ provide: PlatformUtilsService, useValue: platformUtilsService }, { provide: ToastService, useValue: toastService },
], ],
}); });
@ -112,11 +112,11 @@ describe("Service account Redirect Guard", () => {
// Act // Act
await router.navigateByUrl("sm/123/machine-accounts/123"); await router.navigateByUrl("sm/123/machine-accounts/123");
// Assert // Assert
expect(platformUtilsService.showToast).toHaveBeenCalledWith( expect(toastService.showToast).toHaveBeenCalledWith({
"error", variant: "error",
null, title: null,
"Service account not found", message: "Service account not found",
); });
expect(router.url).toBe("/sm/123/machine-accounts"); expect(router.url).toBe("/sm/123/machine-accounts");
}); });
}); });

View File

@ -2,7 +2,7 @@ import { inject } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router"; import { ActivatedRouteSnapshot, CanActivateFn, createUrlTreeFromSnapshot } from "@angular/router";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { ToastService } from "@bitwarden/components";
import { ServiceAccountService } from "../service-account.service"; import { ServiceAccountService } from "../service-account.service";
@ -11,7 +11,7 @@ import { ServiceAccountService } from "../service-account.service";
*/ */
export const serviceAccountAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => { export const serviceAccountAccessGuard: CanActivateFn = async (route: ActivatedRouteSnapshot) => {
const serviceAccountService = inject(ServiceAccountService); const serviceAccountService = inject(ServiceAccountService);
const platformUtilsService = inject(PlatformUtilsService); const toastService = inject(ToastService);
const i18nService = inject(I18nService); const i18nService = inject(I18nService);
try { try {
@ -23,11 +23,11 @@ export const serviceAccountAccessGuard: CanActivateFn = async (route: ActivatedR
return true; return true;
} }
} catch { } catch {
platformUtilsService.showToast( toastService.showToast({
"error", variant: "error",
null, title: null,
i18nService.t("notFound", i18nService.t("machineAccount")), message: i18nService.t("notFound", i18nService.t("machineAccount")),
); });
return createUrlTreeFromSnapshot(route, [ return createUrlTreeFromSnapshot(route, [
"/sm", "/sm",

View File

@ -6,7 +6,7 @@ import { combineLatest, Subject, switchMap, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { ServiceAccountPeopleAccessPoliciesView } from "../../models/view/access-policies/service-account-people-access-policies.view"; import { ServiceAccountPeopleAccessPoliciesView } from "../../models/view/access-policies/service-account-people-access-policies.view";
import { AccessPolicySelectorService } from "../../shared/access-policies/access-policy-selector/access-policy-selector.service"; import { AccessPolicySelectorService } from "../../shared/access-policies/access-policy-selector/access-policy-selector.service";
@ -71,6 +71,7 @@ export class ServiceAccountPeopleComponent implements OnInit, OnDestroy {
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService, private i18nService: I18nService,
private accessPolicySelectorService: AccessPolicySelectorService, private accessPolicySelectorService: AccessPolicySelectorService,
private toastService: ToastService,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -126,11 +127,11 @@ export class ServiceAccountPeopleComponent implements OnInit, OnDestroy {
this.currentAccessPolicies = convertToAccessPolicyItemViews(peoplePoliciesViews); this.currentAccessPolicies = convertToAccessPolicyItemViews(peoplePoliciesViews);
this.platformUtilsService.showToast( this.toastService.showToast({
"success", variant: "success",
null, title: null,
this.i18nService.t("machineAccountAccessUpdated"), message: this.i18nService.t("machineAccountAccessUpdated"),
); });
} catch (e) { } catch (e) {
this.validationService.showError(e); this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies); this.setSelected(this.currentAccessPolicies);

View File

@ -6,6 +6,7 @@ import { combineLatest, Subject, switchMap, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { ToastService } from "@bitwarden/components";
import { ServiceAccountGrantedPoliciesView } from "../../models/view/access-policies/service-account-granted-policies.view"; import { ServiceAccountGrantedPoliciesView } from "../../models/view/access-policies/service-account-granted-policies.view";
import { import {
@ -63,6 +64,7 @@ export class ServiceAccountProjectsComponent implements OnInit, OnDestroy {
private accessPolicyService: AccessPolicyService, private accessPolicyService: AccessPolicyService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService, private i18nService: I18nService,
private toastService: ToastService,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -103,11 +105,11 @@ export class ServiceAccountProjectsComponent implements OnInit, OnDestroy {
this.currentAccessPolicies = convertGrantedPoliciesToAccessPolicyItemViews(grantedViews); this.currentAccessPolicies = convertGrantedPoliciesToAccessPolicyItemViews(grantedViews);
this.platformUtilsService.showToast( this.toastService.showToast({
"success", variant: "success",
null, title: null,
this.i18nService.t("serviceAccountAccessUpdated"), message: this.i18nService.t("serviceAccountAccessUpdated"),
); });
} catch (e) { } catch (e) {
this.validationService.showError(e); this.validationService.showError(e);
this.setSelected(this.currentAccessPolicies); this.setSelected(this.currentAccessPolicies);

View File

@ -4,7 +4,7 @@ import { Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { TableDataSource } from "@bitwarden/components"; import { TableDataSource, ToastService } from "@bitwarden/components";
import { import {
ServiceAccountSecretsDetailsView, ServiceAccountSecretsDetailsView,
@ -47,6 +47,7 @@ export class ServiceAccountsListComponent implements OnDestroy {
constructor( constructor(
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
) { ) {
this.selection.changed this.selection.changed
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
@ -85,11 +86,11 @@ export class ServiceAccountsListComponent implements OnDestroy {
this.serviceAccounts.filter((sa) => this.selection.isSelected(sa.id)), this.serviceAccounts.filter((sa) => this.selection.isSelected(sa.id)),
); );
} else { } else {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
this.i18nService.t("errorOccurred"), title: this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected"), message: this.i18nService.t("nothingSelected"),
); });
} }
} }
} }

View File

@ -8,7 +8,7 @@ import { FileDownloadService } from "@bitwarden/common/platform/abstractions/fil
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService, ToastService } from "@bitwarden/components";
import { openUserVerificationPrompt } from "@bitwarden/web-vault/app/auth/shared/components/user-verification"; import { openUserVerificationPrompt } from "@bitwarden/web-vault/app/auth/shared/components/user-verification";
import { SecretsManagerPortingApiService } from "../services/sm-porting-api.service"; import { SecretsManagerPortingApiService } from "../services/sm-porting-api.service";
@ -44,6 +44,7 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
private logService: LogService, private logService: LogService,
private dialogService: DialogService, private dialogService: DialogService,
private secretsManagerApiService: SecretsManagerPortingApiService, private secretsManagerApiService: SecretsManagerPortingApiService,
private toastService: ToastService,
) {} ) {}
async ngOnInit() { async ngOnInit() {
@ -85,7 +86,11 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
const exportData = await this.secretsManagerApiService.export(this.orgId); const exportData = await this.secretsManagerApiService.export(this.orgId);
await this.downloadFile(exportData, fileExtension); await this.downloadFile(exportData, fileExtension);
this.platformUtilsService.showToast("success", null, this.i18nService.t("dataExportSuccess")); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("dataExportSuccess"),
});
} }
private async downloadFile(data: string, format: string) { private async downloadFile(data: string, format: string) {

View File

@ -4,7 +4,7 @@ import { map } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { TableDataSource } from "@bitwarden/components"; import { TableDataSource, ToastService } from "@bitwarden/components";
import { ProjectListView } from "../models/view/project-list.view"; import { ProjectListView } from "../models/view/project-list.view";
@ -43,6 +43,7 @@ export class ProjectsListComponent {
constructor( constructor(
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
) {} ) {}
isAllSelected() { isAllSelected() {
@ -72,11 +73,11 @@ export class ProjectsListComponent {
this.projects.filter((project) => this.selection.isSelected(project.id)), this.projects.filter((project) => this.selection.isSelected(project.id)),
); );
} else { } else {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
this.i18nService.t("errorOccurred"), title: this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected"), message: this.i18nService.t("nothingSelected"),
); });
} }
} }

View File

@ -5,7 +5,7 @@ import { Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { TableDataSource } from "@bitwarden/components"; import { TableDataSource, ToastService } from "@bitwarden/components";
import { SecretListView } from "../models/view/secret-list.view"; import { SecretListView } from "../models/view/secret-list.view";
import { SecretService } from "../secrets/secret.service"; import { SecretService } from "../secrets/secret.service";
@ -53,6 +53,7 @@ export class SecretsListComponent implements OnDestroy {
constructor( constructor(
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
) { ) {
this.selection.changed this.selection.changed
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
@ -87,11 +88,11 @@ export class SecretsListComponent implements OnDestroy {
this.secrets.filter((secret) => this.selection.isSelected(secret.id)), this.secrets.filter((secret) => this.selection.isSelected(secret.id)),
); );
} else { } else {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
this.i18nService.t("errorOccurred"), title: this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected"), message: this.i18nService.t("nothingSelected"),
); });
} }
} }
@ -99,11 +100,11 @@ export class SecretsListComponent implements OnDestroy {
if (this.selection.selected.length >= 1) { if (this.selection.selected.length >= 1) {
this.restoreSecretsEvent.emit(this.selection.selected); this.restoreSecretsEvent.emit(this.selection.selected);
} else { } else {
this.platformUtilsService.showToast( this.toastService.showToast({
"error", variant: "error",
this.i18nService.t("errorOccurred"), title: this.i18nService.t("errorOccurred"),
this.i18nService.t("nothingSelected"), message: this.i18nService.t("nothingSelected"),
); });
} }
} }

View File

@ -3,6 +3,7 @@ import { Component, Inject } from "@angular/core";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";
import { SecretService } from "../../secrets/secret.service"; import { SecretService } from "../../secrets/secret.service";
@ -21,6 +22,7 @@ export class SecretHardDeleteDialogComponent {
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
@Inject(DIALOG_DATA) public data: SecretHardDeleteOperation, @Inject(DIALOG_DATA) public data: SecretHardDeleteOperation,
private toastService: ToastService,
) {} ) {}
get title() { get title() {
@ -36,6 +38,10 @@ export class SecretHardDeleteDialogComponent {
const message = const message =
this.data.secretIds.length === 1 ? "hardDeleteSuccessToast" : "hardDeletesSuccessToast"; this.data.secretIds.length === 1 ? "hardDeleteSuccessToast" : "hardDeletesSuccessToast";
this.dialogRef.close(this.data.secretIds); this.dialogRef.close(this.data.secretIds);
this.platformUtilsService.showToast("success", null, this.i18nService.t(message)); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
}; };
} }

View File

@ -3,6 +3,7 @@ import { Component, Inject } from "@angular/core";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";
import { SecretService } from "../../secrets/secret.service"; import { SecretService } from "../../secrets/secret.service";
@ -21,6 +22,7 @@ export class SecretRestoreDialogComponent {
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
@Inject(DIALOG_DATA) public data: SecretRestoreOperation, @Inject(DIALOG_DATA) public data: SecretRestoreOperation,
private toastService: ToastService,
) {} ) {}
get title() { get title() {
@ -35,6 +37,10 @@ export class SecretRestoreDialogComponent {
? "secretRestoredSuccessToast" ? "secretRestoredSuccessToast"
: "secretsRestoredSuccessToast"; : "secretsRestoredSuccessToast";
this.dialogRef.close(this.data.secretIds); this.dialogRef.close(this.data.secretIds);
this.platformUtilsService.showToast("success", null, this.i18nService.t(message)); this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(message),
});
}; };
} }