From 6ed0e44722b5c5cdbf4a3dbc7e785423c082f7e6 Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Wed, 20 May 2020 21:38:40 -0300 Subject: [PATCH] [IMPROVE] Remove index files from action-links, accounts and assets (#17607) --- app/accounts/index.js | 1 - app/action-links/client/index.js | 3 +- app/action-links/client/init.js | 6 +- app/action-links/client/lib/actionLinks.js | 65 ++++++++++++++----- app/action-links/index.js | 8 --- app/action-links/server/actionLinkHandler.js | 2 +- app/action-links/server/index.js | 2 +- .../{both => server}/lib/actionLinks.js | 2 +- app/api/index.js | 1 - app/api/server/v1/assets.js | 2 +- app/assets/index.js | 1 - app/bigbluebutton/index.js | 1 - app/bigbluebutton/server/index.js | 1 + app/blockstack/server/routes.js | 2 +- app/bot-helpers/index.js | 1 - app/integrations/server/api/api.js | 2 +- app/livechat/client/index.js | 1 + app/livechat/client/lib/messageTypes.js | 5 ++ app/livechat/imports/server/rest/agent.js | 2 +- .../imports/server/rest/appearance.js | 2 +- .../imports/server/rest/dashboards.js | 2 +- .../imports/server/rest/departments.js | 2 +- app/livechat/imports/server/rest/facebook.js | 2 +- app/livechat/imports/server/rest/inquiries.js | 2 +- .../imports/server/rest/integrations.js | 2 +- app/livechat/imports/server/rest/messages.js | 2 +- .../imports/server/rest/officeHour.js | 2 +- app/livechat/imports/server/rest/queue.js | 2 +- app/livechat/imports/server/rest/rooms.js | 2 +- app/livechat/imports/server/rest/sms.js | 2 +- app/livechat/imports/server/rest/triggers.js | 2 +- app/livechat/imports/server/rest/upload.js | 2 +- app/livechat/imports/server/rest/users.js | 2 +- app/livechat/imports/server/rest/visitors.js | 2 +- app/livechat/lib/messageTypes.js | 32 --------- app/livechat/server/api/v1/agent.js | 2 +- app/livechat/server/api/v1/config.js | 2 +- app/livechat/server/api/v1/customField.js | 2 +- app/livechat/server/api/v1/message.js | 2 +- app/livechat/server/api/v1/offlineMessage.js | 2 +- app/livechat/server/api/v1/pageVisited.js | 2 +- app/livechat/server/api/v1/room.js | 2 +- app/livechat/server/api/v1/transcript.js | 2 +- app/livechat/server/api/v1/transfer.js | 2 +- app/livechat/server/api/v1/videoCall.js | 2 +- app/livechat/server/api/v1/visitor.js | 2 +- app/livechat/server/index.js | 1 + app/livechat/server/lib/messageTypes.js | 26 ++++++++ app/livestream/server/routes.js | 2 +- .../server/oauth/oauth2-server.js | 2 +- app/videobridge/client/actionLink.js | 2 +- app/videobridge/server/actionLink.js | 2 +- app/videobridge/server/methods/bbb.js | 4 +- client/importPackages.js | 2 +- .../api-enterprise/server/canned-responses.js | 2 +- .../server/api/channels.js | 2 +- .../server/api/messages.js | 2 +- .../engagement-dashboard/server/api/users.js | 2 +- .../imports/server/rest/departments.js | 2 +- .../livechat/imports/server/rest/inquiries.js | 2 +- ee/app/livechat/imports/server/rest/rooms.js | 2 +- ee/app/livechat/imports/server/rest/sms.js | 2 +- ee/app/livechat/imports/server/rest/upload.js | 2 +- server/importPackages.js | 12 ++-- server/startup/migrations/v036.js | 2 +- server/startup/migrations/v042.js | 2 +- 66 files changed, 143 insertions(+), 124 deletions(-) delete mode 100644 app/accounts/index.js delete mode 100644 app/action-links/index.js rename app/action-links/{both => server}/lib/actionLinks.js (93%) delete mode 100644 app/api/index.js delete mode 100644 app/assets/index.js delete mode 100644 app/bigbluebutton/index.js create mode 100644 app/bigbluebutton/server/index.js delete mode 100644 app/bot-helpers/index.js create mode 100644 app/livechat/client/lib/messageTypes.js create mode 100644 app/livechat/server/lib/messageTypes.js diff --git a/app/accounts/index.js b/app/accounts/index.js deleted file mode 100644 index ca39cd0df4b1..000000000000 --- a/app/accounts/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './server/index'; diff --git a/app/action-links/client/index.js b/app/action-links/client/index.js index 34c929c096f9..c09886562a2d 100644 --- a/app/action-links/client/index.js +++ b/app/action-links/client/index.js @@ -1,5 +1,4 @@ -import { actionLinks } from '../both/lib/actionLinks'; -import './lib/actionLinks'; +import { actionLinks } from './lib/actionLinks'; import './init'; import './stylesheets/actionLinks.css'; diff --git a/app/action-links/client/init.js b/app/action-links/client/init.js index 64b3fc4acb4c..b5f218b1ca18 100644 --- a/app/action-links/client/init.js +++ b/app/action-links/client/init.js @@ -1,10 +1,10 @@ import { Blaze } from 'meteor/blaze'; import { Template } from 'meteor/templating'; -import { handleError } from '../../utils'; -import { fireGlobalEvent, Layout } from '../../ui-utils'; +import { handleError } from '../../utils/client'; +import { fireGlobalEvent, Layout } from '../../ui-utils/client'; import { messageArgs } from '../../ui-utils/client/lib/messageArgs'; -import { actionLinks } from '../both/lib/actionLinks'; +import { actionLinks } from './lib/actionLinks'; Template.room.events({ diff --git a/app/action-links/client/lib/actionLinks.js b/app/action-links/client/lib/actionLinks.js index 4391eda94afb..b3d911398dad 100644 --- a/app/action-links/client/lib/actionLinks.js +++ b/app/action-links/client/lib/actionLinks.js @@ -1,27 +1,58 @@ import { Meteor } from 'meteor/meteor'; -import { handleError } from '../../../utils'; -import { actionLinks } from '../../both/lib/actionLinks'; -// Action Links Handler. This method will be called off the client. +import { handleError } from '../../../utils/client'; +import { Messages, Subscriptions } from '../../../models/client'; -actionLinks.run = (name, messageId, instance) => { - const message = actionLinks.getMessage(name, messageId); +// Action Links namespace creation. +export const actionLinks = { + actions: {}, + register(name, funct) { + actionLinks.actions[name] = funct; + }, + getMessage(name, messageId) { + const userId = Meteor.userId(); + if (!userId) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { function: 'actionLinks.getMessage' }); + } + + const message = Messages.findOne({ _id: messageId }); + if (!message) { + throw new Meteor.Error('error-invalid-message', 'Invalid message', { function: 'actionLinks.getMessage' }); + } + + const subscription = Subscriptions.findOne({ + rid: message.rid, + 'u._id': userId, + }); + if (!subscription) { + throw new Meteor.Error('error-not-allowed', 'Not allowed', { function: 'actionLinks.getMessage' }); + } + + if (!message.actionLinks || !message.actionLinks[name]) { + throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link', { function: 'actionLinks.getMessage' }); + } - const actionLink = message.actionLinks[name]; + return message; + }, + run(name, messageId, instance) { + const message = actionLinks.getMessage(name, messageId); - let ranClient = false; + const actionLink = message.actionLinks[name]; - if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) { - // run just on client side - actionLinks.actions[actionLink.method_id](message, actionLink.params, instance); + let ranClient = false; - ranClient = true; - } + if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) { + // run just on client side + actionLinks.actions[actionLink.method_id](message, actionLink.params, instance); - // and run on server side - Meteor.call('actionLinkHandler', name, messageId, (err) => { - if (err && !ranClient) { - handleError(err); + ranClient = true; } - }); + + // and run on server side + Meteor.call('actionLinkHandler', name, messageId, (err) => { + if (err && !ranClient) { + handleError(err); + } + }); + }, }; diff --git a/app/action-links/index.js b/app/action-links/index.js deleted file mode 100644 index a67eca871efb..000000000000 --- a/app/action-links/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -if (Meteor.isClient) { - module.exports = require('./client/index.js'); -} -if (Meteor.isServer) { - module.exports = require('./server/index.js'); -} diff --git a/app/action-links/server/actionLinkHandler.js b/app/action-links/server/actionLinkHandler.js index 067f727e3dda..7ccd1b05775b 100644 --- a/app/action-links/server/actionLinkHandler.js +++ b/app/action-links/server/actionLinkHandler.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { actionLinks } from '../both/lib/actionLinks'; +import { actionLinks } from './lib/actionLinks'; // Action Links Handler. This method will be called off the client. Meteor.methods({ diff --git a/app/action-links/server/index.js b/app/action-links/server/index.js index b1c484f79888..a6fb9f92b743 100644 --- a/app/action-links/server/index.js +++ b/app/action-links/server/index.js @@ -1,4 +1,4 @@ -import { actionLinks } from '../both/lib/actionLinks'; +import { actionLinks } from './lib/actionLinks'; import './actionLinkHandler'; export { diff --git a/app/action-links/both/lib/actionLinks.js b/app/action-links/server/lib/actionLinks.js similarity index 93% rename from app/action-links/both/lib/actionLinks.js rename to app/action-links/server/lib/actionLinks.js index c87c712e079b..3f7b2f2e5775 100644 --- a/app/action-links/both/lib/actionLinks.js +++ b/app/action-links/server/lib/actionLinks.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { Messages, Subscriptions } from '../../../models'; +import { Messages, Subscriptions } from '../../../models/server'; // Action Links namespace creation. export const actionLinks = { diff --git a/app/api/index.js b/app/api/index.js deleted file mode 100644 index ca39cd0df4b1..000000000000 --- a/app/api/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './server/index'; diff --git a/app/api/server/v1/assets.js b/app/api/server/v1/assets.js index eacf92ae31cd..108f9649ffe6 100644 --- a/app/api/server/v1/assets.js +++ b/app/api/server/v1/assets.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import Busboy from 'busboy'; -import { RocketChatAssets } from '../../../assets'; +import { RocketChatAssets } from '../../../assets/server'; import { API } from '../api'; API.v1.addRoute('assets.setAsset', { authRequired: true }, { diff --git a/app/assets/index.js b/app/assets/index.js deleted file mode 100644 index ca39cd0df4b1..000000000000 --- a/app/assets/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './server/index'; diff --git a/app/bigbluebutton/index.js b/app/bigbluebutton/index.js deleted file mode 100644 index ba58589ba3d7..000000000000 --- a/app/bigbluebutton/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './server/bigbluebutton-api'; diff --git a/app/bigbluebutton/server/index.js b/app/bigbluebutton/server/index.js new file mode 100644 index 000000000000..b6be696a20bd --- /dev/null +++ b/app/bigbluebutton/server/index.js @@ -0,0 +1 @@ +export { default } from './bigbluebutton-api'; diff --git a/app/blockstack/server/routes.js b/app/blockstack/server/routes.js index ee4c7cc087df..81902030e426 100644 --- a/app/blockstack/server/routes.js +++ b/app/blockstack/server/routes.js @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { WebApp } from 'meteor/webapp'; import { settings } from '../../settings'; -import { RocketChatAssets } from '../../assets'; +import { RocketChatAssets } from '../../assets/server'; WebApp.connectHandlers.use('/_blockstack/manifest', Meteor.bindEnvironment(function(req, res) { const name = settings.get('Site_Name'); diff --git a/app/bot-helpers/index.js b/app/bot-helpers/index.js deleted file mode 100644 index f5778a23b606..000000000000 --- a/app/bot-helpers/index.js +++ /dev/null @@ -1 +0,0 @@ -import './server/index'; diff --git a/app/integrations/server/api/api.js b/app/integrations/server/api/api.js index db79dc0943bd..aa55b3bd1fad 100644 --- a/app/integrations/server/api/api.js +++ b/app/integrations/server/api/api.js @@ -12,7 +12,7 @@ import moment from 'moment'; import { logger } from '../logger'; import { processWebhookMessage } from '../../../lib'; -import { API, APIClass, defaultRateLimiterOptions } from '../../../api'; +import { API, APIClass, defaultRateLimiterOptions } from '../../../api/server'; import * as Models from '../../../models'; import { settings } from '../../../settings/server'; diff --git a/app/livechat/client/index.js b/app/livechat/client/index.js index 26013edf70a5..0174884f532f 100644 --- a/app/livechat/client/index.js +++ b/app/livechat/client/index.js @@ -9,3 +9,4 @@ import './stylesheets/livechat.css'; import './views/sideNav/livechat'; import './views/sideNav/livechatFlex'; import './externalFrame'; +import './lib/messageTypes'; diff --git a/app/livechat/client/lib/messageTypes.js b/app/livechat/client/lib/messageTypes.js new file mode 100644 index 000000000000..0e3353f31366 --- /dev/null +++ b/app/livechat/client/lib/messageTypes.js @@ -0,0 +1,5 @@ +import { actionLinks } from '../../../action-links/client'; + +actionLinks.register('createLivechatCall', function(message, params, instance) { + instance.tabBar.open('video'); +}); diff --git a/app/livechat/imports/server/rest/agent.js b/app/livechat/imports/server/rest/agent.js index b928501dc2c1..170af7636ff2 100644 --- a/app/livechat/imports/server/rest/agent.js +++ b/app/livechat/imports/server/rest/agent.js @@ -1,6 +1,6 @@ import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findAgentDepartments } from '../../../server/api/lib/agents'; API.v1.addRoute('livechat/agents/:agentId/departments', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/appearance.js b/app/livechat/imports/server/rest/appearance.js index f8345f7d31dc..c7fe16243a78 100644 --- a/app/livechat/imports/server/rest/appearance.js +++ b/app/livechat/imports/server/rest/appearance.js @@ -1,4 +1,4 @@ -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findAppearance } from '../../../server/api/lib/appearance'; API.v1.addRoute('livechat/appearance', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/dashboards.js b/app/livechat/imports/server/rest/dashboards.js index 2537942e74dc..af8972296b20 100644 --- a/app/livechat/imports/server/rest/dashboards.js +++ b/app/livechat/imports/server/rest/dashboards.js @@ -1,6 +1,6 @@ import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { hasPermission } from '../../../../authorization/server'; import { findAllChatsStatus, diff --git a/app/livechat/imports/server/rest/departments.js b/app/livechat/imports/server/rest/departments.js index 8a255185f86f..9ec4113ba66a 100644 --- a/app/livechat/imports/server/rest/departments.js +++ b/app/livechat/imports/server/rest/departments.js @@ -1,6 +1,6 @@ import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { hasPermission } from '../../../../authorization'; import { LivechatDepartment, LivechatDepartmentAgents } from '../../../../models'; import { Livechat } from '../../../server/lib/Livechat'; diff --git a/app/livechat/imports/server/rest/facebook.js b/app/livechat/imports/server/rest/facebook.js index cce8c53a7165..b4b8efa55034 100644 --- a/app/livechat/imports/server/rest/facebook.js +++ b/app/livechat/imports/server/rest/facebook.js @@ -2,7 +2,7 @@ import crypto from 'crypto'; import { Random } from 'meteor/random'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { LivechatRooms, LivechatVisitors } from '../../../../models'; import { settings } from '../../../../settings'; import { Livechat } from '../../../server/lib/Livechat'; diff --git a/app/livechat/imports/server/rest/inquiries.js b/app/livechat/imports/server/rest/inquiries.js index a553c875fe84..3abfc5eee735 100644 --- a/app/livechat/imports/server/rest/inquiries.js +++ b/app/livechat/imports/server/rest/inquiries.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { hasPermission } from '../../../../authorization'; import { Users, LivechatDepartment, LivechatInquiry } from '../../../../models'; import { findInquiries, findOneInquiryByRoomId } from '../../../server/api/lib/inquiries'; diff --git a/app/livechat/imports/server/rest/integrations.js b/app/livechat/imports/server/rest/integrations.js index 08d9d064892a..6b7aed33d89f 100644 --- a/app/livechat/imports/server/rest/integrations.js +++ b/app/livechat/imports/server/rest/integrations.js @@ -1,4 +1,4 @@ -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findIntegrationSettings } from '../../../server/api/lib/integrations'; API.v1.addRoute('livechat/integrations.settings', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/messages.js b/app/livechat/imports/server/rest/messages.js index a40557231b53..f5ad166c8c70 100644 --- a/app/livechat/imports/server/rest/messages.js +++ b/app/livechat/imports/server/rest/messages.js @@ -1,7 +1,7 @@ import { check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findExternalMessages } from '../../../server/api/lib/messages'; API.v1.addRoute('livechat/messages.external/:roomId', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/officeHour.js b/app/livechat/imports/server/rest/officeHour.js index f321a31ea5a3..7b2cd02497ee 100644 --- a/app/livechat/imports/server/rest/officeHour.js +++ b/app/livechat/imports/server/rest/officeHour.js @@ -1,4 +1,4 @@ -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findLivechatOfficeHours } from '../../../server/api/lib/officeHour'; API.v1.addRoute('livechat/office-hours', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/queue.js b/app/livechat/imports/server/rest/queue.js index d5f319f2e3c0..43b586431ea2 100644 --- a/app/livechat/imports/server/rest/queue.js +++ b/app/livechat/imports/server/rest/queue.js @@ -1,4 +1,4 @@ -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findQueueMetrics } from '../../../server/api/lib/queue'; API.v1.addRoute('livechat/queue', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/rooms.js b/app/livechat/imports/server/rest/rooms.js index d7556006597a..052da5db3963 100644 --- a/app/livechat/imports/server/rest/rooms.js +++ b/app/livechat/imports/server/rest/rooms.js @@ -1,7 +1,7 @@ import { Match, check } from 'meteor/check'; import { hasPermission } from '../../../../authorization/server'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findRooms } from '../../../server/api/lib/rooms'; const validateDateParams = (property, date) => { diff --git a/app/livechat/imports/server/rest/sms.js b/app/livechat/imports/server/rest/sms.js index edebecb583a7..f813e7def804 100644 --- a/app/livechat/imports/server/rest/sms.js +++ b/app/livechat/imports/server/rest/sms.js @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; import { LivechatRooms, LivechatVisitors, LivechatDepartment } from '../../../../models'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { SMS } from '../../../../sms'; import { Livechat } from '../../../server/lib/Livechat'; diff --git a/app/livechat/imports/server/rest/triggers.js b/app/livechat/imports/server/rest/triggers.js index ca6ebe7a12a0..de3d0b57f27b 100644 --- a/app/livechat/imports/server/rest/triggers.js +++ b/app/livechat/imports/server/rest/triggers.js @@ -1,6 +1,6 @@ import { check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findTriggers, findTriggerById } from '../../../server/api/lib/triggers'; API.v1.addRoute('livechat/triggers', { authRequired: true }, { diff --git a/app/livechat/imports/server/rest/upload.js b/app/livechat/imports/server/rest/upload.js index 3d28f420402e..4c27811749a6 100644 --- a/app/livechat/imports/server/rest/upload.js +++ b/app/livechat/imports/server/rest/upload.js @@ -6,7 +6,7 @@ import { settings } from '../../../../settings'; import { Settings, LivechatRooms, LivechatVisitors } from '../../../../models'; import { fileUploadIsValidContentType } from '../../../../utils'; import { FileUpload } from '../../../../file-upload'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; let maxFileSize; diff --git a/app/livechat/imports/server/rest/users.js b/app/livechat/imports/server/rest/users.js index 04e1815b4f07..f0c88aa25c59 100644 --- a/app/livechat/imports/server/rest/users.js +++ b/app/livechat/imports/server/rest/users.js @@ -2,7 +2,7 @@ import { check } from 'meteor/check'; import _ from 'underscore'; import { hasPermission } from '../../../../authorization'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { Users } from '../../../../models'; import { Livechat } from '../../../server/lib/Livechat'; import { findAgents, findManagers } from '../../../server/api/lib/users'; diff --git a/app/livechat/imports/server/rest/visitors.js b/app/livechat/imports/server/rest/visitors.js index 42b5a20b25d7..c828e9552e58 100644 --- a/app/livechat/imports/server/rest/visitors.js +++ b/app/livechat/imports/server/rest/visitors.js @@ -1,7 +1,7 @@ import { check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findVisitorInfo, findVisitedPages, findChatHistory } from '../../../server/api/lib/visitors'; API.v1.addRoute('livechat/visitors.info', { authRequired: true }, { diff --git a/app/livechat/lib/messageTypes.js b/app/livechat/lib/messageTypes.js index c68e120f0542..8f870923bd28 100644 --- a/app/livechat/lib/messageTypes.js +++ b/app/livechat/lib/messageTypes.js @@ -1,12 +1,6 @@ -import { Meteor } from 'meteor/meteor'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; -import { Livechat } from 'meteor/rocketchat:livechat'; import { MessageTypes } from '../../ui-utils'; -import { actionLinks } from '../../action-links'; -import { Notifications } from '../../notifications'; -import { Messages, LivechatRooms } from '../../models'; -import { settings } from '../../settings'; MessageTypes.registerType({ id: 'livechat_navigation_history', @@ -60,29 +54,3 @@ MessageTypes.registerType({ system: true, message: 'New_videocall_request', }); - -actionLinks.register('createLivechatCall', function(message, params, instance) { - if (Meteor.isClient) { - instance.tabBar.open('video'); - } -}); - -actionLinks.register('denyLivechatCall', function(message/* , params*/) { - if (Meteor.isServer) { - const user = Meteor.user(); - - Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user); - Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id }); - - const language = user.language || settings.get('Language') || 'en'; - - Livechat.closeRoom({ - user, - room: LivechatRooms.findOneById(message.rid), - comment: TAPi18n.__('Videocall_declined', { lng: language }), - }); - Meteor.defer(() => { - Messages.setHiddenById(message._id); - }); - } -}); diff --git a/app/livechat/server/api/v1/agent.js b/app/livechat/server/api/v1/agent.js index 68ceef87da14..7e2329058542 100644 --- a/app/livechat/server/api/v1/agent.js +++ b/app/livechat/server/api/v1/agent.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findRoom, findGuest, findAgent, findOpenRoom } from '../lib/livechat'; import { Livechat } from '../../lib/Livechat'; diff --git a/app/livechat/server/api/v1/config.js b/app/livechat/server/api/v1/config.js index a1f4bab03405..50e4229fa40e 100644 --- a/app/livechat/server/api/v1/config.js +++ b/app/livechat/server/api/v1/config.js @@ -1,6 +1,6 @@ import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findGuest, settings, online, findOpenRoom, getExtraConfigInfo, findAgent } from '../lib/livechat'; API.v1.addRoute('livechat/config', { diff --git a/app/livechat/server/api/v1/customField.js b/app/livechat/server/api/v1/customField.js index f64266d3be6c..3b19e832bc65 100644 --- a/app/livechat/server/api/v1/customField.js +++ b/app/livechat/server/api/v1/customField.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findGuest } from '../lib/livechat'; import { Livechat } from '../../lib/Livechat'; import { findLivechatCustomFields, findCustomFieldById } from '../lib/customFields'; diff --git a/app/livechat/server/api/v1/message.js b/app/livechat/server/api/v1/message.js index e2362baf6d32..0811bc8324fb 100644 --- a/app/livechat/server/api/v1/message.js +++ b/app/livechat/server/api/v1/message.js @@ -4,7 +4,7 @@ import { Random } from 'meteor/random'; import { Messages, LivechatRooms, LivechatVisitors } from '../../../../models'; import { hasPermission } from '../../../../authorization'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { loadMessageHistory } from '../../../../lib'; import { findGuest, findRoom, normalizeHttpHeaderData } from '../lib/livechat'; import { Livechat } from '../../lib/Livechat'; diff --git a/app/livechat/server/api/v1/offlineMessage.js b/app/livechat/server/api/v1/offlineMessage.js index 6788c30e3d86..8264228c97e7 100644 --- a/app/livechat/server/api/v1/offlineMessage.js +++ b/app/livechat/server/api/v1/offlineMessage.js @@ -1,7 +1,7 @@ import { Match, check } from 'meteor/check'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/offline.message', { diff --git a/app/livechat/server/api/v1/pageVisited.js b/app/livechat/server/api/v1/pageVisited.js index e5ef7c42ba64..4f8c638e6146 100644 --- a/app/livechat/server/api/v1/pageVisited.js +++ b/app/livechat/server/api/v1/pageVisited.js @@ -1,7 +1,7 @@ import { Match, check } from 'meteor/check'; import _ from 'underscore'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/page.visited', { diff --git a/app/livechat/server/api/v1/room.js b/app/livechat/server/api/v1/room.js index 83af5ffe1b61..5ec9ef1cf06e 100644 --- a/app/livechat/server/api/v1/room.js +++ b/app/livechat/server/api/v1/room.js @@ -5,7 +5,7 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { settings as rcSettings } from '../../../../settings'; import { Messages, LivechatRooms } from '../../../../models'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findGuest, findRoom, getRoom, settings, findAgent, onCheckRoomParams } from '../lib/livechat'; import { Livechat } from '../../lib/Livechat'; import { normalizeTransferredByData } from '../../lib/Helper'; diff --git a/app/livechat/server/api/v1/transcript.js b/app/livechat/server/api/v1/transcript.js index 02c0d9d27561..f8f3c923d25e 100644 --- a/app/livechat/server/api/v1/transcript.js +++ b/app/livechat/server/api/v1/transcript.js @@ -1,7 +1,7 @@ import { check } from 'meteor/check'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/transcript', { diff --git a/app/livechat/server/api/v1/transfer.js b/app/livechat/server/api/v1/transfer.js index e38277d5529d..aa3fb7facd0e 100644 --- a/app/livechat/server/api/v1/transfer.js +++ b/app/livechat/server/api/v1/transfer.js @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { LivechatRooms } from '../../../../models'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findLivechatTransferHistory } from '../lib/transfer'; API.v1.addRoute('livechat/transfer.history/:rid', { authRequired: true }, { diff --git a/app/livechat/server/api/v1/videoCall.js b/app/livechat/server/api/v1/videoCall.js index 0aaa231da654..56159d8c349c 100644 --- a/app/livechat/server/api/v1/videoCall.js +++ b/app/livechat/server/api/v1/videoCall.js @@ -4,7 +4,7 @@ import { Random } from 'meteor/random'; import { Messages } from '../../../../models'; import { settings as rcSettings } from '../../../../settings'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findGuest, getRoom, settings } from '../lib/livechat'; API.v1.addRoute('livechat/video.call/:token', { diff --git a/app/livechat/server/api/v1/visitor.js b/app/livechat/server/api/v1/visitor.js index f34930a1b9c3..98007540876c 100644 --- a/app/livechat/server/api/v1/visitor.js +++ b/app/livechat/server/api/v1/visitor.js @@ -3,7 +3,7 @@ import { Match, check } from 'meteor/check'; import { LivechatRooms, LivechatVisitors, LivechatCustomField } from '../../../../models'; import { hasPermission } from '../../../../authorization'; -import { API } from '../../../../api'; +import { API } from '../../../../api/server'; import { findGuest, normalizeHttpHeaderData } from '../lib/livechat'; import { Livechat } from '../../lib/Livechat'; diff --git a/app/livechat/server/index.js b/app/livechat/server/index.js index 72632b50670e..527bc59802d6 100644 --- a/app/livechat/server/index.js +++ b/app/livechat/server/index.js @@ -84,5 +84,6 @@ import './sendMessageBySMS'; import './api'; import './api/rest'; import './externalFrame'; +import './lib/messageTypes'; export { Livechat } from './lib/Livechat'; diff --git a/app/livechat/server/lib/messageTypes.js b/app/livechat/server/lib/messageTypes.js new file mode 100644 index 000000000000..3d32da6f401f --- /dev/null +++ b/app/livechat/server/lib/messageTypes.js @@ -0,0 +1,26 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { actionLinks } from '../../../action-links/server'; +import { Notifications } from '../../../notifications/server'; +import { Messages, LivechatRooms } from '../../../models/server'; +import { settings } from '../../../settings/server'; +import { Livechat } from './Livechat'; + +actionLinks.register('denyLivechatCall', function(message/* , params*/) { + const user = Meteor.user(); + + Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user); + Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id }); + + const language = user.language || settings.get('Language') || 'en'; + + Livechat.closeRoom({ + user, + room: LivechatRooms.findOneById(message.rid), + comment: TAPi18n.__('Videocall_declined', { lng: language }), + }); + Meteor.defer(() => { + Messages.setHiddenById(message._id); + }); +}); diff --git a/app/livestream/server/routes.js b/app/livestream/server/routes.js index 8668217d19a5..3a52aec6031c 100644 --- a/app/livestream/server/routes.js +++ b/app/livestream/server/routes.js @@ -3,7 +3,7 @@ import google from 'googleapis'; import { settings } from '../../settings'; import { Users } from '../../models'; -import { API } from '../../api'; +import { API } from '../../api/server'; const { OAuth2 } = google.auth; diff --git a/app/oauth2-server-config/server/oauth/oauth2-server.js b/app/oauth2-server-config/server/oauth/oauth2-server.js index ff813497bc5a..f1c51982c760 100644 --- a/app/oauth2-server-config/server/oauth/oauth2-server.js +++ b/app/oauth2-server-config/server/oauth/oauth2-server.js @@ -3,7 +3,7 @@ import { WebApp } from 'meteor/webapp'; import { OAuth2Server } from 'meteor/rocketchat:oauth2-server'; import { OAuthApps, Users } from '../../../models'; -import { API } from '../../../api'; +import { API } from '../../../api/server'; const oauth2server = new OAuth2Server({ accessTokensCollectionName: 'rocketchat_oauth_access_tokens', diff --git a/app/videobridge/client/actionLink.js b/app/videobridge/client/actionLink.js index 666059649d32..c1955690ddfb 100644 --- a/app/videobridge/client/actionLink.js +++ b/app/videobridge/client/actionLink.js @@ -2,7 +2,7 @@ import { Session } from 'meteor/session'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import toastr from 'toastr'; -import { actionLinks } from '../../action-links'; +import { actionLinks } from '../../action-links/client'; import { Rooms } from '../../models'; actionLinks.register('joinJitsiCall', function(message, params, instance) { diff --git a/app/videobridge/server/actionLink.js b/app/videobridge/server/actionLink.js index 01d5baa2ff4f..e3e42bee4c33 100644 --- a/app/videobridge/server/actionLink.js +++ b/app/videobridge/server/actionLink.js @@ -1,4 +1,4 @@ -import { actionLinks } from '../../action-links'; +import { actionLinks } from '../../action-links/server'; actionLinks.register('joinJitsiCall', function(/* message, params*/) { diff --git a/app/videobridge/server/methods/bbb.js b/app/videobridge/server/methods/bbb.js index 04b1d6030ed1..b06045271d54 100644 --- a/app/videobridge/server/methods/bbb.js +++ b/app/videobridge/server/methods/bbb.js @@ -2,11 +2,11 @@ import { Meteor } from 'meteor/meteor'; import { HTTP } from 'meteor/http'; import xml2js from 'xml2js'; -import BigBlueButtonApi from '../../../bigbluebutton'; +import BigBlueButtonApi from '../../../bigbluebutton/server'; import { settings } from '../../../settings'; import { Rooms, Users } from '../../../models'; import { saveStreamingOptions } from '../../../channel-settings'; -import { API } from '../../../api'; +import { API } from '../../../api/server'; const parser = new xml2js.Parser({ explicitRoot: true, diff --git a/client/importPackages.js b/client/importPackages.js index 183ed71b41fc..7d95bc6f83e7 100644 --- a/client/importPackages.js +++ b/client/importPackages.js @@ -102,7 +102,7 @@ import '../app/notifications'; import '../app/promises/client'; import '../app/ui-utils'; import '../app/ui-cached-collection'; -import '../app/action-links'; +import '../app/action-links/client'; import '../app/reactions/client'; import '../app/livechat/client'; import '../app/meteor-autocomplete/client'; diff --git a/ee/app/api-enterprise/server/canned-responses.js b/ee/app/api-enterprise/server/canned-responses.js index 36b1175406a1..99f41f2709c6 100644 --- a/ee/app/api-enterprise/server/canned-responses.js +++ b/ee/app/api-enterprise/server/canned-responses.js @@ -1,4 +1,4 @@ -import { API } from '../../../../app/api'; +import { API } from '../../../../app/api/server'; import { findAllCannedResponses } from './lib/canned-responses'; API.v1.addRoute('canned-responses.get', { authRequired: true }, { diff --git a/ee/app/engagement-dashboard/server/api/channels.js b/ee/app/engagement-dashboard/server/api/channels.js index 405161d3e0c6..e97dd3995df0 100644 --- a/ee/app/engagement-dashboard/server/api/channels.js +++ b/ee/app/engagement-dashboard/server/api/channels.js @@ -1,6 +1,6 @@ import { check } from 'meteor/check'; -import { API } from '../../../../../app/api'; +import { API } from '../../../../../app/api/server'; import { findAllChannelsWithNumberOfMessages } from '../lib/channels'; import { transformDatesForAPI } from './helpers/date'; diff --git a/ee/app/engagement-dashboard/server/api/messages.js b/ee/app/engagement-dashboard/server/api/messages.js index b51f393e0091..94b6428c011e 100644 --- a/ee/app/engagement-dashboard/server/api/messages.js +++ b/ee/app/engagement-dashboard/server/api/messages.js @@ -1,6 +1,6 @@ import { check } from 'meteor/check'; -import { API } from '../../../../../app/api'; +import { API } from '../../../../../app/api/server'; import { findWeeklyMessagesSentData, findMessagesSentOrigin, findTopFivePopularChannelsByMessageSentQuantity } from '../lib/messages'; import { transformDatesForAPI } from './helpers/date'; diff --git a/ee/app/engagement-dashboard/server/api/users.js b/ee/app/engagement-dashboard/server/api/users.js index aaf33b4c0f28..8a675146237a 100644 --- a/ee/app/engagement-dashboard/server/api/users.js +++ b/ee/app/engagement-dashboard/server/api/users.js @@ -1,6 +1,6 @@ import { check } from 'meteor/check'; -import { API } from '../../../../../app/api'; +import { API } from '../../../../../app/api/server'; import { findWeeklyUsersRegisteredData, findActiveUsersMonthlyData, diff --git a/ee/app/livechat/imports/server/rest/departments.js b/ee/app/livechat/imports/server/rest/departments.js index 4ec594c9051e..1521dc7656a9 100644 --- a/ee/app/livechat/imports/server/rest/departments.js +++ b/ee/app/livechat/imports/server/rest/departments.js @@ -1,4 +1,4 @@ -import { API } from '../../../../../../app/api'; +import { API } from '../../../../../../app/api/server'; import { runEndpointsAsUser } from '../../../../livechat-enterprise/server/lib/runEndpointsAsUser'; const endpointsToRunAsUser = { diff --git a/ee/app/livechat/imports/server/rest/inquiries.js b/ee/app/livechat/imports/server/rest/inquiries.js index 3c9e6c314414..cab34ca9b355 100644 --- a/ee/app/livechat/imports/server/rest/inquiries.js +++ b/ee/app/livechat/imports/server/rest/inquiries.js @@ -1,4 +1,4 @@ -import { API } from '../../../../../../app/api'; +import { API } from '../../../../../../app/api/server'; import { runEndpointsAsUser } from '../../../../livechat-enterprise/server/lib/runEndpointsAsUser'; const endpointsToRunAsUser = { diff --git a/ee/app/livechat/imports/server/rest/rooms.js b/ee/app/livechat/imports/server/rest/rooms.js index 7d15bf85e2f9..76578268b288 100644 --- a/ee/app/livechat/imports/server/rest/rooms.js +++ b/ee/app/livechat/imports/server/rest/rooms.js @@ -1,4 +1,4 @@ -import { API } from '../../../../../../app/api'; +import { API } from '../../../../../../app/api/server'; import { runEndpointsAsUser } from '../../../../livechat-enterprise/server/lib/runEndpointsAsUser'; const endpointsToRunAsUser = { diff --git a/ee/app/livechat/imports/server/rest/sms.js b/ee/app/livechat/imports/server/rest/sms.js index 982ddd7b2438..211f5e444a40 100644 --- a/ee/app/livechat/imports/server/rest/sms.js +++ b/ee/app/livechat/imports/server/rest/sms.js @@ -1,4 +1,4 @@ -import { API } from '../../../../../../app/api'; +import { API } from '../../../../../../app/api/server'; import { runEndpointsAsUser } from '../../../../livechat-enterprise/server/lib/runEndpointsAsUser'; const endpointsToRunAsUser = { diff --git a/ee/app/livechat/imports/server/rest/upload.js b/ee/app/livechat/imports/server/rest/upload.js index 8f87096af200..e8c4ad4e81ba 100644 --- a/ee/app/livechat/imports/server/rest/upload.js +++ b/ee/app/livechat/imports/server/rest/upload.js @@ -1,4 +1,4 @@ -import { API } from '../../../../../../app/api'; +import { API } from '../../../../../../app/api/server'; import { runEndpointsAsUser } from '../../../../livechat-enterprise/server/lib/runEndpointsAsUser'; const endpointsToRunAsUser = { diff --git a/server/importPackages.js b/server/importPackages.js index 96073ce4fa3f..aa56233f2bf5 100644 --- a/server/importPackages.js +++ b/server/importPackages.js @@ -1,14 +1,14 @@ import '../app/cors/server'; import '../app/sms'; import '../app/2fa/server'; -import '../app/accounts'; +import '../app/accounts/server'; import '../app/analytics/server'; -import '../app/api'; -import '../app/assets'; +import '../app/api/server'; +import '../app/assets/server'; import '../app/authorization'; import '../app/autolinker/server'; import '../app/autotranslate/server'; -import '../app/bot-helpers'; +import '../app/bot-helpers/server'; import '../app/cas/server'; import '../app/channel-settings'; import '../app/channel-settings-mail-messages/server'; @@ -98,7 +98,7 @@ import '../app/version-check/server'; import '../app/search/server'; import '../app/chatpal-search/server'; import '../app/discussion/server'; -import '../app/bigbluebutton'; +import '../app/bigbluebutton/server'; import '../app/mail-messages/server'; import '../app/user-status'; import '../app/utils'; @@ -109,6 +109,6 @@ import '../app/callbacks'; import '../app/notifications'; import '../app/promises/server'; import '../app/ui-utils'; -import '../app/action-links'; +import '../app/action-links/server'; import '../app/reactions/server'; import '../app/livechat/server'; diff --git a/server/startup/migrations/v036.js b/server/startup/migrations/v036.js index a4f97e7bf80f..ba22dbdfa8db 100644 --- a/server/startup/migrations/v036.js +++ b/server/startup/migrations/v036.js @@ -5,7 +5,7 @@ import { HTTP } from 'meteor/http'; import { Migrations } from '../../../app/migrations'; import { Settings } from '../../../app/models'; -import { RocketChatAssets } from '../../../app/assets'; +import { RocketChatAssets } from '../../../app/assets/server'; Migrations.add({ version: 36, diff --git a/server/startup/migrations/v042.js b/server/startup/migrations/v042.js index dc95a49cbae2..d17a90026692 100644 --- a/server/startup/migrations/v042.js +++ b/server/startup/migrations/v042.js @@ -2,7 +2,7 @@ import { Mongo } from 'meteor/mongo'; import { Migrations } from '../../../app/migrations'; import { settings } from '../../../app/settings'; -import { RocketChatAssets } from '../../../app/assets'; +import { RocketChatAssets } from '../../../app/assets/server'; Migrations.add({ version: 42,