From 358cbf2f8956f115d1ce0d859055cc64b6b4e0ae Mon Sep 17 00:00:00 2001 From: mutdmour Date: Thu, 26 Oct 2017 23:27:07 +0300 Subject: [PATCH 1/5] fixed issue #8336 --- .../client/models/EmojiCustom.js | 12 ++++++++++++ .../client/methods/setReaction.js | 2 ++ packages/rocketchat-reactions/setReaction.js | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js b/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js index 369ab9754dc..d37b8f4f405 100644 --- a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js +++ b/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js @@ -3,6 +3,18 @@ class EmojiCustom extends RocketChat.models._Base { super(); this._initModel('custom_emoji'); } + + //find + findByNameOrAlias(name, options) { + const query = { + $or: [ + {name}, + {aliases: name} + ] + }; + + return this.find(query, options); + } } RocketChat.models.EmojiCustom = new EmojiCustom(); diff --git a/packages/rocketchat-reactions/client/methods/setReaction.js b/packages/rocketchat-reactions/client/methods/setReaction.js index 38fcd46a3d2..5eac14b9ee9 100644 --- a/packages/rocketchat-reactions/client/methods/setReaction.js +++ b/packages/rocketchat-reactions/client/methods/setReaction.js @@ -15,6 +15,8 @@ Meteor.methods({ return false; } else if (message.private) { return false; + } else if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0){ + return false; } if (message.reactions && message.reactions[reaction] && message.reactions[reaction].usernames.indexOf(user.username) !== -1) { diff --git a/packages/rocketchat-reactions/setReaction.js b/packages/rocketchat-reactions/setReaction.js index 1d655e50576..54223516b6f 100644 --- a/packages/rocketchat-reactions/setReaction.js +++ b/packages/rocketchat-reactions/setReaction.js @@ -17,6 +17,10 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' }); } + if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0){ + throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' }); + } + const user = Meteor.user(); if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1 && !room.reactWhenReadOnly) { From 6a660c12d405614bb8ffe2289ee1977b933e5a5e Mon Sep 17 00:00:00 2001 From: mutdmour Date: Thu, 26 Oct 2017 23:35:49 +0300 Subject: [PATCH 2/5] eslint --- .../client/models/EmojiCustom.js | 20 +++++++++---------- .../client/methods/setReaction.js | 2 +- packages/rocketchat-reactions/setReaction.js | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js b/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js index d37b8f4f405..78cae29a32b 100644 --- a/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js +++ b/packages/rocketchat-emoji-custom/client/models/EmojiCustom.js @@ -4,17 +4,17 @@ class EmojiCustom extends RocketChat.models._Base { this._initModel('custom_emoji'); } - //find - findByNameOrAlias(name, options) { - const query = { - $or: [ - {name}, - {aliases: name} - ] - }; + //find + findByNameOrAlias(name, options) { + const query = { + $or: [ + {name}, + {aliases: name} + ] + }; - return this.find(query, options); - } + return this.find(query, options); + } } RocketChat.models.EmojiCustom = new EmojiCustom(); diff --git a/packages/rocketchat-reactions/client/methods/setReaction.js b/packages/rocketchat-reactions/client/methods/setReaction.js index 5eac14b9ee9..48c2ffd1ff2 100644 --- a/packages/rocketchat-reactions/client/methods/setReaction.js +++ b/packages/rocketchat-reactions/client/methods/setReaction.js @@ -15,7 +15,7 @@ Meteor.methods({ return false; } else if (message.private) { return false; - } else if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0){ + } else if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0) { return false; } diff --git a/packages/rocketchat-reactions/setReaction.js b/packages/rocketchat-reactions/setReaction.js index 54223516b6f..e4c3994238c 100644 --- a/packages/rocketchat-reactions/setReaction.js +++ b/packages/rocketchat-reactions/setReaction.js @@ -17,7 +17,7 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' }); } - if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0){ + if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' }); } From fda44dde4e491b8d2fdf6db74eb576ff239bc4cd Mon Sep 17 00:00:00 2001 From: mutdmour Date: Sat, 2 Dec 2017 08:09:39 +0200 Subject: [PATCH 3/5] updated error message #8336 --- packages/rocketchat-reactions/setReaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-reactions/setReaction.js b/packages/rocketchat-reactions/setReaction.js index e4c3994238c..e2e04a71931 100644 --- a/packages/rocketchat-reactions/setReaction.js +++ b/packages/rocketchat-reactions/setReaction.js @@ -18,7 +18,7 @@ Meteor.methods({ } if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' }); + throw new Meteor.Error('error-not-allowed', 'Invalid emoji provided.', { method: 'setReaction' }); } const user = Meteor.user(); From 27ee610ef268ec66ffa2faebf7edc9bde27212ac Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Mon, 19 Feb 2018 11:48:32 -0300 Subject: [PATCH 4/5] change to valid emoji to fix broken tests, /chat.react endpoint --- tests/end-to-end/api/05-chat.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/end-to-end/api/05-chat.js b/tests/end-to-end/api/05-chat.js index c6dca60d2c2..610c012b95e 100644 --- a/tests/end-to-end/api/05-chat.js +++ b/tests/end-to-end/api/05-chat.js @@ -169,18 +169,21 @@ describe('[Chat]', function() { .end(done); }); - it('/chat.react', (done) => { - request.post(api('chat.react')) - .set(credentials) - .send({ - emoji: 'smile', - messageId: message._id - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - }) - .end(done); + describe('/chat.react', () => { + it('should return statusCode: 200 when the emoji is valid', (done) => { + request.post(api('chat.react')) + .set(credentials) + .send({ + emoji: ':squid:', + messageId: message._id + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }) + .end(done); + }); }); + }); From ddc9d025eaf939a2f3c9b80c8b752b9edb0beb24 Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Mon, 19 Feb 2018 11:57:10 -0300 Subject: [PATCH 5/5] fix lint issues, about trailing spaces --- tests/end-to-end/api/05-chat.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/end-to-end/api/05-chat.js b/tests/end-to-end/api/05-chat.js index 610c012b95e..c37cc7a5776 100644 --- a/tests/end-to-end/api/05-chat.js +++ b/tests/end-to-end/api/05-chat.js @@ -2,8 +2,8 @@ /* globals expect */ /* eslint no-unused-vars: 0 */ -import {getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../../data/api-data.js'; -import {adminEmail, password} from '../../data/user.js'; +import { getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../../data/api-data.js'; +import { adminEmail, password } from '../../data/user.js'; import supertest from 'supertest'; describe('[Chat]', function() { @@ -185,5 +185,4 @@ describe('[Chat]', function() { .end(done); }); }); - });