user canAccessPremium checks

This commit is contained in:
Kyle Spearrin 2018-08-28 23:17:58 -04:00
parent 1873ce41b6
commit 41ff511165
9 changed files with 25 additions and 38 deletions

2
jslib

@ -1 +1 @@
Subproject commit 45da8aa9eb4dd7e12c9fa67ed09189bc4d5ed2f1 Subproject commit 81c21418ec965221b4d322008f9da0ab7b9037d0

View File

@ -6,7 +6,7 @@ import { ActivatedRoute } from '@angular/router';
import { ApiService } from 'jslib/abstractions/api.service'; import { ApiService } from 'jslib/abstractions/api.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { TokenService } from 'jslib/abstractions/token.service'; import { UserService } from 'jslib/abstractions/user.service';
import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType'; import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
@ -18,10 +18,10 @@ import { TwoFactorSetupComponent as BaseTwoFactorSetupComponent } from '../../se
templateUrl: '../../settings/two-factor-setup.component.html', templateUrl: '../../settings/two-factor-setup.component.html',
}) })
export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent { export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent {
constructor(apiService: ApiService, tokenService: TokenService, constructor(apiService: ApiService, userService: UserService,
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService, componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
private route: ActivatedRoute) { private route: ActivatedRoute) {
super(apiService, tokenService, componentFactoryResolver, messagingService); super(apiService, userService, componentFactoryResolver, messagingService);
} }
async ngOnInit() { async ngOnInit() {

View File

@ -15,8 +15,8 @@ import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StateService } from 'jslib/abstractions/state.service'; import { StateService } from 'jslib/abstractions/state.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service'; import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';
import { CipherData } from 'jslib/models/data/cipherData'; import { CipherData } from 'jslib/models/data/cipherData';
import { Cipher } from 'jslib/models/domain/cipher'; import { Cipher } from 'jslib/models/domain/cipher';
@ -37,11 +37,11 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
i18nService: I18nService, platformUtilsService: PlatformUtilsService, i18nService: I18nService, platformUtilsService: PlatformUtilsService,
analytics: Angulartics2, toasterService: ToasterService, analytics: Angulartics2, toasterService: ToasterService,
auditService: AuditService, stateService: StateService, auditService: AuditService, stateService: StateService,
tokenService: TokenService, totpService: TotpService, userService: UserService, totpService: TotpService,
passwordGenerationService: PasswordGenerationService, private apiService: ApiService, passwordGenerationService: PasswordGenerationService, private apiService: ApiService,
messagingService: MessagingService) { messagingService: MessagingService) {
super(cipherService, folderService, i18nService, platformUtilsService, analytics, super(cipherService, folderService, i18nService, platformUtilsService, analytics,
toasterService, auditService, stateService, tokenService, totpService, passwordGenerationService, toasterService, auditService, stateService, userService, totpService, passwordGenerationService,
messagingService); messagingService);
} }

View File

@ -22,14 +22,14 @@
<h3 class="mb-0"> <h3 class="mb-0">
{{p.name}} {{p.name}}
<i class="fa fa-check text-success fa-fw" *ngIf="p.enabled" title="{{'enabled' | i18n}}"></i> <i class="fa fa-check text-success fa-fw" *ngIf="p.enabled" title="{{'enabled' | i18n}}"></i>
<a href="#" appStopClick class="badge badge-primary" *ngIf="!premium && p.premium" (click)="premiumRequired()"> <a href="#" appStopClick class="badge badge-primary" *ngIf="!canAccessPremium && p.premium" (click)="premiumRequired()">
{{'premium' | i18n}} {{'premium' | i18n}}
</a> </a>
</h3> </h3>
{{p.description}} {{p.description}}
</div> </div>
<div class="ml-auto"> <div class="ml-auto">
<button type="button" class="btn btn-outline-secondary btn-sm" [disabled]="!premium && p.premium" (click)="manage(p.type)"> <button type="button" class="btn btn-outline-secondary btn-sm" [disabled]="!canAccessPremium && p.premium" (click)="manage(p.type)">
{{'manage' | i18n}} {{'manage' | i18n}}
</button> </button>
</div> </div>

View File

@ -9,7 +9,7 @@ import {
import { ApiService } from 'jslib/abstractions/api.service'; import { ApiService } from 'jslib/abstractions/api.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { TokenService } from 'jslib/abstractions/token.service'; import { UserService } from 'jslib/abstractions/user.service';
import { TwoFactorProviders } from 'jslib/services/auth.service'; import { TwoFactorProviders } from 'jslib/services/auth.service';
@ -38,16 +38,16 @@ export class TwoFactorSetupComponent implements OnInit {
organizationId: string; organizationId: string;
providers: any[] = []; providers: any[] = [];
premium: boolean; canAccessPremium: boolean;
loading = true; loading = true;
private modal: ModalComponent = null; private modal: ModalComponent = null;
constructor(protected apiService: ApiService, protected tokenService: TokenService, constructor(protected apiService: ApiService, protected userService: UserService,
protected componentFactoryResolver: ComponentFactoryResolver, protected messagingService: MessagingService) { } protected componentFactoryResolver: ComponentFactoryResolver, protected messagingService: MessagingService) { }
async ngOnInit() { async ngOnInit() {
this.premium = this.tokenService.getPremium(); this.canAccessPremium = await this.userService.canAccessPremium();
for (const key in TwoFactorProviders) { for (const key in TwoFactorProviders) {
if (!TwoFactorProviders.hasOwnProperty(key)) { if (!TwoFactorProviders.hasOwnProperty(key)) {
@ -128,8 +128,7 @@ export class TwoFactorSetupComponent implements OnInit {
} }
async premiumRequired() { async premiumRequired() {
const premium = await this.tokenService.getPremium(); if (!this.canAccessPremium) {
if (!premium) {
this.messagingService.send('premiumRequired'); this.messagingService.send('premiumRequired');
return; return;
} }

View File

@ -51,8 +51,7 @@ export class UserBillingComponent implements OnInit {
return; return;
} }
const premium = this.tokenService.getPremium(); if (this.tokenService.getPremium()) {
if (premium) {
this.loading = true; this.loading = true;
this.billing = await this.apiService.getUserBilling(); this.billing = await this.apiService.getUserBilling();
} else { } else {

View File

@ -80,7 +80,7 @@
<div class="col-6 form-group totp d-flex align-items-end" [ngClass]="{'low': totpLow}"> <div class="col-6 form-group totp d-flex align-items-end" [ngClass]="{'low': totpLow}">
<div *ngIf="!cipher.login.totp || !totpCode"> <div *ngIf="!cipher.login.totp || !totpCode">
<img src="../../images/totp-countdown.png" title="{{'verificationCodeTotp' | i18n}}" class="ml-2"> <img src="../../images/totp-countdown.png" title="{{'verificationCodeTotp' | i18n}}" class="ml-2">
<a href="#" appStopClick class="badge badge-primary ml-3" (click)="premiumRequired()" *ngIf="!organization && !cipher.organizationId && !isPremium"> <a href="#" appStopClick class="badge badge-primary ml-3" (click)="premiumRequired()" *ngIf="!organization && !cipher.organizationId && !canAccessPremium">
{{'premium' | i18n}} {{'premium' | i18n}}
</a> </a>
<a href="#" appStopClick class="badge badge-primary ml-3" (click)="upgradeOrganization()" *ngIf="(organization && !organization.useTotp) || (cipher.organizationId && !cipher.organizationUseTotp)"> <a href="#" appStopClick class="badge badge-primary ml-3" (click)="upgradeOrganization()" *ngIf="(organization && !organization.useTotp) || (cipher.organizationId && !cipher.organizationUseTotp)">

View File

@ -16,8 +16,8 @@ import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StateService } from 'jslib/abstractions/state.service'; import { StateService } from 'jslib/abstractions/state.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service'; import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';
import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component'; import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component';
import { LoginUriView } from 'jslib/models/view/loginUriView'; import { LoginUriView } from 'jslib/models/view/loginUriView';
@ -27,7 +27,7 @@ import { LoginUriView } from 'jslib/models/view/loginUriView';
templateUrl: 'add-edit.component.html', templateUrl: 'add-edit.component.html',
}) })
export class AddEditComponent extends BaseAddEditComponent implements OnInit { export class AddEditComponent extends BaseAddEditComponent implements OnInit {
isPremium: boolean; canAccessPremium: boolean;
totpCode: string; totpCode: string;
totpCodeFormatted: string; totpCodeFormatted: string;
totpDash: number; totpDash: number;
@ -43,7 +43,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
i18nService: I18nService, platformUtilsService: PlatformUtilsService, i18nService: I18nService, platformUtilsService: PlatformUtilsService,
analytics: Angulartics2, toasterService: ToasterService, analytics: Angulartics2, toasterService: ToasterService,
auditService: AuditService, stateService: StateService, auditService: AuditService, stateService: StateService,
protected tokenService: TokenService, protected totpService: TotpService, protected userService: UserService, protected totpService: TotpService,
protected passwordGenerationService: PasswordGenerationService, protected messagingService: MessagingService) { protected passwordGenerationService: PasswordGenerationService, protected messagingService: MessagingService) {
super(cipherService, folderService, i18nService, platformUtilsService, analytics, super(cipherService, folderService, i18nService, platformUtilsService, analytics,
toasterService, auditService, stateService); toasterService, auditService, stateService);
@ -55,9 +55,9 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
this.hasPasswordHistory = this.cipher.hasPasswordHistory; this.hasPasswordHistory = this.cipher.hasPasswordHistory;
this.cleanUp(); this.cleanUp();
this.isPremium = this.tokenService.getPremium(); this.canAccessPremium = await this.userService.canAccessPremium();
if (this.cipher.type === CipherType.Login && this.cipher.login.totp && if (this.cipher.type === CipherType.Login && this.cipher.login.totp &&
(this.cipher.organizationUseTotp || this.isPremium)) { (this.cipher.organizationUseTotp || this.canAccessPremium)) {
await this.totpUpdateCode(); await this.totpUpdateCode();
const interval = this.totpService.getTimeInterval(this.cipher.login.totp); const interval = this.totpService.getTimeInterval(this.cipher.login.totp);
await this.totpTick(interval); await this.totpTick(interval);
@ -102,8 +102,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
} }
async premiumRequired() { async premiumRequired() {
const premium = await this.tokenService.getPremium(); if (!this.canAccessPremium) {
if (!premium) {
this.messagingService.send('premiumRequired'); this.messagingService.send('premiumRequired');
return; return;
} }

View File

@ -90,7 +90,7 @@ export class VaultComponent implements OnInit, OnDestroy {
this.showBrowserOutdated = window.navigator.userAgent.indexOf('MSIE') !== -1; this.showBrowserOutdated = window.navigator.userAgent.indexOf('MSIE') !== -1;
const hasEncKey = await this.cryptoService.hasEncKey(); const hasEncKey = await this.cryptoService.hasEncKey();
this.showUpdateKey = !hasEncKey; this.showUpdateKey = !hasEncKey;
const isPremium = await this.tokenService.getPremium(); const canAccessPremium = await this.userService.canAccessPremium();
this.route.queryParams.subscribe(async (params) => { this.route.queryParams.subscribe(async (params) => {
await this.syncService.fullSync(false); await this.syncService.fullSync(false);
@ -116,8 +116,8 @@ export class VaultComponent implements OnInit, OnDestroy {
this.organizationsComponent.load(), this.organizationsComponent.load(),
]); ]);
this.showPremiumCallout = !this.showVerifyEmail && !isPremium && this.showPremiumCallout = !this.showVerifyEmail && !canAccessPremium &&
!this.platformUtilsService.isSelfHost() && !(await this.inOrgWithPremium()); !this.platformUtilsService.isSelfHost();
if (params == null) { if (params == null) {
this.groupingsComponent.selectedAll = true; this.groupingsComponent.selectedAll = true;
@ -475,14 +475,4 @@ export class VaultComponent implements OnInit, OnDestroy {
const url = this.router.createUrlTree(['vault'], { queryParams: queryParams }).toString(); const url = this.router.createUrlTree(['vault'], { queryParams: queryParams }).toString();
this.location.go(url); this.location.go(url);
} }
private async inOrgWithPremium() {
const orgs = await this.userService.getAllOrganizations();
for (let i = 0; i < orgs.length; i++) {
if (orgs[i].usersGetPremium) {
return true;
}
}
return false;
}
} }