1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

refresh token and UI when license updated

This commit is contained in:
Kyle Spearrin 2019-01-24 08:54:33 -05:00
parent a18e7ab2da
commit eb99fe58dd
3 changed files with 35 additions and 7 deletions

View File

@ -1,23 +1,30 @@
import { import {
Component, Component,
NgZone,
OnDestroy,
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
import { UserService } from 'jslib/abstractions/user.service'; import { UserService } from 'jslib/abstractions/user.service';
import { Organization } from 'jslib/models/domain/organization'; import { Organization } from 'jslib/models/domain/organization';
const BroadcasterSubscriptionId = 'OrganizationLayoutComponent';
@Component({ @Component({
selector: 'app-organization-layout', selector: 'app-organization-layout',
templateUrl: 'organization-layout.component.html', templateUrl: 'organization-layout.component.html',
}) })
export class OrganizationLayoutComponent implements OnInit { export class OrganizationLayoutComponent implements OnInit, OnDestroy {
organization: Organization; organization: Organization;
private organizationId: string; private organizationId: string;
constructor(private route: ActivatedRoute, private userService: UserService) { } constructor(private route: ActivatedRoute, private userService: UserService,
private broadcasterService: BroadcasterService, private ngZone: NgZone) { }
ngOnInit() { ngOnInit() {
document.body.classList.remove('layout_frontend'); document.body.classList.remove('layout_frontend');
@ -25,6 +32,20 @@ export class OrganizationLayoutComponent implements OnInit {
this.organizationId = params.organizationId; this.organizationId = params.organizationId;
await this.load(); await this.load();
}); });
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
case 'updatedOrgLicense':
await this.load();
break;
}
});
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
} }
async load() { async load() {

View File

@ -14,6 +14,7 @@ import { OrganizationBillingResponse } from 'jslib/models/response/organizationB
import { ApiService } from 'jslib/abstractions/api.service'; import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { TokenService } from 'jslib/abstractions/token.service'; import { TokenService } from 'jslib/abstractions/token.service';
@ -48,7 +49,7 @@ export class OrganizationBillingComponent implements OnInit {
constructor(private tokenService: TokenService, private apiService: ApiService, constructor(private tokenService: TokenService, private apiService: ApiService,
private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
private analytics: Angulartics2, private toasterService: ToasterService, private analytics: Angulartics2, private toasterService: ToasterService,
private route: ActivatedRoute) { private messagingService: MessagingService, private route: ActivatedRoute) {
this.selfHosted = platformUtilsService.isSelfHost(); this.selfHosted = platformUtilsService.isSelfHost();
} }
@ -159,10 +160,11 @@ export class OrganizationBillingComponent implements OnInit {
} catch { } } catch { }
} }
closeUpdateLicense(load: boolean) { closeUpdateLicense(updated: boolean) {
this.showUpdateLicense = false; this.showUpdateLicense = false;
if (load) { if (updated) {
this.load(); this.load();
this.messagingService.send('updatedOrgLicense');
} }
} }

View File

@ -38,12 +38,17 @@ export class UpdateLicenseComponent {
const fd = new FormData(); const fd = new FormData();
fd.append('license', files[0]); fd.append('license', files[0]);
let updatePromise: Promise<any> = null;
if (this.organizationId == null) { if (this.organizationId == null) {
this.formPromise = this.apiService.postAccountLicense(fd); updatePromise = this.apiService.postAccountLicense(fd);
} else { } else {
this.formPromise = this.apiService.postOrganizationLicenseUpdate(this.organizationId, fd); updatePromise = this.apiService.postOrganizationLicenseUpdate(this.organizationId, fd);
} }
this.formPromise = updatePromise.then(() => {
return this.apiService.refreshIdentityToken();
});
await this.formPromise; await this.formPromise;
this.analytics.eventTrack.next({ action: 'Updated License' }); this.analytics.eventTrack.next({ action: 'Updated License' });
this.toasterService.popAsync('success', null, this.i18nService.t('updatedLicense')); this.toasterService.popAsync('success', null, this.i18nService.t('updatedLicense'));