bitwarden-estensione-browser/apps/web/src/app/organizations/settings/download-license.component.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-12-17 15:57:11 +01:00
import { Component, EventEmitter, Input, Output } from "@angular/core";
2019-03-20 14:56:50 +01:00
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
2022-06-14 17:10:53 +02:00
import { LogService } from "@bitwarden/common/abstractions/log.service";
2019-03-20 14:56:50 +01:00
@Component({
2021-12-17 15:57:11 +01:00
selector: "app-download-license",
templateUrl: "download-license.component.html",
2019-03-20 14:56:50 +01:00
})
export class DownloadLicenseComponent {
2021-12-17 15:57:11 +01:00
@Input() organizationId: string;
@Output() onDownloaded = new EventEmitter();
@Output() onCanceled = new EventEmitter();
2019-03-20 14:56:50 +01:00
2021-12-17 15:57:11 +01:00
installationId: string;
formPromise: Promise<any>;
2019-03-20 14:56:50 +01:00
2021-12-17 15:57:11 +01:00
constructor(
private apiService: ApiService,
private fileDownloadService: FileDownloadService,
2021-12-17 15:57:11 +01:00
private logService: LogService
) {}
2019-03-20 14:56:50 +01:00
2021-12-17 15:57:11 +01:00
async submit() {
if (this.installationId == null || this.installationId === "") {
return;
2019-03-20 14:56:50 +01:00
}
2021-12-17 15:57:11 +01:00
try {
this.formPromise = this.apiService.getOrganizationLicense(
this.organizationId,
this.installationId
);
const license = await this.formPromise;
const licenseString = JSON.stringify(license, null, 2);
this.fileDownloadService.download({
fileName: "bitwarden_organization_license.json",
blobData: licenseString,
});
2021-12-17 15:57:11 +01:00
this.onDownloaded.emit();
} catch (e) {
this.logService.error(e);
2019-03-20 14:56:50 +01:00
}
2021-12-17 15:57:11 +01:00
}
cancel() {
this.onCanceled.emit();
}
2019-03-20 14:56:50 +01:00
}