diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 109ac5cd7..4cffea110 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -13,6 +13,8 @@ import CachedRequest from './lib/CachedRequest'; | |||
13 | import { matchRoute } from '../helpers/routing-helpers'; | 13 | import { matchRoute } from '../helpers/routing-helpers'; |
14 | import { gaEvent, statsEvent } from '../lib/analytics'; | 14 | import { gaEvent, statsEvent } from '../lib/analytics'; |
15 | import { workspaceStore } from '../features/workspaces'; | 15 | import { workspaceStore } from '../features/workspaces'; |
16 | import { serviceLimitStore } from '../features/serviceLimit'; | ||
17 | import { RESTRICTION_TYPES } from '../models/Service'; | ||
16 | 18 | ||
17 | const debug = require('debug')('Franz:ServiceStore'); | 19 | const 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; |
@@ -678,6 +686,33 @@ export default class ServicesStore extends Store { | |||
678 | return serviceData; | 686 | return serviceData; |
679 | } | 687 | } |
680 | 688 | ||
689 | _restrictServiceAccess() { | ||
690 | const { features } = this.stores.features; | ||
691 | const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit; | ||
692 | |||
693 | this.all.map((service, index) => { | ||
694 | if (userHasReachedServiceLimit) { | ||
695 | service.isServiceAccessRestricted = index >= serviceLimit; | ||
696 | service.restrictionType = RESTRICTION_TYPES.SERVICE_LIMIT; | ||
697 | |||
698 | if (index >= serviceLimit) { | ||
699 | debug('Restricting access to server due to service limit'); | ||
700 | } | ||
701 | } | ||
702 | |||
703 | if (service.isUsingCustomUrl) { | ||
704 | service.isServiceAccessRestricted = features.isCustomUrlPremiumFeature; | ||
705 | service.restrictionType = RESTRICTION_TYPES.CUSTOM_URL; | ||
706 | |||
707 | if (features.isCustomUrlPremiumFeature) { | ||
708 | debug('Restricting access to server due to custom url'); | ||
709 | } | ||
710 | } | ||
711 | |||
712 | return service; | ||
713 | }); | ||
714 | } | ||
715 | |||
681 | // Helper | 716 | // Helper |
682 | _initializeServiceRecipeInWebview(serviceId) { | 717 | _initializeServiceRecipeInWebview(serviceId) { |
683 | const service = this.one(serviceId); | 718 | const service = this.one(serviceId); |