Skip to content

Commit

Permalink
[FIX] Notify private settings changes even on public settings changed (
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored and sampaiodiego committed Feb 14, 2019
1 parent 09e80fe commit 98b177f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
55 changes: 29 additions & 26 deletions packages/rocketchat-lib/server/publications/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';

Meteor.methods({
'public-settings/get'(updatedAt) {
this.unblock();
const records = RocketChat.models.Settings.findNotHiddenPublic().fetch();

if (updatedAt instanceof Date) {
Expand All @@ -25,33 +24,32 @@ Meteor.methods({
}
return records;
},
'private-settings/get'(updatedAt) {
'private-settings/get'(updatedAfter) {
if (!Meteor.userId()) {
return [];
}
this.unblock();
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'view-privileged-setting')) {
return [];
}
const records = RocketChat.models.Settings.findNotHidden().fetch();
if (updatedAt instanceof Date) {
return {
update: records.filter(function(record) {
return record._updatedAt > updatedAt;
}),
remove: RocketChat.models.Settings.trashFindDeletedAfter(updatedAt, {
hidden: {
$ne: true,
},
}, {
fields: {
_id: 1,
_deletedAt: 1,
},
}).fetch(),
};

if (!(updatedAfter instanceof Date)) {
return RocketChat.models.Settings.findNotHidden().fetch();
}
return records;

const records = RocketChat.models.Settings.findNotHidden({ updatedAfter }).fetch();
return {
update: records,
remove: RocketChat.models.Settings.trashFindDeletedAfter(updatedAfter, {
hidden: {
$ne: true,
},
}, {
fields: {
_id: 1,
_deletedAt: 1,
},
}).fetch(),
};
},
});

Expand All @@ -61,7 +59,7 @@ RocketChat.models.Settings.on('change', ({ clientAction, id, data, diff }) => {
}
switch (clientAction) {
case 'updated':
case 'inserted':
case 'inserted': {
const setting = data || RocketChat.models.Settings.findOneById(id);
const value = {
_id: setting._id,
Expand All @@ -72,15 +70,20 @@ RocketChat.models.Settings.on('change', ({ clientAction, id, data, diff }) => {

if (setting.public === true) {
RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, value);
} else {
RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting);
}
RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting);
break;
}

case 'removed': {
const setting = data || RocketChat.models.Settings.findOneById(id, { fields: { public: 1 } });

case 'removed':
if (setting.public === true) {
RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id });
}
RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, { _id: id });
RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id });
break;
}
}
});

Expand Down
12 changes: 10 additions & 2 deletions packages/rocketchat-models/server/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ export class Settings extends Base {
});
}

findNotHidden(options) {
return this.find({ hidden: { $ne: true } }, options);
findNotHidden({ updatedAfter, ...options } = {}) {
const query = {
hidden: { $ne: true },
};

if (updatedAfter) {
query._updatedAt = { $gt: updatedAfter };
}

return this.find(query, options);
}

findNotHiddenUpdatedAfter(updatedAt) {
Expand Down

0 comments on commit 98b177f

Please sign in to comment.