2018-07-16 18:42:49 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ComponentFactoryResolver,
|
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
|
|
|
} from '@angular/core';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2018-07-16 18:42:49 +02:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
|
|
import { SyncService } from 'jslib-common/abstractions/sync.service';
|
2018-07-16 18:42:49 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { OrganizationKeysRequest } from 'jslib-common/models/request/organizationKeysRequest';
|
|
|
|
import { OrganizationUpdateRequest } from 'jslib-common/models/request/organizationUpdateRequest';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { OrganizationResponse } from 'jslib-common/models/response/organizationResponse';
|
2018-07-16 18:42:49 +02:00
|
|
|
|
|
|
|
import { ModalComponent } from '../../modal.component';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2020-11-10 22:13:42 +01:00
|
|
|
import { ApiKeyComponent } from '../../settings/api-key.component';
|
2018-09-25 15:12:24 +02:00
|
|
|
import { PurgeVaultComponent } from '../../settings/purge-vault.component';
|
2020-06-13 01:33:29 +02:00
|
|
|
import { TaxInfoComponent } from '../../settings/tax-info.component';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2018-07-16 18:42:49 +02:00
|
|
|
import { DeleteOrganizationComponent } from './delete-organization.component';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-org-account',
|
|
|
|
templateUrl: 'account.component.html',
|
|
|
|
})
|
|
|
|
export class AccountComponent {
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild('deleteOrganizationTemplate', { read: ViewContainerRef, static: true }) deleteModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('purgeOrganizationTemplate', { read: ViewContainerRef, static: true }) purgeModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('apiKeyTemplate', { read: ViewContainerRef, static: true }) apiKeyModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('rotateApiKeyTemplate', { read: ViewContainerRef, static: true }) rotateApiKeyModalRef: ViewContainerRef;
|
2020-06-13 01:33:29 +02:00
|
|
|
@ViewChild(TaxInfoComponent) taxInfo: TaxInfoComponent;
|
2018-07-16 18:42:49 +02:00
|
|
|
|
2020-08-28 17:22:30 +02:00
|
|
|
selfHosted = false;
|
2018-07-16 18:42:49 +02:00
|
|
|
loading = true;
|
2019-03-07 17:18:45 +01:00
|
|
|
canUseApi = false;
|
2018-07-16 18:42:49 +02:00
|
|
|
org: OrganizationResponse;
|
|
|
|
formPromise: Promise<any>;
|
2020-06-17 19:35:39 +02:00
|
|
|
taxFormPromise: Promise<any>;
|
2018-07-16 18:42:49 +02:00
|
|
|
|
|
|
|
private organizationId: string;
|
|
|
|
private modal: ModalComponent = null;
|
|
|
|
|
|
|
|
constructor(private componentFactoryResolver: ComponentFactoryResolver,
|
|
|
|
private apiService: ApiService, private i18nService: I18nService,
|
2021-04-14 23:43:40 +02:00
|
|
|
private toasterService: ToasterService, private route: ActivatedRoute,
|
2021-06-02 18:35:49 +02:00
|
|
|
private syncService: SyncService, private platformUtilsService: PlatformUtilsService,
|
|
|
|
private cryptoService: CryptoService) { }
|
2018-07-16 18:42:49 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2020-08-28 17:22:30 +02:00
|
|
|
this.selfHosted = this.platformUtilsService.isSelfHost();
|
2021-02-03 18:41:33 +01:00
|
|
|
this.route.parent.parent.params.subscribe(async params => {
|
2018-07-16 18:42:49 +02:00
|
|
|
this.organizationId = params.organizationId;
|
|
|
|
try {
|
|
|
|
this.org = await this.apiService.getOrganization(this.organizationId);
|
2019-03-07 17:18:45 +01:00
|
|
|
this.canUseApi = this.org.useApi;
|
2018-07-16 18:42:49 +02:00
|
|
|
} catch { }
|
|
|
|
});
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
try {
|
|
|
|
const request = new OrganizationUpdateRequest();
|
|
|
|
request.name = this.org.name;
|
|
|
|
request.businessName = this.org.businessName;
|
|
|
|
request.billingEmail = this.org.billingEmail;
|
2020-08-12 22:46:18 +02:00
|
|
|
request.identifier = this.org.identifier;
|
2021-06-02 18:35:49 +02:00
|
|
|
|
|
|
|
// Backfill pub/priv key if necessary
|
|
|
|
if (!this.org.hasPublicAndPrivateKeys) {
|
|
|
|
const orgShareKey = await this.cryptoService.getOrgKey(this.organizationId);
|
|
|
|
const orgKeys = await this.cryptoService.makeKeyPair(orgShareKey);
|
|
|
|
request.keys = new OrganizationKeysRequest(orgKeys[0], orgKeys[1].encryptedString);
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:42:49 +02:00
|
|
|
this.formPromise = this.apiService.putOrganization(this.organizationId, request).then(() => {
|
|
|
|
return this.syncService.fullSync(true);
|
|
|
|
});
|
|
|
|
await this.formPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('organizationUpdated'));
|
|
|
|
} catch { }
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:24:05 +02:00
|
|
|
async submitTaxInfo() {
|
2020-06-17 19:35:39 +02:00
|
|
|
this.taxFormPromise = this.taxInfo.submitTaxInfo();
|
|
|
|
await this.taxFormPromise;
|
2020-06-08 23:24:05 +02:00
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('taxInfoUpdated'));
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:42:49 +02:00
|
|
|
deleteOrganization() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.deleteModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<DeleteOrganizationComponent>(
|
|
|
|
DeleteOrganizationComponent, this.deleteModalRef);
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
2018-09-25 15:12:24 +02:00
|
|
|
|
|
|
|
purgeVault() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.purgeModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<PurgeVaultComponent>(PurgeVaultComponent, this.purgeModalRef);
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
2019-03-07 17:18:45 +01:00
|
|
|
|
|
|
|
viewApiKey() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.apiKeyModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<ApiKeyComponent>(ApiKeyComponent, this.apiKeyModalRef);
|
2020-11-10 22:13:42 +01:00
|
|
|
childComponent.keyType = 'organization';
|
|
|
|
childComponent.entityId = this.organizationId;
|
|
|
|
childComponent.postKey = this.apiService.postOrganizationApiKey.bind(this.apiService);
|
|
|
|
childComponent.scope = 'api.organization';
|
|
|
|
childComponent.grantType = 'client_credentials';
|
|
|
|
childComponent.apiKeyTitle = 'apiKey';
|
|
|
|
childComponent.apiKeyWarning = 'apiKeyWarning';
|
|
|
|
childComponent.apiKeyDescription = 'apiKeyDesc';
|
2019-03-07 17:18:45 +01:00
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
rotateApiKey() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.rotateApiKeyModalRef.createComponent(factory).instance;
|
2020-11-10 22:13:42 +01:00
|
|
|
const childComponent = this.modal.show<ApiKeyComponent>(ApiKeyComponent, this.rotateApiKeyModalRef);
|
|
|
|
childComponent.keyType = 'organization';
|
|
|
|
childComponent.isRotation = true;
|
|
|
|
childComponent.entityId = this.organizationId;
|
|
|
|
childComponent.postKey = this.apiService.postOrganizationRotateApiKey.bind(this.apiService);
|
|
|
|
childComponent.scope = 'api.organization';
|
|
|
|
childComponent.grantType = 'client_credentials';
|
|
|
|
childComponent.apiKeyTitle = 'apiKey';
|
|
|
|
childComponent.apiKeyWarning = 'apiKeyWarning';
|
|
|
|
childComponent.apiKeyDescription = 'apiKeyRotateDesc';
|
2019-03-07 17:18:45 +01:00
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
2018-07-16 18:42:49 +02:00
|
|
|
}
|