aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r--src/stores/ServicesStore.js39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index b13425249..2fc543192 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -13,6 +13,8 @@ import CachedRequest from './lib/CachedRequest';
13import { matchRoute } from '../helpers/routing-helpers'; 13import { matchRoute } from '../helpers/routing-helpers';
14import { gaEvent, statsEvent } from '../lib/analytics'; 14import { gaEvent, statsEvent } from '../lib/analytics';
15import { workspaceStore } from '../features/workspaces'; 15import { workspaceStore } from '../features/workspaces';
16import { serviceLimitStore } from '../features/serviceLimit';
17import { RESTRICTION_TYPES } from '../models/Service';
16 18
17const debug = require('debug')('Franz:ServiceStore'); 19const debug = require('debug')('Franz:ServiceStore');
18 20
@@ -75,6 +77,7 @@ export default class ServicesStore extends Store {
75 this._saveActiveService.bind(this), 77 this._saveActiveService.bind(this),
76 this._logoutReaction.bind(this), 78 this._logoutReaction.bind(this),
77 this._handleMuteSettings.bind(this), 79 this._handleMuteSettings.bind(this),
80 this._restrictServiceAccess.bind(this),
78 ]); 81 ]);
79 82
80 // Just bind this 83 // Just bind this
@@ -98,7 +101,10 @@ export default class ServicesStore extends Store {
98 if (this.stores.user.isLoggedIn) { 101 if (this.stores.user.isLoggedIn) {
99 const services = this.allServicesRequest.execute().result; 102 const services = this.allServicesRequest.execute().result;
100 if (services) { 103 if (services) {
101 return observable(services.slice().slice().sort((a, b) => a.order - b.order)); 104 return observable(services.slice().slice().sort((a, b) => a.order - b.order).map((s, index) => {
105 s.index = index;
106 return s;
107 }));
102 } 108 }
103 } 109 }
104 return []; 110 return [];
@@ -153,6 +159,8 @@ export default class ServicesStore extends Store {
153 159
154 // Actions 160 // Actions
155 @action async _createService({ recipeId, serviceData, redirect = true }) { 161 @action async _createService({ recipeId, serviceData, redirect = true }) {
162 if (serviceLimitStore.userHasReachedServiceLimit) return;
163
156 const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); 164 const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData);
157 165
158 const response = await this.createServiceRequest.execute(recipeId, data)._promise; 166 const response = await this.createServiceRequest.execute(recipeId, data)._promise;
@@ -681,6 +689,35 @@ export default class ServicesStore extends Store {
681 return serviceData; 689 return serviceData;
682 } 690 }
683 691
692 _restrictServiceAccess() {
693 const { features } = this.stores.features;
694 const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit;
695
696 this.all.map((service, index) => {
697 if (userHasReachedServiceLimit) {
698 service.isServiceAccessRestricted = index >= serviceLimit;
699
700 if (service.isServiceAccessRestricted) {
701 service.restrictionType = RESTRICTION_TYPES.SERVICE_LIMIT;
702
703 debug('Restricting access to server due to service limit');
704 }
705 }
706
707 if (service.isUsingCustomUrl) {
708 service.isServiceAccessRestricted = !features.isCustomUrlIncludedInCurrentPlan;
709
710 if (service.isServiceAccessRestricted) {
711 service.restrictionType = RESTRICTION_TYPES.CUSTOM_URL;
712
713 debug('Restricting access to server due to custom url');
714 }
715 }
716
717 return service;
718 });
719 }
720
684 // Helper 721 // Helper
685 _initializeServiceRecipeInWebview(serviceId) { 722 _initializeServiceRecipeInWebview(serviceId) {
686 const service = this.one(serviceId); 723 const service = this.one(serviceId);