The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/publications/settings/emitter.js

45 lines
1.4 KiB

import { Settings } from '../../../app/models';
import { Notifications } from '../../../app/notifications';
import { hasPermission } from '../../../app/authorization';
Settings.on('change', ({ clientAction, id, data, diff }) => {
if (diff && Object.keys(diff).length === 1 && diff._updatedAt) { // avoid useless changes
return;
}
switch (clientAction) {
case 'updated':
case 'inserted': {
const setting = data || Settings.findOneById(id);
const value = {
_id: setting._id,
value: setting.value,
editor: setting.editor,
properties: setting.properties,
};
if (setting.public === true) {
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, value);
}
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting);
break;
}
case 'removed': {
const setting = data || Settings.findOneById(id, { fields: { public: 1 } });
if (setting && setting.public === true) {
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id });
}
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, { _id: id });
break;
}
}
});
Notifications.streamAll.allowRead('private-settings-changed', function() {
if (this.userId == null) {
return false;
}
return hasPermission(this.userId, 'view-privileged-setting');
});