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
Snippet message #4623
Snippet message #4623
Conversation
Behavior copied from the pin message plugin.
Do snippets really need to be stored separately? Could it just be a property of a normal message? |
No not really. I based this plugin on the rocketchat-pin-message which does save messages in a different collections. There's already a property in the rocketchat-message collection for a snippet message so it should be quick to do the changes. |
Either way, this will help a ton with users that are pasting in large chunks of code, console output, etc. |
nice work @juanwolf .. =) snippet messages are still limited by message size limit, right? |
@sampaiodiego thanks! Yes. The snippet message is stored as a normal message so the limitation should still work. |
validation: function(message) { | ||
let room = RocketChat.models.Rooms.findOne({_id: message.rid}); | ||
|
||
if (Array.isArray(room.usernames) && (room.usernames.indexOf(Meteor.user().username) === -1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to use subscription instead of room's username?
Like here https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-lib/client/MessageAction.coffee#L100
return false; | ||
} else { | ||
if (message.snippeted || ((RocketChat.settings.get('Message_AllowSnippeting') === undefined) || | ||
(RocketChat.settings.get('Message_AllowSnippeting') === null))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message_AllowSnippeting
can be false
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah right, focused on the null value but not the proper one 😞
</div> | ||
</div> | ||
|
||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix indentation here? Please, do not mix spaces and tabs (we prefer tabs)
let message = Messages.findOne({ _id: FlowRouter.getParam('snippetId') }); | ||
if (message === undefined) { | ||
return null; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else
block is not needed here, the return will stop the code execution 😄
|
||
Template.snippetPage.onCreated(function() { | ||
let snippetId = FlowRouter.getParam('snippetId'); | ||
console.log(`${snippetId}: ${this.snippet}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this log?
{ '_id': _id } | ||
).observeChanges({ | ||
added: function(_id, record) { | ||
publication.added('rocketchat_message', _id, record); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use the real collection name here, can you replace by rocketchat_snippeted_message
@@ -0,0 +1 @@ | |||
this.Messages = new Meteor.Collection('rocketchat_message'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use the real collection name here, can you replace by rocketchat_snippeted_message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, can you change the variable name? This variable will store only messages from snippeted messages and only when you have the tab bar open
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do that! Why should we not use the 'rocketchat_message' collection?
} | ||
).observeChanges({ | ||
added: function(_id, record) { | ||
publication.added('rocketchat_message', _id, record); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use the real collection name here, can you replace by rocketchat_snippeted_message
var match = /^\/([^\/]+)\/(.*)/.exec(req.url); | ||
|
||
if (match[1]) { | ||
let snippet = RocketChat.models.Messages.findOneById(match[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should do this find after login verification, cuz it's not necessary if user is not authorized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you verify if the message is a snippet, otherwise users can download any message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, can you verify if the user has access to the room where this message came from?
@@ -0,0 +1,13 @@ | |||
Meteor.startup(function() { | |||
RocketChat.settings.add('Message_AllowSnippeting', true, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually start new features as disabled by default then users can enable and test, can you change to false
?
Thanks for the code review @rodrigok ! I did some modifications you asked for, I will continue to work on it tomorrow. |
@juanwolf awesome, thanks |
@rodrigok Little question. Because you mentioned that permissions were not set in the request.js file, I wanted to manage it to directly in the snippet page as well. Unfortunately it's just front-end (using FlowRouter) so I can't do proper queries to the mongo, I managed permissions into the publication 'snippetedMessage' but it gives me an empty template (which makes sense but that's really ugly). I was wondering if you have an idea of where I could manage this permission and send to the user a proper 403 response. |
@juanwolf We can start with this ugly solution and start a new PR for improvements. One way is use method to get data instead of subscriptions, in fact we are replacing a lot of subscriptions by methods, then you can receive the response for your single record or an error and manage the template to show the correct result easily. |
@juanwolf Can you fix the conflict? |
@rodrigok I am on it ! |
@engelgabriel IMHO we should merge this in release 0.46 |
Required to allow in permissions for normal users!!! |
@RocketChat/core
Closes #4395 [Closes #1553 but no auto-recognition]
I made a plugin to handle snippets into RocketChat. It is not finished yet but some review from the community would be awesome.
How it works

- Choose a name for your snippet
- Confirmation Message
- Snippet created!After that, the message containing the snippet is formatted as you could do it using the "```". The system also create a new message containing the link to access to your snippet.
You can also access to your snippet with the tab bar on your right.

- View your snippet
# Settings ## Message configurationYou can disable or enable this feature in the "Message" administration section

## ~~Snippet storage configuration~~You have the choice between GridFS storage and FileSystem storagePlease do not hesitate to review the code and give me your thoughts about this plugin :)
Edit 14/10