mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
* Rename service-factory folder * Move cryptographic service factories * Move crypto models * Move crypto services * Move domain base class * Platform code owners * Move desktop log services * Move log files * Establish component library ownership * Move background listeners * Move background background * Move localization to Platform * Move browser alarms to Platform * Move browser state to Platform * Move CLI state to Platform * Move Desktop native concerns to Platform * Move flag and misc to Platform * Lint fixes * Move electron state to platform * Move web state to Platform * Move lib state to Platform * Fix broken tests * Rename interface to idiomatic TS * `npm run prettier` 🤖 * Resolve review feedback * Set platform as owners of web core and shared * Expand moved services * Fix test types --------- Co-authored-by: Hinton <hinton@users.noreply.github.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
@Component({
|
|
selector: "app-update-license",
|
|
templateUrl: "update-license.component.html",
|
|
})
|
|
export class UpdateLicenseComponent {
|
|
@Input() organizationId: string;
|
|
@Input() showCancel = true;
|
|
@Output() onUpdated = new EventEmitter();
|
|
@Output() onCanceled = new EventEmitter();
|
|
|
|
formPromise: Promise<void>;
|
|
|
|
constructor(
|
|
private apiService: ApiService,
|
|
private i18nService: I18nService,
|
|
private platformUtilsService: PlatformUtilsService,
|
|
private logService: LogService,
|
|
private organizationApiService: OrganizationApiServiceAbstraction
|
|
) {}
|
|
|
|
async submit() {
|
|
const fileEl = document.getElementById("file") as HTMLInputElement;
|
|
const files = fileEl.files;
|
|
if (files == null || files.length === 0) {
|
|
this.platformUtilsService.showToast(
|
|
"error",
|
|
this.i18nService.t("errorOccurred"),
|
|
this.i18nService.t("selectFile")
|
|
);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const fd = new FormData();
|
|
fd.append("license", files[0]);
|
|
|
|
let updatePromise: Promise<void | unknown> = null;
|
|
if (this.organizationId == null) {
|
|
updatePromise = this.apiService.postAccountLicense(fd);
|
|
} else {
|
|
updatePromise = this.organizationApiService.updateLicense(this.organizationId, fd);
|
|
}
|
|
|
|
this.formPromise = updatePromise.then(() => {
|
|
return this.apiService.refreshIdentityToken();
|
|
});
|
|
|
|
await this.formPromise;
|
|
this.platformUtilsService.showToast(
|
|
"success",
|
|
null,
|
|
this.i18nService.t("licenseUploadSuccess")
|
|
);
|
|
this.onUpdated.emit();
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
}
|
|
}
|
|
|
|
cancel() {
|
|
this.onCanceled.emit();
|
|
}
|
|
}
|