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