Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some dependencies inside rocketchat-lib/server/startup, publications... #13222

Merged
merged 10 commits into from
Jan 22, 2019
Merged
2 changes: 0 additions & 2 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ Package.onUse(function(api) {

// SERVER MODELS
api.addFiles('server/models/index.js', 'server');
api.addFiles('server/models/Permissions.js', 'server');
api.addFiles('server/models/Roles.js', 'server');

api.addFiles('server/oauth/oauth.js', 'server');
api.addFiles('server/oauth/facebook.js', 'server');
Expand Down
3 changes: 0 additions & 3 deletions packages/rocketchat-lib/server/models/Permissions.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/rocketchat-lib/server/models/Roles.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
Integrations,
IntegrationHistory,
Base as _Base,
Permissions,
Roles,
} from 'meteor/rocketchat:models';

Object.assign(RocketChat.models, {
Expand All @@ -30,4 +32,6 @@ Object.assign(RocketChat.models, {
CustomSounds,
Integrations,
IntegrationHistory,
Permissions,
Roles,
});
1 change: 1 addition & 0 deletions packages/rocketchat-lib/server/oauth/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Match, check } from 'meteor/check';
import _ from 'underscore';
import { OAuth } from 'meteor/oauth';
import { HTTP } from 'meteor/http';

const crypto = Npm.require('crypto');
const whitelisted = [
'id',
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-lib/server/oauth/proxy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import _ from 'underscore';
import { OAuth } from 'meteor/oauth';
import { settings } from 'meteor/rocketchat:settings';

OAuth._redirectUri = _.wrap(OAuth._redirectUri, function(func, serviceName, ...args) {
const proxy = RocketChat.settings.get('Accounts_OAuth_Proxy_services').replace(/\s/g, '').split(',');
const proxy = settings.get('Accounts_OAuth_Proxy_services').replace(/\s/g, '').split(',');
if (proxy.includes(serviceName)) {
return `${ RocketChat.settings.get('Accounts_OAuth_Proxy_host') }/oauth_redirect`;
return `${ settings.get('Accounts_OAuth_Proxy_host') }/oauth_redirect`;
} else {
return func(serviceName, ...args);
}
Expand Down
29 changes: 16 additions & 13 deletions packages/rocketchat-lib/server/publications/settings.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Meteor } from 'meteor/meteor';
import { Settings } from 'meteor/rocketchat:models';
import { hasPermission } from 'meteor/rocketchat:authorization';
import { Notifications } from 'meteor/rocketchat:notifications';

Meteor.methods({
'public-settings/get'(updatedAt) {
this.unblock();
const records = RocketChat.models.Settings.findNotHiddenPublic().fetch();
const records = Settings.findNotHiddenPublic().fetch();

if (updatedAt instanceof Date) {
return {
update: records.filter(function(record) {
return record._updatedAt > updatedAt;
}),
remove: RocketChat.models.Settings.trashFindDeletedAfter(updatedAt, {
remove: Settings.trashFindDeletedAfter(updatedAt, {
hidden: {
$ne: true,
},
Expand All @@ -30,16 +33,16 @@ Meteor.methods({
return [];
}
this.unblock();
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'view-privileged-setting')) {
if (!hasPermission(Meteor.userId(), 'view-privileged-setting')) {
return [];
}
const records = RocketChat.models.Settings.findNotHidden().fetch();
const records = Settings.findNotHidden().fetch();
if (updatedAt instanceof Date) {
return {
update: records.filter(function(record) {
return record._updatedAt > updatedAt;
}),
remove: RocketChat.models.Settings.trashFindDeletedAfter(updatedAt, {
remove: Settings.trashFindDeletedAfter(updatedAt, {
hidden: {
$ne: true,
},
Expand All @@ -55,14 +58,14 @@ Meteor.methods({
},
});

RocketChat.models.Settings.on('change', ({ clientAction, id, data, diff }) => {
Settings.on('change', ({ clientAction, id, data, diff }) => {
if (diff && Object.keys(diff).length === 1 && diff._updatedAt) { // avoid useless changes
return;
}
switch (clientAction) {
case 'updated':
case 'inserted':
const setting = data || RocketChat.models.Settings.findOneById(id);
const setting = data || Settings.findOneById(id);
const value = {
_id: setting._id,
value: setting.value,
Expand All @@ -71,22 +74,22 @@ RocketChat.models.Settings.on('change', ({ clientAction, id, data, diff }) => {
};

if (setting.public === true) {
RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, value);
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, value);
} else {
RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting);
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting);
}
break;

case 'removed':
RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, { _id: id });
RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id });
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, { _id: id });
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id });
break;
}
});

RocketChat.Notifications.streamAll.allowRead('private-settings-changed', function() {
Notifications.streamAll.allowRead('private-settings-changed', function() {
if (this.userId == null) {
return false;
}
return RocketChat.authz.hasPermission(this.userId, 'view-privileged-setting');
return hasPermission(this.userId, 'view-privileged-setting');
});
4 changes: 3 additions & 1 deletion packages/rocketchat-lib/server/startup/email.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RocketChat.settings.addGroup('Email', function() {
import { settings } from 'meteor/rocketchat:settings';

settings.addGroup('Email', function() {
this.section('Style', function() {

this.add('email_style', `html, body, .body { font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Helvetica Neue','Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol','Meiryo UI',Arial,sans-serif; }
Expand Down
41 changes: 21 additions & 20 deletions packages/rocketchat-lib/server/startup/oAuthServicesUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';
import { CustomOAuth } from 'meteor/rocketchat:custom-oauth';
import { Logger } from 'meteor/rocketchat:logger';
import { settings } from 'meteor/rocketchat:settings';
import _ from 'underscore';

const logger = new Logger('rocketchat:lib', {
Expand All @@ -13,7 +14,7 @@ const logger = new Logger('rocketchat:lib', {
});

function _OAuthServicesUpdate() {
const services = RocketChat.settings.get(/^(Accounts_OAuth_|Accounts_OAuth_Custom-)[a-z0-9_]+$/i);
const services = settings.get(/^(Accounts_OAuth_|Accounts_OAuth_Custom-)[a-z0-9_]+$/i);
services.forEach((service) => {
logger.oauth_updated(service.key);
let serviceName = service.key.replace('Accounts_OAuth_', '');
Expand All @@ -25,26 +26,26 @@ function _OAuthServicesUpdate() {
}
if (service.value === true) {
const data = {
clientId: RocketChat.settings.get(`${ service.key }_id`),
secret: RocketChat.settings.get(`${ service.key }_secret`),
clientId: settings.get(`${ service.key }_id`),
secret: settings.get(`${ service.key }_secret`),
};
if (/Accounts_OAuth_Custom-/.test(service.key)) {
data.custom = true;
data.clientId = RocketChat.settings.get(`${ service.key }-id`);
data.secret = RocketChat.settings.get(`${ service.key }-secret`);
data.serverURL = RocketChat.settings.get(`${ service.key }-url`);
data.tokenPath = RocketChat.settings.get(`${ service.key }-token_path`);
data.identityPath = RocketChat.settings.get(`${ service.key }-identity_path`);
data.authorizePath = RocketChat.settings.get(`${ service.key }-authorize_path`);
data.scope = RocketChat.settings.get(`${ service.key }-scope`);
data.buttonLabelText = RocketChat.settings.get(`${ service.key }-button_label_text`);
data.buttonLabelColor = RocketChat.settings.get(`${ service.key }-button_label_color`);
data.loginStyle = RocketChat.settings.get(`${ service.key }-login_style`);
data.buttonColor = RocketChat.settings.get(`${ service.key }-button_color`);
data.tokenSentVia = RocketChat.settings.get(`${ service.key }-token_sent_via`);
data.identityTokenSentVia = RocketChat.settings.get(`${ service.key }-identity_token_sent_via`);
data.usernameField = RocketChat.settings.get(`${ service.key }-username_field`);
data.mergeUsers = RocketChat.settings.get(`${ service.key }-merge_users`);
data.clientId = settings.get(`${ service.key }-id`);
data.secret = settings.get(`${ service.key }-secret`);
data.serverURL = settings.get(`${ service.key }-url`);
data.tokenPath = settings.get(`${ service.key }-token_path`);
data.identityPath = settings.get(`${ service.key }-identity_path`);
data.authorizePath = settings.get(`${ service.key }-authorize_path`);
data.scope = settings.get(`${ service.key }-scope`);
data.buttonLabelText = settings.get(`${ service.key }-button_label_text`);
data.buttonLabelColor = settings.get(`${ service.key }-button_label_color`);
data.loginStyle = settings.get(`${ service.key }-login_style`);
data.buttonColor = settings.get(`${ service.key }-button_color`);
data.tokenSentVia = settings.get(`${ service.key }-token_sent_via`);
data.identityTokenSentVia = settings.get(`${ service.key }-identity_token_sent_via`);
data.usernameField = settings.get(`${ service.key }-username_field`);
data.mergeUsers = settings.get(`${ service.key }-merge_users`);
new CustomOAuth(serviceName.toLowerCase(), {
serverURL: data.serverURL,
tokenPath: data.tokenPath,
Expand Down Expand Up @@ -88,11 +89,11 @@ function OAuthServicesRemove(_id) {
});
}

RocketChat.settings.get(/^Accounts_OAuth_.+/, function() {
settings.get(/^Accounts_OAuth_.+/, function() {
return OAuthServicesUpdate(); // eslint-disable-line new-cap
});

RocketChat.settings.get(/^Accounts_OAuth_Custom-[a-z0-9_]+/, function(key, value) {
settings.get(/^Accounts_OAuth_Custom-[a-z0-9_]+/, function(key, value) {
if (!value) {
return OAuthServicesRemove(key);// eslint-disable-line new-cap
}
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/server/startup/robots.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { settings } from 'meteor/rocketchat:settings';

Meteor.startup(function() {
return WebApp.connectHandlers.use('/robots.txt', Meteor.bindEnvironment(function(req, res/* , next*/) {
res.writeHead(200);
res.end(RocketChat.settings.get('Robot_Instructions_File_Content'));
res.end(settings.get('Robot_Instructions_File_Content'));
}));
});
23 changes: 12 additions & 11 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Random } from 'meteor/random';
import { settings } from 'meteor/rocketchat:settings';
import './email';

// Insert server unique id if it doesn't exist
RocketChat.settings.add('uniqueID', process.env.DEPLOYMENT_ID || Random.id(), {
settings.add('uniqueID', process.env.DEPLOYMENT_ID || Random.id(), {
public: true,
hidden: true,
});

// When you define a setting and want to add a description, you don't need to automatically define the i18nDescription
// if you add a node to the i18n.json with the same setting name but with `_Description` it will automatically work.

RocketChat.settings.addGroup('Accounts', function() {
settings.addGroup('Accounts', function() {
this.add('Accounts_AllowAnonymousRead', false, {
type: 'boolean',
public: true,
Expand Down Expand Up @@ -535,7 +536,7 @@ RocketChat.settings.addGroup('Accounts', function() {
});
});

RocketChat.settings.addGroup('OAuth', function() {
settings.addGroup('OAuth', function() {
this.section('Facebook', function() {
const enableQuery = {
_id: 'Accounts_OAuth_Facebook',
Expand Down Expand Up @@ -692,7 +693,7 @@ RocketChat.settings.addGroup('OAuth', function() {
});
});

RocketChat.settings.addGroup('General', function() {
settings.addGroup('General', function() {
this.add('Show_Setup_Wizard', 'pending', {
type: 'select',
public: true,
Expand Down Expand Up @@ -898,7 +899,7 @@ RocketChat.settings.addGroup('General', function() {
});
});

RocketChat.settings.addGroup('Message', function() {
settings.addGroup('Message', function() {
this.section('Message_Attachments', function() {
this.add('Message_Attachments_GroupAttach', false, {
type: 'boolean',
Expand Down Expand Up @@ -1076,7 +1077,7 @@ RocketChat.settings.addGroup('Message', function() {
});
});

RocketChat.settings.addGroup('Meta', function() {
settings.addGroup('Meta', function() {
this.add('Meta_language', '', {
type: 'string',
});
Expand All @@ -1099,7 +1100,7 @@ RocketChat.settings.addGroup('Meta', function() {
});
});

RocketChat.settings.addGroup('Push', function() {
settings.addGroup('Push', function() {
this.add('Push_enable', true, {
type: 'boolean',
public: true,
Expand Down Expand Up @@ -1200,7 +1201,7 @@ RocketChat.settings.addGroup('Push', function() {
});
});

RocketChat.settings.addGroup('Layout', function() {
settings.addGroup('Layout', function() {
this.section('Content', function() {
this.add('Layout_Home_Title', 'Home', {
type: 'string',
Expand Down Expand Up @@ -1289,7 +1290,7 @@ RocketChat.settings.addGroup('Layout', function() {
});
});

RocketChat.settings.addGroup('Logs', function() {
settings.addGroup('Logs', function() {
this.add('Log_Level', '0', {
type: 'select',
values: [
Expand Down Expand Up @@ -1355,7 +1356,7 @@ RocketChat.settings.addGroup('Logs', function() {
});
});

RocketChat.settings.addGroup('Setup_Wizard', function() {
settings.addGroup('Setup_Wizard', function() {
this.section('Organization_Info', function() {
this.add('Organization_Type', '', {
type: 'select',
Expand Down Expand Up @@ -2666,4 +2667,4 @@ RocketChat.settings.addGroup('Setup_Wizard', function() {
});
});

RocketChat.settings.init();
settings.init();
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { Meteor } from 'meteor/meteor';
import { WebAppInternals } from 'meteor/webapp';
import { settings } from 'meteor/rocketchat:settings';
import _ from 'underscore';

function testWebAppInternals(fn) {
typeof WebAppInternals !== 'undefined' && fn(WebAppInternals);
}
RocketChat.settings.onload('CDN_PREFIX', function(key, value) {
const useForAll = RocketChat.settings.get('CDN_PREFIX_ALL');
settings.onload('CDN_PREFIX', function(key, value) {
const useForAll = settings.get('CDN_PREFIX_ALL');
if (_.isString(value) && value.trim() && useForAll) {
return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(value));
}
});

RocketChat.settings.onload('CDN_JSCSS_PREFIX', function(key, value) {
const useForAll = RocketChat.settings.get('CDN_PREFIX_ALL');
settings.onload('CDN_JSCSS_PREFIX', function(key, value) {
const useForAll = settings.get('CDN_PREFIX_ALL');
if (_.isString(value) && value.trim() && !useForAll) {
return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(value));
}
});

Meteor.startup(function() {
const cdnValue = RocketChat.settings.get('CDN_PREFIX');
const useForAll = RocketChat.settings.get('CDN_PREFIX_ALL');
const cdnJsCss = RocketChat.settings.get('CDN_JSCSS_PREFIX');
const cdnValue = settings.get('CDN_PREFIX');
const useForAll = settings.get('CDN_PREFIX_ALL');
const cdnJsCss = settings.get('CDN_JSCSS_PREFIX');
if (_.isString(cdnValue) && cdnValue.trim()) {
if (useForAll) {
return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(cdnValue));
Expand Down
Loading