diff --git a/src/abstractions/user.service.ts b/src/abstractions/user.service.ts index ab2239a8454..29eae7b08cc 100644 --- a/src/abstractions/user.service.ts +++ b/src/abstractions/user.service.ts @@ -13,6 +13,7 @@ export abstract class UserService { getKdfIterations: () => Promise; clear: () => Promise; isAuthenticated: () => Promise; + canAccessPremium: () => Promise; getOrganization: (id: string) => Promise; getAllOrganizations: () => Promise; replaceOrganizations: (organizations: { [id: string]: OrganizationData; }) => Promise; diff --git a/src/angular/components/view.component.ts b/src/angular/components/view.component.ts index 17866be231c..fbb1b16053d 100644 --- a/src/angular/components/view.component.ts +++ b/src/angular/components/view.component.ts @@ -21,6 +21,7 @@ import { I18nService } from '../../abstractions/i18n.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { TokenService } from '../../abstractions/token.service'; import { TotpService } from '../../abstractions/totp.service'; +import { UserService } from '../../abstractions/user.service'; import { AttachmentView } from '../../models/view/attachmentView'; import { CipherView } from '../../models/view/cipherView'; @@ -38,6 +39,7 @@ export class ViewComponent implements OnDestroy, OnInit { showPassword: boolean; showCardCode: boolean; isPremium: boolean; + canAccessPremium: boolean; totpCode: string; totpCodeFormatted: string; totpDash: number; @@ -54,7 +56,7 @@ export class ViewComponent implements OnDestroy, OnInit { protected i18nService: I18nService, protected analytics: Angulartics2, protected auditService: AuditService, protected win: Window, protected broadcasterService: BroadcasterService, protected ngZone: NgZone, - protected changeDetectorRef: ChangeDetectorRef) { } + protected changeDetectorRef: ChangeDetectorRef, protected userService: UserService) { } ngOnInit() { this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { @@ -83,9 +85,10 @@ export class ViewComponent implements OnDestroy, OnInit { this.cipher = await cipher.decrypt(); this.isPremium = this.tokenService.getPremium(); + this.canAccessPremium = await this.userService.canAccessPremium(); if (this.cipher.type === CipherType.Login && this.cipher.login.totp && - (cipher.organizationUseTotp || this.isPremium)) { + (cipher.organizationUseTotp || this.canAccessPremium)) { await this.totpUpdateCode(); const interval = this.totpService.getTimeInterval(this.cipher.login.totp); await this.totpTick(interval); diff --git a/src/services/user.service.ts b/src/services/user.service.ts index df80de16a31..6d68bbd0be4 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -116,6 +116,21 @@ export class UserService implements UserServiceAbstraction { return userId != null; } + async canAccessPremium(): Promise { + const tokenPremium = await this.tokenService.getPremium(); + if (tokenPremium) { + return true; + } + + const orgs = await this.getAllOrganizations(); + for (let i = 0; i < orgs.length; i++) { + if (orgs[i].usersGetPremium) { + return true; + } + } + return false; + } + async getOrganization(id: string): Promise { const userId = await this.getUserId(); const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>(