[FIX] Push gateway and cloud integration (#18377)

* Link push gateway setting to cloud register

* Add migration to disable gateway and alert admins
pull/18383/head
Diego Sampaio 5 years ago committed by GitHub
parent cf053273f6
commit dfeebb8afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/lib/server/startup/settings.js
  2. 9
      app/push/server/push.js
  3. 6
      packages/rocketchat-i18n/i18n/en.i18n.json
  4. 1
      server/startup/migrations/index.js
  5. 54
      server/startup/migrations/v201.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',

@ -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);
}

@ -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: <br/><ul><li>[name], [fname], [lname] for the user's full name, first name or last name, respectively.</li><li>[email] for the user's email.</li><li>[password] for the user's password.</li><li>[Site_Name] and [Site_URL] for the Application Name and URL respectively.</li></ul>",
"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 <a href='https://rocket.chat/terms'>Terms</a> & <a href='https://rocket.chat/privacy'>Privacy Policy</a>",
"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 <em>__peer__</em> 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",

@ -197,4 +197,5 @@ import './v197';
import './v198';
import './v199';
import './v200';
import './v201';
import './xrun';

@ -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,
}],
});
});
},
});
Loading…
Cancel
Save