Convert rocketchat-ui-master to main module structure (#13107)

* Move rocketchat settings to specific package

* WIP: Move models from rocketchat-lib to a specific package (server)

* Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models

* Move client models from rocketchat:lib to rocketchat:models

* Fix lint

* Move rocketchat.info from lib to utils

* Remove directly dependency between lib and migrations

* Move statistics Model to rocketchat:models

* Create rocketchat:metrics to be able to depacking rocketchat callbacks

* Move  callbacks to specific package

* Remove unused dependency

* Move rocketchat-notifications to a specific package

* Move rocketchat-promises to a specific package

* remove directly dependency from metrics and models

* Move CachedCollection from lib to models

* Move ui models/collections from ui to models

* Move authorization client/ui models to rocketchat:models to be able to remove lib dependency

* Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz

* Move some common functions to rocketchat:utils

* Change imports to dynamic imports to avoid directly dependency between some packages

* Move authz models to rocketchat:models

* Remove directly dependency between rocketchat:authz and rocketchat:lib

* Move some functions from rocketchat:lib to rocketchat:utils

* Add functions to settings package

* Convert rocketchat:file-upload to main module structure

* Import FileUpload where it is being used

* Remove FileUpload and fileUploadHandler from globals eslintrc

* Move some  functions to rocketchat:ui-utils

* Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils

* Remove dependency between lazy-load and lib

* Change imports of renderMessageBody from ui-message to ui-utils

* Add import of main ready from ui-utils

* Convert rocketchat-ui-sidenav to main module structure

* Add imports of toolbarSearch from ui-sidenav

* Remove toolbarSearch from eslintrc globals

* Move CachedCollection to a specific package

* Change imports of CachedCollection to new package

* Move some functions to rocketchat:ui-utils

* Remove directly dependency between tooltip and lib

*  Remove directly dependency between settings and metrics

* Move some settings client function from lib to settings

* Convert rocketchat-ui-master to main module structure

* Merge branch 'develop' into globals/move-rocketchat-callbacks

* Fix import missed objects inside RocketChat namespace

* Fix lint
pull/13115/head^2
Marcos Spessatto Defendi 6 years ago committed by Rodrigo Nascimento
parent a8f26bcb48
commit deae2a43dc
  1. 1
      .meteor/packages
  2. 1
      .meteor/versions
  3. 2
      packages/rocketchat-authorization/client/startup.js
  4. 1
      packages/rocketchat-authorization/package.js
  5. 108
      packages/rocketchat-iframe-login/client/iframe_client.js
  6. 1
      packages/rocketchat-iframe-login/package.js
  7. 14
      packages/rocketchat-lib/client/lib/Layout.js
  8. 2
      packages/rocketchat-lib/client/lib/cachedCollection.js
  9. 47
      packages/rocketchat-lib/client/lib/settings.js
  10. 3
      packages/rocketchat-lib/client/lib/tooltip.js
  11. 2
      packages/rocketchat-lib/package.js
  12. 1
      packages/rocketchat-metrics/package.js
  13. 21
      packages/rocketchat-metrics/server/lib/metrics.js
  14. 3
      packages/rocketchat-models/client/index.js
  15. 2
      packages/rocketchat-models/client/models/CachedChatRoom.js
  16. 2
      packages/rocketchat-models/client/models/CachedChatSubscription.js
  17. 2
      packages/rocketchat-models/client/models/ChatPermissions.js
  18. 1
      packages/rocketchat-models/package.js
  19. 2
      packages/rocketchat-settings/client/index.js
  20. 47
      packages/rocketchat-settings/client/lib/settings.js
  21. 1
      packages/rocketchat-settings/package.js
  22. 5
      packages/rocketchat-tooltip/client/index.js
  23. 6
      packages/rocketchat-tooltip/client/init.js
  24. 3
      packages/rocketchat-tooltip/client/rocketchat-tooltip.js
  25. 3
      packages/rocketchat-tooltip/package.js
  26. 1
      packages/rocketchat-ui-cached-collection/client/index.js
  27. 0
      packages/rocketchat-ui-cached-collection/client/models/CachedCollection.js
  28. 19
      packages/rocketchat-ui-cached-collection/package.js
  29. 5
      packages/rocketchat-ui-master/client/index.js
  30. 62
      packages/rocketchat-ui-master/client/main.js
  31. 12
      packages/rocketchat-ui-master/package.js
  32. 1
      packages/rocketchat-ui-master/server/index.js
  33. 26
      packages/rocketchat-ui-master/server/inject.js
  34. 7
      packages/rocketchat-ui-utils/client/index.js
  35. 112
      packages/rocketchat-ui-utils/client/lib/IframeLogin.js
  36. 14
      packages/rocketchat-ui-utils/client/lib/Layout.js
  37. 3
      packages/rocketchat-ui-utils/client/lib/RoomManager.js
  38. 20
      packages/rocketchat-ui-utils/client/lib/fireGlobalEvent.js
  39. 1
      packages/rocketchat-ui-utils/package.js
  40. 21
      packages/rocketchat-ui/client/lib/fireEvent.js

@ -209,3 +209,4 @@ rocketchat:callbacks
rocketchat:notifications
rocketchat:promises
rocketchat:ui-utils
rocketchat:ui-cached-collection

@ -249,6 +249,7 @@ rocketchat:tooltip@0.0.1
rocketchat:ui@0.1.0
rocketchat:ui-account@0.1.0
rocketchat:ui-admin@0.1.0
rocketchat:ui-cached-collection@0.0.1
rocketchat:ui-clean-history@0.0.1
rocketchat:ui-flextab@0.1.0
rocketchat:ui-login@0.1.0

@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { CachedCollectionManager } from 'meteor/rocketchat:models';
import { CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection';
import { hasAllPermission } from './hasPermission';
Meteor.startup(async() => {

@ -13,6 +13,7 @@ Package.onUse(function(api) {
'rocketchat:utils',
'rocketchat:models',
'rocketchat:notifications',
'rocketchat:ui-cached-collection',
]);
api.use([
'templating',

@ -1,10 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Accounts } from 'meteor/accounts-base';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { HTTP } from 'meteor/http';
import { IframeLogin } from 'meteor/rocketchat:ui-utils';
import { OAuth } from 'meteor/oauth';
import _ from 'underscore';
@ -14,109 +11,6 @@ Accounts._unstoreLoginToken = function(...args) {
_unstoreLoginToken.apply(Accounts, args);
};
class IframeLogin {
constructor() {
this.enabled = false;
this.reactiveIframeUrl = new ReactiveVar();
this.reactiveEnabled = new ReactiveVar();
this.iframeUrl = undefined;
this.apiUrl = undefined;
this.apiMethod = undefined;
Tracker.autorun((c) => {
this.enabled = RocketChat.settings.get('Accounts_iframe_enabled');
this.reactiveEnabled.set(this.enabled);
this.iframeUrl = RocketChat.settings.get('Accounts_iframe_url');
this.apiUrl = RocketChat.settings.get('Accounts_Iframe_api_url');
this.apiMethod = RocketChat.settings.get('Accounts_Iframe_api_method');
if (this.enabled === false) {
return c.stop();
}
if (this.enabled === true && this.iframeUrl && this.apiUrl && this.apiMethod) {
c.stop();
if (!Accounts._storedLoginToken()) {
this.tryLogin(() => {});
}
}
});
}
tryLogin(callback) {
if (!this.enabled) {
return;
}
if (!this.iframeUrl || !this.apiUrl || !this.apiMethod) {
return;
}
console.log('tryLogin');
const options = {
beforeSend: (xhr) => {
xhr.withCredentials = true;
},
};
let { iframeUrl } = this;
let separator = '?';
if (iframeUrl.indexOf('?') > -1) {
separator = '&';
}
if (window.cordova) {
iframeUrl += `${ separator }client=cordova`;
} else if (navigator.userAgent.indexOf('Electron') > -1) {
iframeUrl += `${ separator }client=electron`;
}
HTTP.call(this.apiMethod, this.apiUrl, options, (error, result) => {
console.log(error, result);
if (result && result.data && (result.data.token || result.data.loginToken)) {
this.loginWithToken(result.data, (error, result) => {
if (error) {
this.reactiveIframeUrl.set(iframeUrl);
} else {
this.reactiveIframeUrl.set();
}
callback(error, result);
});
} else {
this.reactiveIframeUrl.set(iframeUrl);
callback(error, result);
}
});
}
loginWithToken(tokenData, callback) {
if (!this.enabled) {
return;
}
if (Match.test(tokenData, String)) {
tokenData = {
token: tokenData,
};
}
console.log('loginWithToken');
if (tokenData.loginToken) {
return Meteor.loginWithToken(tokenData.loginToken, callback);
}
Accounts.callLoginMethod({
methodArguments: [{
iframe: true,
token: tokenData.token,
}],
userCallback: callback,
});
}
}
RocketChat.iframeLogin = new IframeLogin();
const requestCredential = (serviceName, options = {}, callback) => {

@ -9,6 +9,7 @@ Package.onUse(function(api) {
'rocketchat:logger',
'kadira:flow-router',
'rocketchat:lib',
'rocketchat:ui-utils',
'accounts-base',
'ecmascript',
'reactive-var',

@ -1,14 +1,4 @@
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Layout } from 'meteor/rocketchat:ui-utils';
RocketChat.Layout = new (class RocketChatLayout {
constructor() {
Tracker.autorun(() => {
this.layout = FlowRouter.getQueryParam('layout');
});
}
RocketChat.Layout = Layout;
isEmbedded() {
return this.layout === 'embedded';
}
});

@ -1,4 +1,4 @@
import { CachedCollection, CachedCollectionManager } from 'meteor/rocketchat:models';
import { CachedCollection, CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection';
RocketChat.CachedCollectionManager = CachedCollectionManager;
RocketChat.CachedCollection = CachedCollection;

@ -1,54 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { ReactiveDict } from 'meteor/reactive-dict';
import { t } from 'meteor/rocketchat:utils';
/*
* RocketChat.settings holds all packages settings
* @namespace RocketChat.settings
*/
RocketChat.settings.cachedCollection = new RocketChat.CachedCollection({
name: 'public-settings',
eventType: 'onAll',
userRelated: false,
listenChangesForLoggedUsersOnly: true,
});
RocketChat.settings.collection = RocketChat.settings.cachedCollection.collection;
RocketChat.settings.cachedCollection.init();
RocketChat.settings.dict = new ReactiveDict('settings');
RocketChat.settings.get = function(_id) {
return RocketChat.settings.dict.get(_id);
};
RocketChat.settings.init = function() {
let initialLoad = true;
RocketChat.settings.collection.find().observe({
added(record) {
Meteor.settings[record._id] = record.value;
RocketChat.settings.dict.set(record._id, record.value);
RocketChat.settings.load(record._id, record.value, initialLoad);
},
changed(record) {
Meteor.settings[record._id] = record.value;
RocketChat.settings.dict.set(record._id, record.value);
RocketChat.settings.load(record._id, record.value, initialLoad);
},
removed(record) {
delete Meteor.settings[record._id];
RocketChat.settings.dict.set(record._id, null);
RocketChat.settings.load(record._id, null, initialLoad);
},
});
initialLoad = false;
};
RocketChat.settings.init();
Meteor.startup(function() {
if (Meteor.isCordova === true) {
return;

@ -0,0 +1,3 @@
import { tooltip } from 'meteor/rocketchat:tooltip';
RocketChat.tooltip = tooltip;

@ -32,6 +32,7 @@ Package.onUse(function(api) {
api.use('rocketchat:notifications');
api.use('rocketchat:promises');
api.use('rocketchat:ui-utils');
api.use('rocketchat:tooltip');
api.use('rocketchat:accounts');
api.use('modules');
api.use('rocketchat:i18n');
@ -235,6 +236,7 @@ Package.onUse(function(api) {
api.addFiles('client/lib/Layout.js', 'client');
api.addFiles('client/lib/handleError.js', 'client');
api.addFiles('client/lib/authorization.js', 'client');
api.addFiles('client/lib/tooltip.js', 'client');
// CLIENT LIB STARTUP
api.addFiles('client/lib/startup/commands.js', 'client');

@ -8,7 +8,6 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:settings',
'rocketchat:migrations',
'rocketchat:version',
]);

@ -1,5 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { settings } from 'meteor/rocketchat:settings';
import { Migrations } from 'meteor/rocketchat:migrations';
import client from 'prom-client';
import connect from 'connect';
@ -77,12 +76,12 @@ metrics.totalPrivateGroupMessages = new client.Gauge({ name: 'rocketchat_private
metrics.totalDirectMessages = new client.Gauge({ name: 'rocketchat_direct_messages_total', help: 'total of messages in direct rooms' });
metrics.totalLivechatMessages = new client.Gauge({ name: 'rocketchat_livechat_messages_total', help: 'total of messages in livechat rooms' });
client.register.setDefaultLabels({
uniqueId: settings.get('uniqueID'),
siteUrl: settings.get('Site_Url'),
});
const setPrometheusData = async() => {
const { settings } = await import('meteor/rocketchat:settings');
client.register.setDefaultLabels({
uniqueId: settings.get('uniqueID'),
siteUrl: settings.get('Site_Url'),
});
const date = new Date();
if (!Info) {
const Utils = await import('meteor/rocketchat:utils');
@ -167,7 +166,8 @@ app.use('/', (req, res) => {
const server = http.createServer(app);
let timer;
const updatePrometheusConfig = () => {
const updatePrometheusConfig = async() => {
const { settings } = await import('meteor/rocketchat:settings');
const port = settings.get('Prometheus_Port');
const enabled = settings.get('Prometheus_Enabled');
if (port == null || enabled == null) {
@ -186,5 +186,8 @@ const updatePrometheusConfig = () => {
}
};
settings.get('Prometheus_Enabled', updatePrometheusConfig);
settings.get('Prometheus_Port', updatePrometheusConfig);
Meteor.startup(async() => {
const { settings } = await import('meteor/rocketchat:settings');
settings.get('Prometheus_Enabled', updatePrometheusConfig);
settings.get('Prometheus_Port', updatePrometheusConfig);
});

@ -3,7 +3,6 @@ import { Base } from './models/_Base';
import Avatars from './models/Avatars';
import Uploads from './models/Uploads';
import UserDataFiles from './models/UserDataFiles';
import { CachedCollection, CachedCollectionManager } from './models/CachedCollection';
import { Roles } from './models/Roles';
import { Subscriptions as subscriptions } from './models/Subscriptions';
import { Users as users } from './models/Users';
@ -31,8 +30,6 @@ export {
Avatars,
Uploads,
UserDataFiles,
CachedCollection,
CachedCollectionManager,
Roles,
Subscriptions,
Users,

@ -1,3 +1,3 @@
import { CachedCollection } from './CachedCollection';
import { CachedCollection } from 'meteor/rocketchat:ui-cached-collection';
export const CachedChatRoom = new CachedCollection({ name: 'rooms' });

@ -1,3 +1,3 @@
import { CachedCollection } from './CachedCollection';
import { CachedCollection } from 'meteor/rocketchat:ui-cached-collection';
export const CachedChatSubscription = new CachedCollection({ name: 'subscriptions' });

@ -1,4 +1,4 @@
import { CachedCollection } from './CachedCollection';
import { CachedCollection } from 'meteor/rocketchat:ui-cached-collection';
export const AuthzCachedCollection = new CachedCollection({
name: 'permissions',

@ -10,6 +10,7 @@ Package.onUse(function(api) {
'ecmascript',
'rocketchat:settings',
'rocketchat:callbacks',
'rocketchat:ui-cached-collection',
'konecty:multiple-instances-status',
]);
api.mainModule('client/index.js', 'client');

@ -1,4 +1,4 @@
import { settings } from '../lib/settings';
import { settings } from './lib/settings';
export {
settings,

@ -0,0 +1,47 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveDict } from 'meteor/reactive-dict';
import { CachedCollection } from 'meteor/rocketchat:ui-cached-collection';
import { settings } from '../../lib/settings';
settings.cachedCollection = new CachedCollection({
name: 'public-settings',
eventType: 'onAll',
userRelated: false,
listenChangesForLoggedUsersOnly: true,
});
settings.collection = settings.cachedCollection.collection;
settings.cachedCollection.init();
settings.dict = new ReactiveDict('settings');
settings.get = function(_id) {
return settings.dict.get(_id);
};
settings.init = function() {
let initialLoad = true;
settings.collection.find().observe({
added(record) {
Meteor.settings[record._id] = record.value;
settings.dict.set(record._id, record.value);
settings.load(record._id, record.value, initialLoad);
},
changed(record) {
Meteor.settings[record._id] = record.value;
settings.dict.set(record._id, record.value);
settings.load(record._id, record.value, initialLoad);
},
removed(record) {
delete Meteor.settings[record._id];
settings.dict.set(record._id, null);
settings.load(record._id, null, initialLoad);
},
});
initialLoad = false;
};
settings.init();
export { settings };

@ -8,6 +8,7 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:ui-cached-collection',
]);
api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');

@ -1,3 +1,4 @@
import './rocketchat-tooltip.html';
import './rocketchat-tooltip';
import './init';
import { tooltip } from './rocketchat-tooltip';
export { tooltip };

@ -1,6 +0,0 @@
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
Template.main.onCreated(function() {
RocketChat.tooltip.init();
});

@ -1,8 +1,7 @@
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Blaze } from 'meteor/blaze';
RocketChat.tooltip = {
export const tooltip = {
source: null,
initiated: false,
opened: false,

@ -10,9 +10,6 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'templating',
'rocketchat:lib',
'rocketchat:theme',
'rocketchat:ui-master',
]);
api.addFiles('client/tooltip.css', 'client');
api.mainModule('client/index.js', 'client');

@ -0,0 +1 @@
export { CachedCollection, CachedCollectionManager } from './models/CachedCollection';

@ -0,0 +1,19 @@
Package.describe({
name: 'rocketchat:ui-cached-collection',
version: '0.0.1',
// Brief, one-line summary of the package.
summary: '',
// URL to the Git repository containing the source code for this package.
git: '',
// By default, Meteor will default to using README.md for documentation.
// To avoid submitting documentation, set this field to null.
documentation: 'README.md',
});
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:callbacks',
]);
api.mainModule('client/index.js', 'client');
});

@ -0,0 +1,5 @@
import './main.html';
import './loading.html';
import './error.html';
import './logoLayout.html';
import './main';

@ -2,15 +2,20 @@ import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { t } from 'meteor/rocketchat:utils';
import { t, getUserPreference } from 'meteor/rocketchat:utils';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { mainReady } from 'meteor/rocketchat:ui-utils';
import { mainReady, Layout, iframeLogin, modal, popover, menu, fireGlobalEvent } from 'meteor/rocketchat:ui-utils';
import { toolbarSearch } from 'meteor/rocketchat:ui-sidenav';
import { settings } from 'meteor/rocketchat:settings';
import { CachedChatSubscription, Roles, ChatSubscription } from 'meteor/rocketchat:models';
import { CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection';
import { hasRole } from 'meteor/rocketchat:authorization';
import { tooltip } from 'meteor/rocketchat:tooltip';
import Clipboard from 'clipboard';
import s from 'underscore.string';
RocketChat.settings.collection.find({ _id:/theme-color-rc/i }, { fields:{ value: 1 } }).observe({ changed: () => { DynamicCss.run(true); } });
settings.collection.find({ _id:/theme-color-rc/i }, { fields:{ value: 1 } }).observe({ changed: () => { DynamicCss.run(true); } });
Template.body.onRendered(function() {
new Clipboard('.clipboard');
@ -86,7 +91,7 @@ Template.body.onRendered(function() {
if (link.origin === s.rtrim(Meteor.absoluteUrl(), '/') && /msg=([a-zA-Z0-9]+)/.test(link.search)) {
e.preventDefault();
e.stopPropagation();
if (RocketChat.Layout.isEmbedded()) {
if (Layout.isEmbedded()) {
return fireGlobalEvent('click-message-link', {
link: link.pathname + link.search,
});
@ -101,7 +106,7 @@ Template.body.onRendered(function() {
const d = document;
const script = 'script';
const l = 'dataLayer';
const i = RocketChat.settings.get('GoogleTagManager_id');
const i = settings.get('GoogleTagManager_id');
if (Match.test(i, String) && i.trim() !== '') {
c.stop();
return (function(w, d, s, l, i) {
@ -124,17 +129,20 @@ Template.body.onRendered(function() {
}
});
RocketChat.mainReady = mainReady;
Template.main.onCreated(function() {
tooltip.init();
});
Template.main.helpers({
removeSidenav() {
const { modal } = this;
return (modal || typeof modal === 'function' ? modal() : modal); // || RocketChat.Layout.isEmbedded();
},
siteName() {
return RocketChat.settings.get('Site_Name');
return settings.get('Site_Name');
},
logged() {
if (Meteor.userId() != null || (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true && Session.get('forceLogin') !== true)) {
if (Meteor.userId() != null || (settings.get('Accounts_AllowAnonymousRead') === true && Session.get('forceLogin') !== true)) {
$('html').addClass('noscroll').removeClass('scroll');
return true;
} else {
@ -143,26 +151,26 @@ Template.main.helpers({
}
},
useIframe() {
const iframeEnabled = typeof RocketChat.iframeLogin !== 'undefined';
return iframeEnabled && RocketChat.iframeLogin.reactiveEnabled.get();
const iframeEnabled = typeof iframeLogin !== 'undefined';
return iframeEnabled && iframeLogin.reactiveEnabled.get();
},
iframeUrl() {
const iframeEnabled = typeof RocketChat.iframeLogin !== 'undefined';
return iframeEnabled && RocketChat.iframeLogin.reactiveIframeUrl.get();
const iframeEnabled = typeof iframeLogin !== 'undefined';
return iframeEnabled && iframeLogin.reactiveIframeUrl.get();
},
subsReady() {
const routerReady = FlowRouter.subsReady('userData', 'activeUsers');
const subscriptionsReady = CachedChatSubscription.ready.get();
const settingsReady = RocketChat.settings.cachedCollection.ready.get();
const settingsReady = settings.cachedCollection.ready.get();
const ready = (Meteor.userId() == null) || (routerReady && subscriptionsReady && settingsReady);
RocketChat.CachedCollectionManager.syncEnabled = ready;
CachedCollectionManager.syncEnabled = ready;
Meteor.defer(() => {
RocketChat.mainReady.set(ready);
mainReady.set(ready);
});
return ready;
},
hasUsername() {
return (Meteor.userId() != null && Meteor.user().username != null) || (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true);
return (Meteor.userId() != null && Meteor.user().username != null) || (Meteor.userId() == null && settings.get('Accounts_AllowAnonymousRead') === true);
},
requirePasswordChange() {
const user = Meteor.user();
@ -176,31 +184,31 @@ Template.main.helpers({
return false;
}
const mandatoryRole = RocketChat.models.Roles.findOne({ _id: { $in: user.roles }, mandatory2fa: true });
const mandatoryRole = Roles.findOne({ _id: { $in: user.roles }, mandatory2fa: true });
return mandatoryRole !== undefined;
},
CustomScriptLoggedOut() {
const script = RocketChat.settings.get('Custom_Script_Logged_Out') || '';
const script = settings.get('Custom_Script_Logged_Out') || '';
if (script.trim()) {
eval(script);//eslint-disable-line
}
},
CustomScriptLoggedIn() {
const script = RocketChat.settings.get('Custom_Script_Logged_In') || '';
const script = settings.get('Custom_Script_Logged_In') || '';
if (script.trim()) {
eval(script);//eslint-disable-line
}
},
embeddedVersion() {
if (RocketChat.Layout.isEmbedded()) {
if (Layout.isEmbedded()) {
return 'embedded-view';
}
},
showSetupWizard() {
const userId = Meteor.userId();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');
const Show_Setup_Wizard = settings.get('Show_Setup_Wizard');
return (!userId && Show_Setup_Wizard === 'pending') || (userId && RocketChat.authz.hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress');
return (!userId && Show_Setup_Wizard === 'pending') || (userId && hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress');
},
});
@ -221,21 +229,21 @@ Template.main.onRendered(function() {
});
return Tracker.autorun(function() {
const userId = Meteor.userId();
const Show_Setup_Wizard = RocketChat.settings.get('Show_Setup_Wizard');
const Show_Setup_Wizard = settings.get('Show_Setup_Wizard');
if ((!userId && Show_Setup_Wizard === 'pending') || (userId && RocketChat.authz.hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress')) {
if ((!userId && Show_Setup_Wizard === 'pending') || (userId && hasRole(userId, 'admin') && Show_Setup_Wizard === 'in_progress')) {
FlowRouter.go('setup-wizard');
}
if (RocketChat.getUserPreference(userId, 'hideUsernames')) {
if (getUserPreference(userId, 'hideUsernames')) {
$(document.body).on('mouseleave', 'button.thumb', function() {
return RocketChat.tooltip.hide();
return tooltip.hide();
});
return $(document.body).on('mouseenter', 'button.thumb', function(e) {
const avatarElem = $(e.currentTarget);
const username = avatarElem.attr('data-username');
if (username) {
e.stopPropagation();
return RocketChat.tooltip.showElement($('<span>').text(username), avatarElem);
return tooltip.showElement($('<span>').text(username), avatarElem);
}
});
} else {

@ -16,20 +16,14 @@ Package.onUse(function(api) {
'ecmascript',
'templating',
'reactive-var',
'rocketchat:lib',
'rocketchat:utils',
'rocketchat:tooltip',
'rocketchat:ui-utils',
'rocketchat:ui-sidenav',
'meteorhacks:inject-initial',
]);
api.addFiles('client/main.html', 'client');
api.addFiles('client/loading.html', 'client');
api.addFiles('client/error.html', 'client');
api.addFiles('client/logoLayout.html', 'client');
api.addFiles('client/main.js', 'client');
api.addFiles('server/inject.js', 'server');
api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');
api.addAssets('server/dynamic-css.js', 'server');
api.addAssets('public/icons.svg', 'server');
});

@ -1,11 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { Inject } from 'meteor/meteorhacks:inject-initial';
import { Settings } from 'meteor/rocketchat:models';
import { settings } from 'meteor/rocketchat:settings';
import _ from 'underscore';
import s from 'underscore.string';
const renderDynamicCssList = _.debounce(Meteor.bindEnvironment(() => {
// const variables = RocketChat.models.Settings.findOne({_id:'theme-custom-variables'}, {fields: { value: 1}});
const colors = RocketChat.models.Settings.find({ _id:/theme-color-rc/i }, { fields: { value: 1, editor: 1 } }).fetch().filter((color) => color && color.value);
const colors = Settings.find({ _id:/theme-color-rc/i }, { fields: { value: 1, editor: 1 } }).fetch().filter((color) => color && color.value);
if (!colors) {
return;
@ -25,7 +27,7 @@ renderDynamicCssList();
// changed: renderDynamicCssList
// });
RocketChat.models.Settings.find({ _id:/theme-color-rc/i }, { fields: { value: 1 } }).observe({
Settings.find({ _id:/theme-color-rc/i }, { fields: { value: 1 } }).observe({
changed: renderDynamicCssList,
});
@ -57,7 +59,7 @@ if (process.env.DISABLE_ANIMATION || process.env.TEST_MODE === 'true') {
`);
}
RocketChat.settings.get('Assets_SvgFavicon_Enable', (key, value) => {
settings.get('Assets_SvgFavicon_Enable', (key, value) => {
const standardFavicons = `
<link rel="icon" sizes="16x16" type="image/png" href="assets/favicon_16.png" />
<link rel="icon" sizes="32x32" type="image/png" href="assets/favicon_32.png" />`;
@ -71,13 +73,13 @@ RocketChat.settings.get('Assets_SvgFavicon_Enable', (key, value) => {
}
});
RocketChat.settings.get('theme-color-sidebar-background', (key, value) => {
settings.get('theme-color-sidebar-background', (key, value) => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key, `<meta name="msapplication-TileColor" content="${ escapedValue }" />` +
`<meta name="theme-color" content="${ escapedValue }" />`);
});
RocketChat.settings.get('Accounts_ForgetUserSessionOnWindowClose', (key, value) => {
settings.get('Accounts_ForgetUserSessionOnWindowClose', (key, value) => {
if (value) {
Inject.rawModHtml(key, (html) => {
const script = `
@ -94,7 +96,7 @@ RocketChat.settings.get('Accounts_ForgetUserSessionOnWindowClose', (key, value)
}
});
RocketChat.settings.get('Site_Name', (key, value = 'Rocket.Chat') => {
settings.get('Site_Name', (key, value = 'Rocket.Chat') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key,
`<title>${ escapedValue }</title>` +
@ -102,34 +104,34 @@ RocketChat.settings.get('Site_Name', (key, value = 'Rocket.Chat') => {
`<meta name="apple-mobile-web-app-title" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_language', (key, value = '') => {
settings.get('Meta_language', (key, value = '') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key,
`<meta http-equiv="content-language" content="${ escapedValue }">` +
`<meta name="language" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_robots', (key, value = '') => {
settings.get('Meta_robots', (key, value = '') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key, `<meta name="robots" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_msvalidate01', (key, value = '') => {
settings.get('Meta_msvalidate01', (key, value = '') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key, `<meta name="msvalidate.01" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_google-site-verification', (key, value = '') => {
settings.get('Meta_google-site-verification', (key, value = '') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key, `<meta name="google-site-verification" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_fb_app_id', (key, value = '') => {
settings.get('Meta_fb_app_id', (key, value = '') => {
const escapedValue = s.escapeHTML(value);
Inject.rawHead(key, `<meta property="fb:app_id" content="${ escapedValue }">`);
});
RocketChat.settings.get('Meta_custom', (key, value = '') => {
settings.get('Meta_custom', (key, value = '') => {
Inject.rawHead(key, value);
});

@ -13,6 +13,9 @@ import { RoomManager } from './lib/RoomManager';
import { upsertMessage, RoomHistoryManager } from './lib/RoomHistoryManager';
import { mainReady } from './lib/mainReady';
import { renderMessageBody } from './lib/renderMessageBody';
import { Layout } from './lib/Layout';
import { IframeLogin, iframeLogin } from './lib/IframeLogin';
import { fireGlobalEvent } from './lib/fireGlobalEvent';
export {
AdminBox,
@ -33,4 +36,8 @@ export {
mainReady,
renderMessageBody,
upsertMessage,
Layout,
IframeLogin,
iframeLogin,
fireGlobalEvent,
};

@ -0,0 +1,112 @@
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { settings } from 'meteor/rocketchat:settings';
import { Accounts } from 'meteor/accounts-base';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { HTTP } from 'meteor/http';
export class IframeLogin {
constructor() {
this.enabled = false;
this.reactiveIframeUrl = new ReactiveVar();
this.reactiveEnabled = new ReactiveVar();
this.iframeUrl = undefined;
this.apiUrl = undefined;
this.apiMethod = undefined;
Tracker.autorun((c) => {
this.enabled = settings.get('Accounts_iframe_enabled');
this.reactiveEnabled.set(this.enabled);
this.iframeUrl = settings.get('Accounts_iframe_url');
this.apiUrl = settings.get('Accounts_Iframe_api_url');
this.apiMethod = settings.get('Accounts_Iframe_api_method');
if (this.enabled === false) {
return c.stop();
}
if (this.enabled === true && this.iframeUrl && this.apiUrl && this.apiMethod) {
c.stop();
if (!Accounts._storedLoginToken()) {
this.tryLogin(() => {});
}
}
});
}
tryLogin(callback) {
if (!this.enabled) {
return;
}
if (!this.iframeUrl || !this.apiUrl || !this.apiMethod) {
return;
}
console.log('tryLogin');
const options = {
beforeSend: (xhr) => {
xhr.withCredentials = true;
},
};
let { iframeUrl } = this;
let separator = '?';
if (iframeUrl.indexOf('?') > -1) {
separator = '&';
}
if (window.cordova) {
iframeUrl += `${ separator }client=cordova`;
} else if (navigator.userAgent.indexOf('Electron') > -1) {
iframeUrl += `${ separator }client=electron`;
}
HTTP.call(this.apiMethod, this.apiUrl, options, (error, result) => {
console.log(error, result);
if (result && result.data && (result.data.token || result.data.loginToken)) {
this.loginWithToken(result.data, (error, result) => {
if (error) {
this.reactiveIframeUrl.set(iframeUrl);
} else {
this.reactiveIframeUrl.set();
}
callback(error, result);
});
} else {
this.reactiveIframeUrl.set(iframeUrl);
callback(error, result);
}
});
}
loginWithToken(tokenData, callback) {
if (!this.enabled) {
return;
}
if (Match.test(tokenData, String)) {
tokenData = {
token: tokenData,
};
}
console.log('loginWithToken');
if (tokenData.loginToken) {
return Meteor.loginWithToken(tokenData.loginToken, callback);
}
Accounts.callLoginMethod({
methodArguments: [{
iframe: true,
token: tokenData.token,
}],
userCallback: callback,
});
}
}
export const iframeLogin = new IframeLogin();

@ -0,0 +1,14 @@
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
export const Layout = new (class RocketChatLayout {
constructor() {
Tracker.autorun(() => {
this.layout = FlowRouter.getQueryParam('layout');
});
}
isEmbedded() {
return this.layout === 'embedded';
}
});

@ -8,7 +8,8 @@ import { roomTypes as _roomTypes } from 'meteor/rocketchat:utils';
import { promises } from 'meteor/rocketchat:promises';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { Notifications } from 'meteor/rocketchat:notifications';
import { CachedChatRoom, ChatMessage, ChatSubscription, CachedChatSubscription, CachedCollectionManager } from 'meteor/rocketchat:models';
import { CachedChatRoom, ChatMessage, ChatSubscription, CachedChatSubscription } from 'meteor/rocketchat:models';
import { CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection';
import _ from 'underscore';
import { upsertMessage, RoomHistoryManager } from './RoomHistoryManager';
import { mainReady } from './mainReady';

@ -0,0 +1,20 @@
import { settings } from 'meteor/rocketchat:settings';
import { Tracker } from 'meteor/tracker';
export const fireGlobalEvent = function _fireGlobalEvent(eventName, params) {
window.dispatchEvent(new CustomEvent(eventName, { detail: params }));
Tracker.autorun((computation) => {
const enabled = settings.get('Iframe_Integration_send_enable');
if (enabled === undefined) {
return;
}
computation.stop();
if (enabled) {
parent.postMessage({
eventName,
data: params,
}, settings.get('Iframe_Integration_send_target_origin'));
}
});
};

@ -9,6 +9,7 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'http',
'templating',
'kadira:flow-router',
'kadira:blaze-layout',

@ -1,20 +1,3 @@
import { Tracker } from 'meteor/tracker';
fireGlobalEvent = function _fireGlobalEvent(eventName, params) {
window.dispatchEvent(new CustomEvent(eventName, { detail: params }));
Tracker.autorun((computation) => {
const enabled = RocketChat.settings.get('Iframe_Integration_send_enable');
if (enabled === undefined) {
return;
}
computation.stop();
if (enabled) {
parent.postMessage({
eventName,
data: params,
}, RocketChat.settings.get('Iframe_Integration_send_target_origin'));
}
});
};
import { fireGlobalEvent as _fireGlobalEvent } from 'meteor/rocketchat:ui-utils';
fireGlobalEvent = _fireGlobalEvent;

Loading…
Cancel
Save