diff --git a/app/lib/server/startup/settings.js b/app/lib/server/startup/settings.js index 30152a1c333..ca9c21c0c7d 100644 --- a/app/lib/server/startup/settings.js +++ b/app/lib/server/startup/settings.js @@ -1198,10 +1198,20 @@ settings.addGroup('Push', function() { this.add('Push_enable_gateway', true, { type: 'boolean', alert: 'Push_Setting_Requires_Restart_Alert', - enableQuery: { - _id: 'Push_enable', - value: true, - }, + enableQuery: [ + { + _id: 'Push_enable', + value: true, + }, + { + _id: 'Register_Server', + value: true, + }, + { + _id: 'Cloud_Service_Agree_PrivacyTerms', + value: true, + }, + ], }); this.add('Push_gateway', 'https://gateway.rocket.chat', { type: 'string', diff --git a/app/push/server/push.js b/app/push/server/push.js index 69a094ddcc6..3c61b9aef55 100644 --- a/app/push/server/push.js +++ b/app/push/server/push.js @@ -8,6 +8,7 @@ import _ from 'underscore'; import { initAPN, sendAPN } from './apn'; import { sendGCM } from './gcm'; import { logger, LoggerManager } from './logger'; +import { settings } from '../../settings/server'; export const _matchToken = Match.OneOf({ apn: String }, { gcm: String }); export const appTokensCollection = new Mongo.Collection('_raix_push_app_tokens'); @@ -70,6 +71,12 @@ export class PushClass { appTokensCollection.rawCollection().deleteOne({ token }); } + _shouldUseGateway() { + return !!this.options.gateways + && settings.get('Register_Server') + && settings.get('Cloud_Service_Agree_PrivacyTerms'); + } + sendNotificationNative(app, notification, countApn, countGcm) { logger.debug('send to token', app.token); @@ -186,7 +193,7 @@ export class PushClass { appTokensCollection.find(query).forEach((app) => { logger.debug('send to token', app.token); - if (this.options.gateways) { + if (this._shouldUseGateway()) { return this.sendNotificationGateway(app, notification, countApn, countGcm); } diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 74b5eb672ca..d67614ef3b0 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -245,6 +245,7 @@ "Accounts_UseDNSDomainCheck": "Use DNS Domain Check", "Accounts_UserAddedEmailSubject_Default": "You have been added to [Site_Name]", "Accounts_UserAddedEmail_Description": "You may use the following placeholders:
", + "Action_required": "Action required", "Activate": "Activate", "Active_users": "Active users", "Daily_Active_Users": "Daily Active Users", @@ -789,7 +790,8 @@ "Cloud_error_in_authenticating": "Error received while authenticating", "Cloud_error_code": "Code: __errorCode__", "Cloud_status_page_description": "If a particular Cloud Service is having issues you can check for known issues on our status page at", - "Cloud_Service_Agree_PrivacyTerms": "Cloud Service Agree PrivacyTerms", + "Cloud_Service_Agree_PrivacyTerms": "Cloud Service Privacy Terms Agreement", + "Cloud_Service_Agree_PrivacyTerms_Description": "I agree with the Terms & Privacy Policy", "Cloud_token_instructions": "To Register your workspace go to Cloud Console. Login or Create an account and click register self-managed. Paste the token provided below", "Cloud_troubleshooting": "Troubleshooting", "Collaborative": "Collaborative", @@ -2865,6 +2867,7 @@ "Push_apn_passphrase": "APN Passphrase", "Push_enable": "Enable", "Push_enable_gateway": "Enable Gateway", + "Push_enable_gateway_Description": "You need to accept to register your server (Setup Wizard > Organization Info > Register Server) and our privacy terms (Setup Wizard > Could Info > Cloud Service Privacy Terms Agreement) to enabled this setting and use our gateway", "Push_gateway": "Gateway", "Push_gateway_description": "Multiple lines can be used to specify multiple gateways", "Push_gcm_api_key": "GCM API Key", @@ -3436,6 +3439,7 @@ "The_image_resize_will_not_work_because_we_can_not_detect_ImageMagick_or_GraphicsMagick_installed_in_your_server": "The image resize will not work because we can not detect ImageMagick or GraphicsMagick installed on your server.", "The_message_is_a_discussion_you_will_not_be_able_to_recover": "The message is a discussion you will not be able to recover the messages!", "The_peer__peer__does_not_exist": "The peer __peer__ does not exist.", + "The_mobile_notifications_were_disabled_to_all_users_go_to_Admin_Push_to_enable_the_Push_Gateway_again": "The mobile notifications were disabled to all users, go to \"Admin > Push\" to enable the Push Gateway again", "The_redirectUri_is_required": "The redirectUri is required", "The_selected_user_is_not_an_agent": "The selected user is not an agent", "The_server_will_restart_in_s_seconds": "The server will restart in %s seconds", diff --git a/server/startup/migrations/index.js b/server/startup/migrations/index.js index 14a2dad344b..5628426c442 100644 --- a/server/startup/migrations/index.js +++ b/server/startup/migrations/index.js @@ -197,4 +197,5 @@ import './v197'; import './v198'; import './v199'; import './v200'; +import './v201'; import './xrun'; diff --git a/server/startup/migrations/v201.js b/server/startup/migrations/v201.js new file mode 100644 index 00000000000..9c88dc1dc92 --- /dev/null +++ b/server/startup/migrations/v201.js @@ -0,0 +1,54 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { Settings } from '../../../app/models/server'; +import { Migrations } from '../../../app/migrations/server'; +import { sendMessagesToAdmins } from '../../lib/sendMessagesToAdmins'; + +Migrations.add({ + version: 201, + up: () => { + const pushEnabled = Settings.findOneById('Push_enable'); + const pushGatewayEnabled = Settings.findOneById('Push_enable_gateway'); + const registerServer = Settings.findOneById('Register_Server'); + const cloudAgreement = Settings.findOneById('Cloud_Service_Agree_PrivacyTerms'); + + if (!pushEnabled?.value) { + return; + } + if (!pushGatewayEnabled?.value) { + return; + } + if (registerServer?.value && cloudAgreement?.value) { + return; + } + + // if push gateway is enabled but server is not registered or cloud terms not agreed, disable gateway and alert admin + Settings.upsert({ + _id: 'Push_enable_gateway', + }, { + $set: { + value: false, + }, + }); + + const id = 'push-gateway-disabled'; + const title = 'Action_required'; + const text = 'The_mobile_notifications_were_disabled_to_all_users_go_to_Admin_Push_to_enable_the_Push_Gateway_again'; + const link = '/admin/Push'; + + Meteor.startup(() => { + sendMessagesToAdmins({ + msgs: ({ adminUser }) => [{ msg: `*${ TAPi18n.__(title, adminUser.language) }*\n${ TAPi18n.__(text, adminUser.language) }` }], + banners: [{ + id, + priority: 100, + title, + text, + modifiers: ['danger'], + link, + }], + }); + }); + }, +});