diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 6c6b7589f..876851a66 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -12,6 +12,8 @@ import Request from './lib/Request'; | |||
12 | import CachedRequest from './lib/CachedRequest'; | 12 | import CachedRequest from './lib/CachedRequest'; |
13 | import { matchRoute } from '../helpers/routing-helpers'; | 13 | import { matchRoute } from '../helpers/routing-helpers'; |
14 | import { workspaceStore } from '../features/workspaces'; | 14 | import { workspaceStore } from '../features/workspaces'; |
15 | import { serviceLimitStore } from '../features/serviceLimit'; | ||
16 | import { RESTRICTION_TYPES } from '../models/Service'; | ||
15 | 17 | ||
16 | const debug = require('debug')('Franz:ServiceStore'); | 18 | const debug = require('debug')('Franz:ServiceStore'); |
17 | 19 | ||
@@ -74,6 +76,7 @@ export default class ServicesStore extends Store { | |||
74 | this._saveActiveService.bind(this), | 76 | this._saveActiveService.bind(this), |
75 | this._logoutReaction.bind(this), | 77 | this._logoutReaction.bind(this), |
76 | this._handleMuteSettings.bind(this), | 78 | this._handleMuteSettings.bind(this), |
79 | this._restrictServiceAccess.bind(this), | ||
77 | ]); | 80 | ]); |
78 | 81 | ||
79 | // Just bind this | 82 | // Just bind this |
@@ -97,7 +100,10 @@ export default class ServicesStore extends Store { | |||
97 | if (this.stores.user.isLoggedIn) { | 100 | if (this.stores.user.isLoggedIn) { |
98 | const services = this.allServicesRequest.execute().result; | 101 | const services = this.allServicesRequest.execute().result; |
99 | if (services) { | 102 | if (services) { |
100 | return observable(services.slice().slice().sort((a, b) => a.order - b.order)); | 103 | return observable(services.slice().slice().sort((a, b) => a.order - b.order).map((s, index) => { |
104 | s.index = index; | ||
105 | return s; | ||
106 | })); | ||
101 | } | 107 | } |
102 | } | 108 | } |
103 | return []; | 109 | return []; |
@@ -152,6 +158,8 @@ export default class ServicesStore extends Store { | |||
152 | 158 | ||
153 | // Actions | 159 | // Actions |
154 | @action async _createService({ recipeId, serviceData, redirect = true }) { | 160 | @action async _createService({ recipeId, serviceData, redirect = true }) { |
161 | if (serviceLimitStore.userHasReachedServiceLimit) return; | ||
162 | |||
155 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); | 163 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); |
156 | 164 | ||
157 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; | 165 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; |
@@ -430,6 +438,9 @@ export default class ServicesStore extends Store { | |||
430 | redirect: false, | 438 | redirect: false, |
431 | }); | 439 | }); |
432 | } | 440 | } |
441 | } else if (channel === 'feature:todos') { | ||
442 | Object.assign(args[0].data, { serviceId }); | ||
443 | this.actions.todos.handleHostMessage(args[0]); | ||
433 | } | 444 | } |
434 | } | 445 | } |
435 | 446 | ||
@@ -666,6 +677,35 @@ export default class ServicesStore extends Store { | |||
666 | return serviceData; | 677 | return serviceData; |
667 | } | 678 | } |
668 | 679 | ||
680 | _restrictServiceAccess() { | ||
681 | const { features } = this.stores.features; | ||
682 | const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit; | ||
683 | |||
684 | this.all.map((service, index) => { | ||
685 | if (userHasReachedServiceLimit) { | ||
686 | service.isServiceAccessRestricted = index >= serviceLimit; | ||
687 | |||
688 | if (service.isServiceAccessRestricted) { | ||
689 | service.restrictionType = RESTRICTION_TYPES.SERVICE_LIMIT; | ||
690 | |||
691 | debug('Restricting access to server due to service limit'); | ||
692 | } | ||
693 | } | ||
694 | |||
695 | if (service.isUsingCustomUrl) { | ||
696 | service.isServiceAccessRestricted = !features.isCustomUrlIncludedInCurrentPlan; | ||
697 | |||
698 | if (service.isServiceAccessRestricted) { | ||
699 | service.restrictionType = RESTRICTION_TYPES.CUSTOM_URL; | ||
700 | |||
701 | debug('Restricting access to server due to custom url'); | ||
702 | } | ||
703 | } | ||
704 | |||
705 | return service; | ||
706 | }); | ||
707 | } | ||
708 | |||
669 | // Helper | 709 | // Helper |
670 | _initializeServiceRecipeInWebview(serviceId) { | 710 | _initializeServiceRecipeInWebview(serviceId) { |
671 | const service = this.one(serviceId); | 711 | const service = this.one(serviceId); |