1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

SM-528: Fix SM Import / Export Error Messaging (#4833)

* SM-528: Remove try catch to use default error handling

* SM-528: Add admin check on import / export

* SM-528: Hide settings nav section unless admin

* SM-528: Refactor observable in navigation component

* SM-528: Hide SM Trash from nav menu if not admin

* SM-528: clean up navigation.component.ts
This commit is contained in:
Colton Hurst 2023-03-01 09:39:32 -05:00 committed by GitHub
parent abbfb0696f
commit 667d3fccc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 25 deletions

View File

@ -10,8 +10,13 @@
[text]="'serviceAccounts' | i18n"
route="service-accounts"
></bit-nav-item>
<bit-nav-item icon="bwi-trash" [text]="'trash' | i18n" route="trash"></bit-nav-item>
<bit-nav-group icon="bwi-cog" [text]="'settings' | i18n">
<bit-nav-item
icon="bwi-trash"
[text]="'trash' | i18n"
route="trash"
*ngIf="isAdmin$ | async"
></bit-nav-item>
<bit-nav-group icon="bwi-cog" [text]="'settings' | i18n" *ngIf="isAdmin$ | async">
<bit-nav-item [text]="'importData' | i18n" route="settings/import"></bit-nav-item>
<bit-nav-item [text]="'exportData' | i18n" route="settings/export"></bit-nav-item>
</bit-nav-group>

View File

@ -1,5 +1,8 @@
import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { map } from "rxjs";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/models/domain/organization";
import { SecretsManagerLogo } from "./secrets-manager-logo";
@ -9,7 +12,13 @@ import { SecretsManagerLogo } from "./secrets-manager-logo";
templateUrl: "./navigation.component.html",
})
export class NavigationComponent {
protected isAdmin$ = this.route.params.pipe(
map((params) => this.organizationService.get(params.organizationId)?.isAdmin)
);
protected readonly logo = SecretsManagerLogo;
protected orgFilter = (org: Organization) => org.canAccessSecretsManager;
constructor(private route: ActivatedRoute, private organizationService: OrganizationService) {}
}

View File

@ -76,7 +76,6 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
};
private async doExport() {
try {
const exportData = await this.secretsManagerApiService.export(
this.orgId,
this.formGroup.get("format").value
@ -84,9 +83,6 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
await this.downloadFile(exportData, this.formGroup.get("format").value);
this.platformUtilsService.showToast("success", null, this.i18nService.t("dataExportSuccess"));
} catch (e) {
this.logService.error(e);
}
}
private async downloadFile(data: string, format: string) {

View File

@ -30,19 +30,13 @@ export class SecretsManagerPortingApiService {
) {}
async export(organizationId: string, exportFormat = "json"): Promise<string> {
let response = {};
try {
response = await this.apiService.send(
const response = await this.apiService.send(
"GET",
"/sm/" + organizationId + "/export?format=" + exportFormat,
null,
true,
true
);
} catch (error) {
return null;
}
return JSON.stringify(
await this.decryptExport(organizationId, new SecretsManagerExportResponse(response)),

View File

@ -1,6 +1,9 @@
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { Organization } from "@bitwarden/common/models/domain/organization";
import { OrganizationPermissionsGuard } from "@bitwarden/web-vault/app/organizations/guards/org-permissions.guard";
import { SecretsManagerExportComponent } from "./porting/sm-export.component";
import { SecretsManagerImportComponent } from "./porting/sm-import.component";
@ -8,15 +11,19 @@ const routes: Routes = [
{
path: "import",
component: SecretsManagerImportComponent,
canActivate: [OrganizationPermissionsGuard],
data: {
titleId: "importData",
organizationPermissions: (org: Organization) => org.isAdmin,
},
},
{
path: "export",
component: SecretsManagerExportComponent,
canActivate: [OrganizationPermissionsGuard],
data: {
titleId: "exportData",
organizationPermissions: (org: Organization) => org.isAdmin,
},
},
];