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" [text]="'serviceAccounts' | i18n"
route="service-accounts" route="service-accounts"
></bit-nav-item> ></bit-nav-item>
<bit-nav-item icon="bwi-trash" [text]="'trash' | i18n" route="trash"></bit-nav-item> <bit-nav-item
<bit-nav-group icon="bwi-cog" [text]="'settings' | i18n"> 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]="'importData' | i18n" route="settings/import"></bit-nav-item>
<bit-nav-item [text]="'exportData' | i18n" route="settings/export"></bit-nav-item> <bit-nav-item [text]="'exportData' | i18n" route="settings/export"></bit-nav-item>
</bit-nav-group> </bit-nav-group>

View File

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

View File

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

View File

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

View File

@ -1,6 +1,9 @@
import { NgModule } from "@angular/core"; import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router"; 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 { SecretsManagerExportComponent } from "./porting/sm-export.component";
import { SecretsManagerImportComponent } from "./porting/sm-import.component"; import { SecretsManagerImportComponent } from "./porting/sm-import.component";
@ -8,15 +11,19 @@ const routes: Routes = [
{ {
path: "import", path: "import",
component: SecretsManagerImportComponent, component: SecretsManagerImportComponent,
canActivate: [OrganizationPermissionsGuard],
data: { data: {
titleId: "importData", titleId: "importData",
organizationPermissions: (org: Organization) => org.isAdmin,
}, },
}, },
{ {
path: "export", path: "export",
component: SecretsManagerExportComponent, component: SecretsManagerExportComponent,
canActivate: [OrganizationPermissionsGuard],
data: { data: {
titleId: "exportData", titleId: "exportData",
organizationPermissions: (org: Organization) => org.isAdmin,
}, },
}, },
]; ];