diff --git a/app/notifications/server/lib/Notifications.js b/app/notifications/server/lib/Notifications.js index 003db8f22f14..8ef07e56a803 100644 --- a/app/notifications/server/lib/Notifications.js +++ b/app/notifications/server/lib/Notifications.js @@ -4,6 +4,7 @@ import { DDPCommon } from 'meteor/ddp-common'; import { WEB_RTC_EVENTS } from '../../../webrtc'; import { Subscriptions, Rooms } from '../../../models/server'; import { settings } from '../../../settings/server'; +import { hasRole } from '../../../authorization'; const changedPayload = function(collection, id, fields) { return DDPCommon.stringifyDDP({ @@ -65,19 +66,16 @@ class Notifications { this.notifyUser = this.notifyUser.bind(this); this.streamAll = new Meteor.Streamer('notify-all'); this.streamLogged = new Meteor.Streamer('notify-logged'); + this.streamAdmin = new Meteor.Streamer('notify-admin'); this.streamRoom = new Meteor.Streamer('notify-room'); this.streamRoomUsers = new Meteor.Streamer('notify-room-users'); this.streamUser = new RoomStreamer('notify-user'); this.streamAll.allowWrite('none'); this.streamLogged.allowWrite('none'); + this.streamAdmin.allowWrite('none'); this.streamRoom.allowWrite('none'); this.streamRoomUsers.allowWrite(function(eventName, ...args) { const [roomId, e] = eventName.split('/'); - // const user = Meteor.users.findOne(this.userId, { - // fields: { - // username: 1 - // } - // }); if (Subscriptions.findOneByRoomIdAndUserId(roomId, this.userId) != null) { const subscriptions = Subscriptions.findByRoomIdAndNotUserId(roomId, this.userId).fetch(); subscriptions.forEach((subscription) => self.notifyUser(subscription.u._id, e, ...args)); @@ -87,6 +85,9 @@ class Notifications { this.streamUser.allowWrite('logged'); this.streamAll.allowRead('all'); this.streamLogged.allowRead('logged'); + this.streamAdmin.allowRead(function() { + return this.userId && hasRole(this.userId, 'admin'); + }); this.streamRoom.allowRead(function(eventName, extraData) { const [roomId] = eventName.split('/'); const room = Rooms.findOneById(roomId); @@ -142,6 +143,14 @@ class Notifications { return this.streamUser.emit.apply(this.streamUser, args); } + notifyAdmin(userId, eventName, ...args) { + if (this.debug === true) { + console.log('notifyAdmin', [eventName, ...args]); + } + args.unshift(eventName); + return this.streamAdmin.emit.apply(this.streamAdmin, args); + } + notifyAllInThisInstance(eventName, ...args) { if (this.debug === true) { console.log('notifyAll', [eventName, ...args]); diff --git a/server/publications/subscription/emitter.js b/server/publications/subscription/emitter.js index dfcd50f88a3d..f298becc5df8 100644 --- a/server/publications/subscription/emitter.js +++ b/server/publications/subscription/emitter.js @@ -1,5 +1,5 @@ import { Notifications } from '../../../app/notifications'; -import { Subscriptions } from '../../../app/models'; +import { Subscriptions, Users } from '../../../app/models'; import { msgStream } from '../../../app/lib/server/lib/msgStream'; import { fields } from '.'; @@ -27,4 +27,15 @@ Subscriptions.on('change', ({ clientAction, id, data }) => { clientAction, data, ); + + const { customFields } = Users.findOne(data.u._id, { fields: { customFields: 1 } }) || {}; + if (customFields) { + data.u.customFields = customFields; + Notifications.notifyAdmin( + data.u._id, + 'subscriptions-changed', + clientAction, + data, + ); + } });