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

147 lines
5.9 KiB
TypeScript
Raw Normal View History

2018-07-16 18:42:49 +02:00
import {
Component,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import {
Feature/families for enterprise (#1300) * Added manual routing * Families for enterprise/account settings (#1290) * Added sponsored families page * Revert "Added manual routing" This reverts commit a970ba78ffa98545176b636630e48115efcf51cc. * Add messages to page * Remove stages and simplify design * Switch to new figma design * Add screen reader * Add calls to server * Reorder methods * Used to organization filters * Connected page to server * Add preliminary text to subscription page * Sponsor existing family organization flow * Update jslib Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add revoke sponsorship flow * Add spinner to send offer button * Determine if subscription has sponsored items * Work on subscription button * Add message for new family organization * Families for enterprise/subscription page (#1292) * Work on subscription button * Determine if subscription has sponsored items * Work on subscriptions page * Add message for new family organization Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Families for enterprise/redeem card (#1295) * Add toast localization message * Use helpers to property display sponsorship items * Split table rows into component so buttons load (#1296) * Split table rows into component so buttons load * Update jslib * Families for enterprise/localizations (#1299) * Add more localizations * Remove unneeded comments * Fix help article * Run linting * Do not show redeem button if no orgs exist to redeem * Implement new process for accepting sponsorships * Hide business checkbox * Update jslib * Removed commented code * Remove commented html * Cleaned up imports * Use proper message * Remove merge conflict message * Remove confusing comment * Listened to PR feedback * Remove unused property * Update help text * Fix aria labels * Add try catch * Made toast before emit * Minor copy changes * Update jslib * Remove unneeded loading Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2021-11-22 14:41:40 +01:00
ActivatedRoute,
Router
} from '@angular/router';
2018-07-16 18:42:49 +02:00
import { ToasterService } from 'angular2-toaster';
import { ModalService } from 'jslib-angular/services/modal.service';
2018-07-16 18:42:49 +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 { LogService } from 'jslib-common/abstractions/log.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
import { OrganizationKeysRequest } from 'jslib-common/models/request/organizationKeysRequest';
import { OrganizationUpdateRequest } from 'jslib-common/models/request/organizationUpdateRequest';
import { OrganizationResponse } from 'jslib-common/models/response/organizationResponse';
2018-07-16 18:42:49 +02: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';
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 {
@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
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;
constructor(private modalService: ModalService,
2018-07-16 18:42:49 +02:00
private apiService: ApiService, private i18nService: I18nService,
private toasterService: ToasterService, private route: ActivatedRoute,
private syncService: SyncService, private platformUtilsService: PlatformUtilsService,
Feature/families for enterprise (#1300) * Added manual routing * Families for enterprise/account settings (#1290) * Added sponsored families page * Revert "Added manual routing" This reverts commit a970ba78ffa98545176b636630e48115efcf51cc. * Add messages to page * Remove stages and simplify design * Switch to new figma design * Add screen reader * Add calls to server * Reorder methods * Used to organization filters * Connected page to server * Add preliminary text to subscription page * Sponsor existing family organization flow * Update jslib Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add revoke sponsorship flow * Add spinner to send offer button * Determine if subscription has sponsored items * Work on subscription button * Add message for new family organization * Families for enterprise/subscription page (#1292) * Work on subscription button * Determine if subscription has sponsored items * Work on subscriptions page * Add message for new family organization Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Families for enterprise/redeem card (#1295) * Add toast localization message * Use helpers to property display sponsorship items * Split table rows into component so buttons load (#1296) * Split table rows into component so buttons load * Update jslib * Families for enterprise/localizations (#1299) * Add more localizations * Remove unneeded comments * Fix help article * Run linting * Do not show redeem button if no orgs exist to redeem * Implement new process for accepting sponsorships * Hide business checkbox * Update jslib * Removed commented code * Remove commented html * Cleaned up imports * Use proper message * Remove merge conflict message * Remove confusing comment * Listened to PR feedback * Remove unused property * Update help text * Fix aria labels * Add try catch * Made toast before emit * Minor copy changes * Update jslib * Remove unneeded loading Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2021-11-22 14:41:40 +01:00
private cryptoService: CryptoService, private logService: LogService,
private router: Router) { }
2018-07-16 18:42:49 +02:00
async ngOnInit() {
this.selfHosted = this.platformUtilsService.isSelfHost();
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;
} catch (e) {
this.logService.error(e);
}
2018-07-16 18:42:49 +02:00
});
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;
// 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 (e) {
this.logService.error(e);
}
2018-07-16 18:42:49 +02:00
}
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'));
}
async deleteOrganization() {
await this.modalService.openViewRef(DeleteOrganizationComponent, this.deleteModalRef, comp => {
comp.organizationId = this.organizationId;
Feature/families for enterprise (#1300) * Added manual routing * Families for enterprise/account settings (#1290) * Added sponsored families page * Revert "Added manual routing" This reverts commit a970ba78ffa98545176b636630e48115efcf51cc. * Add messages to page * Remove stages and simplify design * Switch to new figma design * Add screen reader * Add calls to server * Reorder methods * Used to organization filters * Connected page to server * Add preliminary text to subscription page * Sponsor existing family organization flow * Update jslib Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add revoke sponsorship flow * Add spinner to send offer button * Determine if subscription has sponsored items * Work on subscription button * Add message for new family organization * Families for enterprise/subscription page (#1292) * Work on subscription button * Determine if subscription has sponsored items * Work on subscriptions page * Add message for new family organization Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Families for enterprise/redeem card (#1295) * Add toast localization message * Use helpers to property display sponsorship items * Split table rows into component so buttons load (#1296) * Split table rows into component so buttons load * Update jslib * Families for enterprise/localizations (#1299) * Add more localizations * Remove unneeded comments * Fix help article * Run linting * Do not show redeem button if no orgs exist to redeem * Implement new process for accepting sponsorships * Hide business checkbox * Update jslib * Removed commented code * Remove commented html * Cleaned up imports * Use proper message * Remove merge conflict message * Remove confusing comment * Listened to PR feedback * Remove unused property * Update help text * Fix aria labels * Add try catch * Made toast before emit * Minor copy changes * Update jslib * Remove unneeded loading Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2021-11-22 14:41:40 +01:00
comp.onSuccess.subscribe(() => {
this.router.navigate(['/']);
});
2018-07-16 18:42:49 +02:00
});
}
2018-09-25 15:12:24 +02:00
async purgeVault() {
await this.modalService.openViewRef(PurgeVaultComponent, this.purgeModalRef, comp => {
comp.organizationId = this.organizationId;
2018-09-25 15:12:24 +02:00
});
}
2019-03-07 17:18:45 +01:00
async viewApiKey() {
await this.modalService.openViewRef(ApiKeyComponent, this.apiKeyModalRef, comp => {
comp.keyType = 'organization';
comp.entityId = this.organizationId;
comp.postKey = this.apiService.postOrganizationApiKey.bind(this.apiService);
comp.scope = 'api.organization';
comp.grantType = 'client_credentials';
comp.apiKeyTitle = 'apiKey';
comp.apiKeyWarning = 'apiKeyWarning';
comp.apiKeyDescription = 'apiKeyDesc';
2019-03-07 17:18:45 +01:00
});
}
async rotateApiKey() {
await this.modalService.openViewRef(ApiKeyComponent, this.rotateApiKeyModalRef, comp => {
comp.keyType = 'organization';
comp.isRotation = true;
comp.entityId = this.organizationId;
comp.postKey = this.apiService.postOrganizationRotateApiKey.bind(this.apiService);
comp.scope = 'api.organization';
comp.grantType = 'client_credentials';
comp.apiKeyTitle = 'apiKey';
comp.apiKeyWarning = 'apiKeyWarning';
comp.apiKeyDescription = 'apiKeyRotateDesc';
2019-03-07 17:18:45 +01:00
});
}
2018-07-16 18:42:49 +02:00
}