1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-28 10:55:27 +02:00
bitwarden-browser/src/app/organizations/settings/account.component.ts

146 lines
5.7 KiB
TypeScript
Raw Normal View History

2018-07-16 18:42:49 +02:00
import {
Component,
ComponentFactoryResolver,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { OrganizationUpdateRequest } from 'jslib/models/request/organizationUpdateRequest';
import { OrganizationResponse } from 'jslib/models/response/organizationResponse';
import { ModalComponent } from '../../modal.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';
2019-03-07 17:18:45 +01:00
import { ApiKeyComponent } from './api-key.component';
2018-07-16 18:42:49 +02:00
import { DeleteOrganizationComponent } from './delete-organization.component';
2019-03-07 17:18:45 +01:00
import { RotateApiKeyComponent } from './rotate-api-key.component';
2018-07-16 18:42:49 +02:00
@Component({
selector: 'app-org-account',
templateUrl: 'account.component.html',
})
export class AccountComponent {
@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
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,
private analytics: Angulartics2, private toasterService: ToasterService,
private route: ActivatedRoute, private syncService: SyncService) { }
async ngOnInit() {
this.route.parent.parent.params.subscribe(async (params) => {
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;
request.identifier = this.org.identifier;
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.analytics.eventTrack.next({ action: 'Updated Organization Settings' });
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.analytics.eventTrack.next({ action: 'Updated Organization Tax Info' });
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);
childComponent.organizationId = this.organizationId;
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;
const childComponent = this.modal.show<RotateApiKeyComponent>(RotateApiKeyComponent, this.rotateApiKeyModalRef);
childComponent.organizationId = this.organizationId;
this.modal.onClosed.subscribe(async () => {
this.modal = null;
});
}
2018-07-16 18:42:49 +02:00
}