diff options
author | 2019-06-14 15:29:04 +0200 | |
---|---|---|
committer | 2019-06-14 15:29:04 +0200 | |
commit | bbfb750bafadae49116b1a420664ea753cd9b50b (patch) | |
tree | dddf11190cfdcfaa8171f7609b1e4d5dd0654dff /src | |
parent | Add "service limit reached" screen (diff) | |
download | ferdium-app-bbfb750bafadae49116b1a420664ea753cd9b50b.tar.gz ferdium-app-bbfb750bafadae49116b1a420664ea753cd9b50b.tar.zst ferdium-app-bbfb750bafadae49116b1a420664ea753cd9b50b.zip |
Restrict services with customURL when not premium user
Diffstat (limited to 'src')
-rw-r--r-- | src/components/services/content/ServiceRestricted.js | 38 | ||||
-rw-r--r-- | src/components/services/content/ServiceView.js | 2 | ||||
-rw-r--r-- | src/i18n/locales/defaultMessages.json | 46 | ||||
-rw-r--r-- | src/i18n/locales/en-US.json | 6 | ||||
-rw-r--r-- | src/i18n/messages/src/components/services/content/ServiceRestricted.json | 46 | ||||
-rw-r--r-- | src/models/Service.js | 17 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 34 |
7 files changed, 145 insertions, 44 deletions
diff --git a/src/components/services/content/ServiceRestricted.js b/src/components/services/content/ServiceRestricted.js index 9fb7d0961..4b8d926aa 100644 --- a/src/components/services/content/ServiceRestricted.js +++ b/src/components/services/content/ServiceRestricted.js | |||
@@ -5,16 +5,25 @@ import { defineMessages, intlShape } from 'react-intl'; | |||
5 | 5 | ||
6 | import { serviceLimitStore } from '../../../features/serviceLimit'; | 6 | import { serviceLimitStore } from '../../../features/serviceLimit'; |
7 | import Button from '../../ui/Button'; | 7 | import Button from '../../ui/Button'; |
8 | import { RESTRICTION_TYPES } from '../../../models/Service'; | ||
8 | 9 | ||
9 | const messages = defineMessages({ | 10 | const messages = defineMessages({ |
10 | headline: { | 11 | headlineServiceLimit: { |
11 | id: 'service.restrictedHandler.headline', | 12 | id: 'service.restrictedHandler.serviceLimit.headline', |
12 | defaultMessage: '!!!You have reached your service limit.', | 13 | defaultMessage: '!!!You have reached your service limit.', |
13 | }, | 14 | }, |
14 | text: { | 15 | textServiceLimit: { |
15 | id: 'service.restrictedHandler.text', | 16 | id: 'service.restrictedHandler.serviceLimit.text', |
16 | defaultMessage: '!!!Please upgrade your account to use more than {count} services.', | 17 | defaultMessage: '!!!Please upgrade your account to use more than {count} services.', |
17 | }, | 18 | }, |
19 | headlineCustomUrl: { | ||
20 | id: 'service.restrictedHandler.customUrl.headline', | ||
21 | defaultMessage: '!!!Franz Professional Plan required', | ||
22 | }, | ||
23 | textCustomUrl: { | ||
24 | id: 'service.restrictedHandler.customUrl.text', | ||
25 | defaultMessage: '!!!Please upgrade to the Franz Professional plan to use custom urls & self hosted services.', | ||
26 | }, | ||
18 | action: { | 27 | action: { |
19 | id: 'service.restrictedHandler.action', | 28 | id: 'service.restrictedHandler.action', |
20 | defaultMessage: '!!!Upgrade Account', | 29 | defaultMessage: '!!!Upgrade Account', |
@@ -25,6 +34,7 @@ export default @observer class ServiceRestricted extends Component { | |||
25 | static propTypes = { | 34 | static propTypes = { |
26 | name: PropTypes.string.isRequired, | 35 | name: PropTypes.string.isRequired, |
27 | upgrade: PropTypes.func.isRequired, | 36 | upgrade: PropTypes.func.isRequired, |
37 | type: PropTypes.number.isRequired, | ||
28 | }; | 38 | }; |
29 | 39 | ||
30 | static contextTypes = { | 40 | static contextTypes = { |
@@ -36,13 +46,27 @@ export default @observer class ServiceRestricted extends Component { | |||
36 | countdownIntervalTimeout = 1000; | 46 | countdownIntervalTimeout = 1000; |
37 | 47 | ||
38 | render() { | 48 | render() { |
39 | const { name, upgrade } = this.props; | 49 | const { |
50 | name, | ||
51 | upgrade, | ||
52 | type, | ||
53 | } = this.props; | ||
40 | const { intl } = this.context; | 54 | const { intl } = this.context; |
41 | 55 | ||
42 | return ( | 56 | return ( |
43 | <div className="services__info-layer"> | 57 | <div className="services__info-layer"> |
44 | <h1>{intl.formatMessage(messages.headline)}</h1> | 58 | {type === RESTRICTION_TYPES.SERVICE_LIMIT && ( |
45 | <p>{intl.formatMessage(messages.text, { count: serviceLimitStore.serviceLimit })}</p> | 59 | <> |
60 | <h1>{intl.formatMessage(messages.headlineServiceLimit)}</h1> | ||
61 | <p>{intl.formatMessage(messages.textServiceLimit, { count: serviceLimitStore.serviceLimit })}</p> | ||
62 | </> | ||
63 | )} | ||
64 | {type === RESTRICTION_TYPES.CUSTOM_URL && ( | ||
65 | <> | ||
66 | <h1>{intl.formatMessage(messages.headlineCustomUrl)}</h1> | ||
67 | <p>{intl.formatMessage(messages.textCustomUrl)}</p> | ||
68 | </> | ||
69 | )} | ||
46 | <Button | 70 | <Button |
47 | label={intl.formatMessage(messages.action, { name })} | 71 | label={intl.formatMessage(messages.action, { name })} |
48 | buttonType="inverted" | 72 | buttonType="inverted" |
diff --git a/src/components/services/content/ServiceView.js b/src/components/services/content/ServiceView.js index 18279fd06..f65f51346 100644 --- a/src/components/services/content/ServiceView.js +++ b/src/components/services/content/ServiceView.js | |||
@@ -133,8 +133,8 @@ export default @observer class ServiceView extends Component { | |||
133 | {service.isServiceAccessRestricted ? ( | 133 | {service.isServiceAccessRestricted ? ( |
134 | <ServiceRestricted | 134 | <ServiceRestricted |
135 | name={service.recipe.name} | 135 | name={service.recipe.name} |
136 | webview={service.webview} | ||
137 | upgrade={upgrade} | 136 | upgrade={upgrade} |
137 | type={service.restrictionType} | ||
138 | /> | 138 | /> |
139 | ) : ( | 139 | ) : ( |
140 | <ServiceWebview | 140 | <ServiceWebview |
diff --git a/src/i18n/locales/defaultMessages.json b/src/i18n/locales/defaultMessages.json index 533944fd0..c2363923f 100644 --- a/src/i18n/locales/defaultMessages.json +++ b/src/i18n/locales/defaultMessages.json | |||
@@ -897,39 +897,65 @@ | |||
897 | "defaultMessage": "!!!You have reached your service limit.", | 897 | "defaultMessage": "!!!You have reached your service limit.", |
898 | "end": { | 898 | "end": { |
899 | "column": 3, | 899 | "column": 3, |
900 | "line": 13 | 900 | "line": 14 |
901 | }, | 901 | }, |
902 | "file": "src/components/services/content/ServiceRestricted.js", | 902 | "file": "src/components/services/content/ServiceRestricted.js", |
903 | "id": "service.restrictedHandler.headline", | 903 | "id": "service.restrictedHandler.serviceLimit.headline", |
904 | "start": { | 904 | "start": { |
905 | "column": 12, | 905 | "column": 24, |
906 | "line": 10 | 906 | "line": 11 |
907 | } | 907 | } |
908 | }, | 908 | }, |
909 | { | 909 | { |
910 | "defaultMessage": "!!!Please upgrade your account to use more than {count} services.", | 910 | "defaultMessage": "!!!Please upgrade your account to use more than {count} services.", |
911 | "end": { | 911 | "end": { |
912 | "column": 3, | 912 | "column": 3, |
913 | "line": 17 | 913 | "line": 18 |
914 | }, | 914 | }, |
915 | "file": "src/components/services/content/ServiceRestricted.js", | 915 | "file": "src/components/services/content/ServiceRestricted.js", |
916 | "id": "service.restrictedHandler.text", | 916 | "id": "service.restrictedHandler.serviceLimit.text", |
917 | "start": { | 917 | "start": { |
918 | "column": 8, | 918 | "column": 20, |
919 | "line": 14 | 919 | "line": 15 |
920 | } | ||
921 | }, | ||
922 | { | ||
923 | "defaultMessage": "!!!Franz Professional Plan required", | ||
924 | "end": { | ||
925 | "column": 3, | ||
926 | "line": 22 | ||
927 | }, | ||
928 | "file": "src/components/services/content/ServiceRestricted.js", | ||
929 | "id": "service.restrictedHandler.customUrl.headline", | ||
930 | "start": { | ||
931 | "column": 21, | ||
932 | "line": 19 | ||
933 | } | ||
934 | }, | ||
935 | { | ||
936 | "defaultMessage": "!!!Please upgrade to the Franz Professional plan to use custom urls & self hosted services.", | ||
937 | "end": { | ||
938 | "column": 3, | ||
939 | "line": 26 | ||
940 | }, | ||
941 | "file": "src/components/services/content/ServiceRestricted.js", | ||
942 | "id": "service.restrictedHandler.customUrl.text", | ||
943 | "start": { | ||
944 | "column": 17, | ||
945 | "line": 23 | ||
920 | } | 946 | } |
921 | }, | 947 | }, |
922 | { | 948 | { |
923 | "defaultMessage": "!!!Upgrade Account", | 949 | "defaultMessage": "!!!Upgrade Account", |
924 | "end": { | 950 | "end": { |
925 | "column": 3, | 951 | "column": 3, |
926 | "line": 21 | 952 | "line": 30 |
927 | }, | 953 | }, |
928 | "file": "src/components/services/content/ServiceRestricted.js", | 954 | "file": "src/components/services/content/ServiceRestricted.js", |
929 | "id": "service.restrictedHandler.action", | 955 | "id": "service.restrictedHandler.action", |
930 | "start": { | 956 | "start": { |
931 | "column": 10, | 957 | "column": 10, |
932 | "line": 18 | 958 | "line": 27 |
933 | } | 959 | } |
934 | } | 960 | } |
935 | ], | 961 | ], |
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index d83ce37b0..e921d8958 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json | |||
@@ -120,8 +120,10 @@ | |||
120 | "service.errorHandler.message": "Error", | 120 | "service.errorHandler.message": "Error", |
121 | "service.errorHandler.text": "{name} has failed to load.", | 121 | "service.errorHandler.text": "{name} has failed to load.", |
122 | "service.restrictedHandler.action": "Upgrade Account", | 122 | "service.restrictedHandler.action": "Upgrade Account", |
123 | "service.restrictedHandler.headline": "You have reached your service limit.", | 123 | "service.restrictedHandler.customUrl.headline": "Franz Professional Plan required", |
124 | "service.restrictedHandler.text": "Please upgrade your account to use more than {count} services.", | 124 | "service.restrictedHandler.customUrl.text": "Please upgrade to the Franz Professional plan to use custom urls & self hosted services.", |
125 | "service.restrictedHandler.serviceLimit.headline": "You have reached your service limit.", | ||
126 | "service.restrictedHandler.serviceLimit.text": "Please upgrade your account to use more than {count} services.", | ||
125 | "service.webviewLoader.loading": "Loading", | 127 | "service.webviewLoader.loading": "Loading", |
126 | "services.getStarted": "Get started", | 128 | "services.getStarted": "Get started", |
127 | "services.welcome": "Welcome to Franz", | 129 | "services.welcome": "Welcome to Franz", |
diff --git a/src/i18n/messages/src/components/services/content/ServiceRestricted.json b/src/i18n/messages/src/components/services/content/ServiceRestricted.json index 30ecd4d75..c1984afe3 100644 --- a/src/i18n/messages/src/components/services/content/ServiceRestricted.json +++ b/src/i18n/messages/src/components/services/content/ServiceRestricted.json | |||
@@ -1,27 +1,53 @@ | |||
1 | [ | 1 | [ |
2 | { | 2 | { |
3 | "id": "service.restrictedHandler.headline", | 3 | "id": "service.restrictedHandler.serviceLimit.headline", |
4 | "defaultMessage": "!!!You have reached your service limit.", | 4 | "defaultMessage": "!!!You have reached your service limit.", |
5 | "file": "src/components/services/content/ServiceRestricted.js", | 5 | "file": "src/components/services/content/ServiceRestricted.js", |
6 | "start": { | 6 | "start": { |
7 | "line": 10, | 7 | "line": 11, |
8 | "column": 12 | 8 | "column": 24 |
9 | }, | 9 | }, |
10 | "end": { | 10 | "end": { |
11 | "line": 13, | 11 | "line": 14, |
12 | "column": 3 | 12 | "column": 3 |
13 | } | 13 | } |
14 | }, | 14 | }, |
15 | { | 15 | { |
16 | "id": "service.restrictedHandler.text", | 16 | "id": "service.restrictedHandler.serviceLimit.text", |
17 | "defaultMessage": "!!!Please upgrade your account to use more than {count} services.", | 17 | "defaultMessage": "!!!Please upgrade your account to use more than {count} services.", |
18 | "file": "src/components/services/content/ServiceRestricted.js", | 18 | "file": "src/components/services/content/ServiceRestricted.js", |
19 | "start": { | 19 | "start": { |
20 | "line": 14, | 20 | "line": 15, |
21 | "column": 8 | 21 | "column": 20 |
22 | }, | ||
23 | "end": { | ||
24 | "line": 18, | ||
25 | "column": 3 | ||
26 | } | ||
27 | }, | ||
28 | { | ||
29 | "id": "service.restrictedHandler.customUrl.headline", | ||
30 | "defaultMessage": "!!!Franz Professional Plan required", | ||
31 | "file": "src/components/services/content/ServiceRestricted.js", | ||
32 | "start": { | ||
33 | "line": 19, | ||
34 | "column": 21 | ||
35 | }, | ||
36 | "end": { | ||
37 | "line": 22, | ||
38 | "column": 3 | ||
39 | } | ||
40 | }, | ||
41 | { | ||
42 | "id": "service.restrictedHandler.customUrl.text", | ||
43 | "defaultMessage": "!!!Please upgrade to the Franz Professional plan to use custom urls & self hosted services.", | ||
44 | "file": "src/components/services/content/ServiceRestricted.js", | ||
45 | "start": { | ||
46 | "line": 23, | ||
47 | "column": 17 | ||
22 | }, | 48 | }, |
23 | "end": { | 49 | "end": { |
24 | "line": 17, | 50 | "line": 26, |
25 | "column": 3 | 51 | "column": 3 |
26 | } | 52 | } |
27 | }, | 53 | }, |
@@ -30,11 +56,11 @@ | |||
30 | "defaultMessage": "!!!Upgrade Account", | 56 | "defaultMessage": "!!!Upgrade Account", |
31 | "file": "src/components/services/content/ServiceRestricted.js", | 57 | "file": "src/components/services/content/ServiceRestricted.js", |
32 | "start": { | 58 | "start": { |
33 | "line": 18, | 59 | "line": 27, |
34 | "column": 10 | 60 | "column": 10 |
35 | }, | 61 | }, |
36 | "end": { | 62 | "end": { |
37 | "line": 21, | 63 | "line": 30, |
38 | "column": 3 | 64 | "column": 3 |
39 | } | 65 | } |
40 | } | 66 | } |
diff --git a/src/models/Service.js b/src/models/Service.js index fa3648a39..848a84aa2 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -4,6 +4,11 @@ import normalizeUrl from 'normalize-url'; | |||
4 | 4 | ||
5 | const debug = require('debug')('Franz:Service'); | 5 | const debug = require('debug')('Franz:Service'); |
6 | 6 | ||
7 | export const RESTRICTION_TYPES = { | ||
8 | SERVICE_LIMIT: 0, | ||
9 | CUSTOM_URL: 1, | ||
10 | }; | ||
11 | |||
7 | export default class Service { | 12 | export default class Service { |
8 | id = ''; | 13 | id = ''; |
9 | 14 | ||
@@ -59,6 +64,12 @@ export default class Service { | |||
59 | 64 | ||
60 | @observable errorMessage = ''; | 65 | @observable errorMessage = ''; |
61 | 66 | ||
67 | @observable isUsingCustomUrl = false; | ||
68 | |||
69 | @observable isServiceAccessRestricted = false; | ||
70 | |||
71 | @observable restrictionType = null; | ||
72 | |||
62 | constructor(data, recipe) { | 73 | constructor(data, recipe) { |
63 | if (!data) { | 74 | if (!data) { |
64 | console.error('Service config not valid'); | 75 | console.error('Service config not valid'); |
@@ -104,8 +115,6 @@ export default class Service { | |||
104 | 115 | ||
105 | this.recipe = recipe; | 116 | this.recipe = recipe; |
106 | 117 | ||
107 | this.isServiceAccessRestricted = false; | ||
108 | |||
109 | autorun(() => { | 118 | autorun(() => { |
110 | if (!this.isEnabled) { | 119 | if (!this.isEnabled) { |
111 | this.webview = null; | 120 | this.webview = null; |
@@ -113,6 +122,10 @@ export default class Service { | |||
113 | this.unreadDirectMessageCount = 0; | 122 | this.unreadDirectMessageCount = 0; |
114 | this.unreadIndirectMessageCount = 0; | 123 | this.unreadIndirectMessageCount = 0; |
115 | } | 124 | } |
125 | |||
126 | if (this.recipe.hasCustomUrl && this.customUrl) { | ||
127 | this.isUsingCustomUrl = true; | ||
128 | } | ||
116 | }); | 129 | }); |
117 | } | 130 | } |
118 | 131 | ||
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'; | |||
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'; | 16 | import { serviceLimitStore } from '../features/serviceLimit'; |
17 | import { RESTRICTION_TYPES } from '../models/Service'; | ||
17 | 18 | ||
18 | const debug = require('debug')('Franz:ServiceStore'); | 19 | const debug = require('debug')('Franz:ServiceStore'); |
19 | 20 | ||
@@ -76,6 +77,7 @@ export default class ServicesStore extends Store { | |||
76 | this._saveActiveService.bind(this), | 77 | this._saveActiveService.bind(this), |
77 | this._logoutReaction.bind(this), | 78 | this._logoutReaction.bind(this), |
78 | this._handleMuteSettings.bind(this), | 79 | this._handleMuteSettings.bind(this), |
80 | this._restrictServiceAccess.bind(this), | ||
79 | ]); | 81 | ]); |
80 | 82 | ||
81 | // Just bind this | 83 | // Just bind this |
@@ -93,11 +95,6 @@ export default class ServicesStore extends Store { | |||
93 | () => this.stores.settings.app.spellcheckerLanguage, | 95 | () => this.stores.settings.app.spellcheckerLanguage, |
94 | () => this._shareSettingsWithServiceProcess(), | 96 | () => this._shareSettingsWithServiceProcess(), |
95 | ); | 97 | ); |
96 | |||
97 | reaction( | ||
98 | () => this.all, | ||
99 | () => this._restrictServiceAccess(), | ||
100 | ); | ||
101 | } | 98 | } |
102 | 99 | ||
103 | @computed get all() { | 100 | @computed get all() { |
@@ -690,17 +687,30 @@ export default class ServicesStore extends Store { | |||
690 | } | 687 | } |
691 | 688 | ||
692 | _restrictServiceAccess() { | 689 | _restrictServiceAccess() { |
693 | const services = this.all; | 690 | const { features } = this.stores.features; |
694 | const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit; | 691 | const { userHasReachedServiceLimit, serviceLimit } = this.stores.serviceLimit; |
695 | 692 | ||
696 | if (userHasReachedServiceLimit) { | 693 | this.all.map((service, index) => { |
697 | services.map((service, index) => { | 694 | if (userHasReachedServiceLimit) { |
698 | console.log('restrictServiceAcceess', index >= serviceLimit); | ||
699 | service.isServiceAccessRestricted = index >= serviceLimit; | 695 | service.isServiceAccessRestricted = index >= serviceLimit; |
696 | service.restrictionType = RESTRICTION_TYPES.SERVICE_LIMIT; | ||
700 | 697 | ||
701 | return service; | 698 | if (index >= serviceLimit) { |
702 | }); | 699 | debug('Restricting access to server due to service limit'); |
703 | } | 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 | }); | ||
704 | } | 714 | } |
705 | 715 | ||
706 | // Helper | 716 | // Helper |