Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Notify private settings changes even on public settings changed #13369

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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