diff --git a/packages/rocketchat-livechat/server/models/LivechatCustomField.js b/packages/rocketchat-livechat/server/models/LivechatCustomField.js index 27a70f6199b..ab4a8b58192 100644 --- a/packages/rocketchat-livechat/server/models/LivechatCustomField.js +++ b/packages/rocketchat-livechat/server/models/LivechatCustomField.js @@ -44,4 +44,3 @@ class LivechatCustomFieldClass extends Base { } export const LivechatCustomField = new LivechatCustomFieldClass(); -RocketChat.models.LivechatCustomField = LivechatCustomField; diff --git a/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js b/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js index 7f7b31224bc..05a11351301 100644 --- a/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js +++ b/packages/rocketchat-livechat/server/models/LivechatOfficeHour.js @@ -108,4 +108,3 @@ class LivechatOfficeHourClass extends Base { } } export const LivechatOfficeHour = new LivechatOfficeHourClass(); -RocketChat.models.LivechatOfficeHour = LivechatOfficeHour; diff --git a/packages/rocketchat-livechat/server/models/LivechatTrigger.js b/packages/rocketchat-livechat/server/models/LivechatTrigger.js index 77abc29280e..e52734f362a 100644 --- a/packages/rocketchat-livechat/server/models/LivechatTrigger.js +++ b/packages/rocketchat-livechat/server/models/LivechatTrigger.js @@ -29,4 +29,3 @@ class LivechatTriggerClass extends Base { } } export const LivechatTrigger = new LivechatTriggerClass(); -RocketChat.models.LivechatTrigger = LivechatTrigger; diff --git a/packages/rocketchat-livechat/server/publications/customFields.js b/packages/rocketchat-livechat/server/publications/customFields.js index 3d778d70389..616517caddb 100644 --- a/packages/rocketchat-livechat/server/publications/customFields.js +++ b/packages/rocketchat-livechat/server/publications/customFields.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatCustomField } from '../models'; import s from 'underscore.string'; @@ -8,7 +8,7 @@ Meteor.publish('livechat:customFields', function(_id) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:customFields' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:customFields' })); } diff --git a/packages/rocketchat-livechat/server/publications/departmentAgents.js b/packages/rocketchat-livechat/server/publications/departmentAgents.js index 69af2003bef..e99e015ec09 100644 --- a/packages/rocketchat-livechat/server/publications/departmentAgents.js +++ b/packages/rocketchat-livechat/server/publications/departmentAgents.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatDepartmentAgents } from '../models'; Meteor.publish('livechat:departmentAgents', function(departmentId) { @@ -7,7 +7,7 @@ Meteor.publish('livechat:departmentAgents', function(departmentId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:departmentAgents' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) { + if (!hasPermission(this.userId, 'view-livechat-rooms')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:departmentAgents' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatAgents.js b/packages/rocketchat-livechat/server/publications/livechatAgents.js index c5d333039c1..31d026b283e 100644 --- a/packages/rocketchat-livechat/server/publications/livechatAgents.js +++ b/packages/rocketchat-livechat/server/publications/livechatAgents.js @@ -1,18 +1,18 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission, getUsersInRole } from 'meteor/rocketchat:authorization'; Meteor.publish('livechat:agents', function() { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' })); } const self = this; - const handle = RocketChat.authz.getUsersInRole('livechat-agent').observeChanges({ + const handle = getUsersInRole('livechat-agent').observeChanges({ added(id, fields) { self.added('agentUsers', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatAppearance.js b/packages/rocketchat-livechat/server/publications/livechatAppearance.js index ae46dc9797c..2e08b44fb0b 100644 --- a/packages/rocketchat-livechat/server/publications/livechatAppearance.js +++ b/packages/rocketchat-livechat/server/publications/livechatAppearance.js @@ -1,12 +1,13 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Settings } from 'meteor/rocketchat:models'; Meteor.publish('livechat:appearance', function() { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:appearance' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { + if (!hasPermission(this.userId, 'view-livechat-manager')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:appearance' })); } @@ -34,7 +35,7 @@ Meteor.publish('livechat:appearance', function() { const self = this; - const handle = RocketChat.models.Settings.find(query).observeChanges({ + const handle = Settings.find(query).observeChanges({ added(id, fields) { self.added('livechatAppearance', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatDepartments.js b/packages/rocketchat-livechat/server/publications/livechatDepartments.js index dc45a31e020..1e987bbf0f1 100644 --- a/packages/rocketchat-livechat/server/publications/livechatDepartments.js +++ b/packages/rocketchat-livechat/server/publications/livechatDepartments.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatDepartment } from '../models'; Meteor.publish('livechat:departments', function(_id) { @@ -7,7 +7,7 @@ Meteor.publish('livechat:departments', function(_id) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatInquiries.js b/packages/rocketchat-livechat/server/publications/livechatInquiries.js index 3eb7893c13d..f1e4aaa6151 100644 --- a/packages/rocketchat-livechat/server/publications/livechatInquiries.js +++ b/packages/rocketchat-livechat/server/publications/livechatInquiries.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatInquiry } from '../../lib/LivechatInquiry'; Meteor.publish('livechat:inquiry', function() { @@ -7,7 +7,7 @@ Meteor.publish('livechat:inquiry', function() { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:inquiry' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatIntegration.js b/packages/rocketchat-livechat/server/publications/livechatIntegration.js index 4eaeb694e24..521573b4b4d 100644 --- a/packages/rocketchat-livechat/server/publications/livechatIntegration.js +++ b/packages/rocketchat-livechat/server/publications/livechatIntegration.js @@ -1,18 +1,19 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Settings } from 'meteor/rocketchat:models'; Meteor.publish('livechat:integration', function() { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:integration' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { + if (!hasPermission(this.userId, 'view-livechat-manager')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:integration' })); } const self = this; - const handle = RocketChat.models.Settings.findByIds(['Livechat_webhookUrl', 'Livechat_secret_token', 'Livechat_webhook_on_close', 'Livechat_webhook_on_offline_msg', 'Livechat_webhook_on_visitor_message', 'Livechat_webhook_on_agent_message']).observeChanges({ + const handle = Settings.findByIds(['Livechat_webhookUrl', 'Livechat_secret_token', 'Livechat_webhook_on_close', 'Livechat_webhook_on_offline_msg', 'Livechat_webhook_on_visitor_message', 'Livechat_webhook_on_agent_message']).observeChanges({ added(id, fields) { self.added('livechatIntegration', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatManagers.js b/packages/rocketchat-livechat/server/publications/livechatManagers.js index 6f9aa3dec65..21b9070dad5 100644 --- a/packages/rocketchat-livechat/server/publications/livechatManagers.js +++ b/packages/rocketchat-livechat/server/publications/livechatManagers.js @@ -1,18 +1,18 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission, getUsersInRole } from 'meteor/rocketchat:authorization'; Meteor.publish('livechat:managers', function() { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:managers' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) { + if (!hasPermission(this.userId, 'view-livechat-rooms')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:managers' })); } const self = this; - const handle = RocketChat.authz.getUsersInRole('livechat-manager').observeChanges({ + const handle = getUsersInRole('livechat-manager').observeChanges({ added(id, fields) { self.added('managerUsers', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatMonitoring.js b/packages/rocketchat-livechat/server/publications/livechatMonitoring.js index 99707fc2332..a120eb01aae 100644 --- a/packages/rocketchat-livechat/server/publications/livechatMonitoring.js +++ b/packages/rocketchat-livechat/server/publications/livechatMonitoring.js @@ -1,13 +1,14 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms } from 'meteor/rocketchat:models'; Meteor.publish('livechat:monitoring', function(date) { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:monitoring' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { + if (!hasPermission(this.userId, 'view-livechat-manager')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:monitoring' })); } @@ -21,7 +22,7 @@ Meteor.publish('livechat:monitoring', function(date) { const self = this; - const handle = RocketChat.models.Rooms.getAnalyticsMetricsBetweenDate('l', date).observeChanges({ + const handle = Rooms.getAnalyticsMetricsBetweenDate('l', date).observeChanges({ added(id, fields) { self.added('livechatMonitoring', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js b/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js index 754217ef3e3..da8d795f6fe 100644 --- a/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js +++ b/packages/rocketchat-livechat/server/publications/livechatOfficeHours.js @@ -1,9 +1,9 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatOfficeHour } from '../models'; Meteor.publish('livechat:officeHour', function() { - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:agents' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatQueue.js b/packages/rocketchat-livechat/server/publications/livechatQueue.js index 94df8ba2c8f..8230848f460 100644 --- a/packages/rocketchat-livechat/server/publications/livechatQueue.js +++ b/packages/rocketchat-livechat/server/publications/livechatQueue.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatDepartmentAgents } from '../models'; Meteor.publish('livechat:queue', function() { @@ -7,7 +7,7 @@ Meteor.publish('livechat:queue', function() { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:queue' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:queue' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatRooms.js b/packages/rocketchat-livechat/server/publications/livechatRooms.js index 0a5cb4f5354..c0586e4dc80 100644 --- a/packages/rocketchat-livechat/server/publications/livechatRooms.js +++ b/packages/rocketchat-livechat/server/publications/livechatRooms.js @@ -1,13 +1,14 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms } from 'meteor/rocketchat:models'; Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:rooms' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-rooms')) { + if (!hasPermission(this.userId, 'view-livechat-rooms')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:rooms' })); } @@ -50,7 +51,7 @@ Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) { const self = this; - const handle = RocketChat.models.Rooms.findLivechat(query, offset, limit).observeChanges({ + const handle = Rooms.findLivechat(query, offset, limit).observeChanges({ added(id, fields) { self.added('livechatRoom', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/livechatTriggers.js b/packages/rocketchat-livechat/server/publications/livechatTriggers.js index eaf10f591d7..9d20679d5f9 100644 --- a/packages/rocketchat-livechat/server/publications/livechatTriggers.js +++ b/packages/rocketchat-livechat/server/publications/livechatTriggers.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import { LivechatTrigger } from '../models'; Meteor.publish('livechat:triggers', function(_id) { @@ -7,7 +7,7 @@ Meteor.publish('livechat:triggers', function(_id) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:triggers' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { + if (!hasPermission(this.userId, 'view-livechat-manager')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:triggers' })); } diff --git a/packages/rocketchat-livechat/server/publications/livechatVisitors.js b/packages/rocketchat-livechat/server/publications/livechatVisitors.js index b71b4888d55..e7137ed45be 100644 --- a/packages/rocketchat-livechat/server/publications/livechatVisitors.js +++ b/packages/rocketchat-livechat/server/publications/livechatVisitors.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; import LivechatVisitors from '../models/LivechatVisitors'; Meteor.publish('livechat:visitors', function(date) { @@ -8,7 +8,7 @@ Meteor.publish('livechat:visitors', function(date) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitors' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) { + if (!hasPermission(this.userId, 'view-livechat-manager')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitors' })); } diff --git a/packages/rocketchat-livechat/server/publications/visitorHistory.js b/packages/rocketchat-livechat/server/publications/visitorHistory.js index 77b0405430b..d826639bb18 100644 --- a/packages/rocketchat-livechat/server/publications/visitorHistory.js +++ b/packages/rocketchat-livechat/server/publications/visitorHistory.js @@ -1,18 +1,19 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Subscriptions } from 'meteor/rocketchat:models'; Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) { if (!this.userId) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' })); } - const room = RocketChat.models.Rooms.findOneById(roomId); + const room = Rooms.findOneById(roomId); - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, this.userId, { fields: { _id: 1 } }); + const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, this.userId, { fields: { _id: 1 } }); if (!subscription) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' })); } @@ -20,7 +21,7 @@ Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) { const self = this; if (room && room.v && room.v._id) { - const handle = RocketChat.models.Rooms.findByVisitorId(room.v._id).observeChanges({ + const handle = Rooms.findByVisitorId(room.v._id).observeChanges({ added(id, fields) { self.added('visitor_history', id, fields); }, diff --git a/packages/rocketchat-livechat/server/publications/visitorInfo.js b/packages/rocketchat-livechat/server/publications/visitorInfo.js index a5ba86542ce..fafa5120ade 100644 --- a/packages/rocketchat-livechat/server/publications/visitorInfo.js +++ b/packages/rocketchat-livechat/server/publications/visitorInfo.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms } from 'meteor/rocketchat:models'; import LivechatVisitors from '../models/LivechatVisitors'; Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) { @@ -7,11 +8,11 @@ Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' })); } - const room = RocketChat.models.Rooms.findOneById(roomId); + const room = Rooms.findOneById(roomId); if (room && room.v && room.v._id) { return LivechatVisitors.findById(room.v._id); diff --git a/packages/rocketchat-livechat/server/publications/visitorPageVisited.js b/packages/rocketchat-livechat/server/publications/visitorPageVisited.js index 039e36fcf82..739949b266a 100644 --- a/packages/rocketchat-livechat/server/publications/visitorPageVisited.js +++ b/packages/rocketchat-livechat/server/publications/visitorPageVisited.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Messages } from 'meteor/rocketchat:models'; Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) { @@ -7,15 +8,15 @@ Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' })); } - if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) { + if (!hasPermission(this.userId, 'view-l-room')) { return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' })); } const self = this; - const room = RocketChat.models.Rooms.findOneById(roomId); + const room = Rooms.findOneById(roomId); if (room) { - const handle = RocketChat.models.Messages.findByRoomIdAndType(room._id, 'livechat_navigation_history').observeChanges({ + const handle = Messages.findByRoomIdAndType(room._id, 'livechat_navigation_history').observeChanges({ added(id, fields) { self.added('visitor_navigation_history', id, fields); },