From bbfb750bafadae49116b1a420664ea753cd9b50b Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 14 Jun 2019 15:29:04 +0200 Subject: Restrict services with customURL when not premium user --- src/stores/ServicesStore.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/stores') diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 79d1a0ea1..4cffea110 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -14,6 +14,7 @@ import { matchRoute } from '../helpers/routing-helpers'; import { gaEvent, statsEvent } from '../lib/analytics'; import { workspaceStore } from '../features/workspaces'; import { serviceLimitStore } from '../features/serviceLimit'; +import { RESTRICTION_TYPES } from '../models/Service'; const debug = require('debug')('Franz:ServiceStore'); @@ -76,6 +77,7 @@ export default class ServicesStore extends Store { this._saveActiveService.bind(this), this._logoutReaction.bind(this), this._handleMuteSettings.bind(this), + this._restrictServiceAccess.bind(this), ]); // Just bind this @@ -93,11 +95,6 @@ export default class ServicesStore extends Store { () => this.stores.settings.app.spellcheckerLanguage, () => this._shareSettingsWithServiceProcess(), ); - - reaction( - () => this.all, - () => this._restrictServiceAccess(), - ); } @computed get all() { @@ -690,17 +687,30 @@ export default class ServicesStore extends Store { } _restrictServiceAccess() { - const services = this.all; + const { features } = this.stores.features; const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit; - if (userHasReachedServiceLimit) { - services.map((service, index) => { - console.log('restrictServiceAcceess', index >= serviceLimit); + this.all.map((service, index) => { + if (userHasReachedServiceLimit) { service.isServiceAccessRestricted = index >= serviceLimit; + service.restrictionType = RESTRICTION_TYPES.SERVICE_LIMIT; - return service; - }); - } + if (index >= serviceLimit) { + debug('Restricting access to server due to service limit'); + } + } + + if (service.isUsingCustomUrl) { + service.isServiceAccessRestricted = features.isCustomUrlPremiumFeature; + service.restrictionType = RESTRICTION_TYPES.CUSTOM_URL; + + if (features.isCustomUrlPremiumFeature) { + debug('Restricting access to server due to custom url'); + } + } + + return service; + }); } // Helper -- cgit v1.2.3-54-g00ecf