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

[feature] Implement scope warning for exports (#688)

* [feature] Add a hasOrganizations() service method

* [feature] Add a component to warn users about export scope
This commit is contained in:
Addison Beck 2022-02-22 22:56:46 -05:00 committed by GitHub
parent 1fb3d54014
commit 78b5f15042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,5 @@
<ng-container *ngIf="show">
<app-callout type="info" title="{{ scopeConfig.title | i18n }}">
{{ scopeConfig.description | i18n: scopeConfig.scopeIdentifier }}
</app-callout>
</ng-container>

View File

@ -0,0 +1,43 @@
import { Component, Input, OnInit } from "@angular/core";
import { OrganizationService } from "jslib-common/abstractions/organization.service";
import { StateService } from "jslib-common/abstractions/state.service";
@Component({
selector: "app-export-scope-callout",
templateUrl: "export-scope-callout.component.html",
})
export class ExportScopeCalloutComponent implements OnInit {
@Input() organizationId: string = null;
show: boolean = false;
scopeConfig: {
title: string;
description: string;
scopeIdentifier: string;
};
constructor(
protected organizationService: OrganizationService,
protected stateService: StateService
) {}
async ngOnInit(): Promise<void> {
if (!(await this.organizationService.hasOrganizations())) {
return;
}
this.scopeConfig =
this.organizationId != null
? {
title: "exportingOrganizationVaultTitle",
description: "exportingOrganizationVaultDescription",
scopeIdentifier: (await this.organizationService.get(this.organizationId)).name,
}
: {
title: "exportingPersonalVaultTitle",
description: "exportingPersonalVaultDescription",
scopeIdentifier: await this.stateService.getEmail(),
};
this.show = true;
}
}

View File

@ -7,4 +7,5 @@ export abstract class OrganizationService {
getAll: (userId?: string) => Promise<Organization[]>; getAll: (userId?: string) => Promise<Organization[]>;
save: (orgs: { [id: string]: OrganizationData }) => Promise<any>; save: (orgs: { [id: string]: OrganizationData }) => Promise<any>;
canManageSponsorships: () => Promise<boolean>; canManageSponsorships: () => Promise<boolean>;
hasOrganizations: (userId?: string) => Promise<boolean>;
} }

View File

@ -47,4 +47,9 @@ export class OrganizationService implements OrganizationServiceAbstraction {
(o) => o.familySponsorshipAvailable || o.familySponsorshipFriendlyName !== null (o) => o.familySponsorshipAvailable || o.familySponsorshipFriendlyName !== null
); );
} }
async hasOrganizations(userId?: string): Promise<boolean> {
const organizations = await this.getAll(userId);
return organizations.length > 0;
}
} }