If autolinking would make posts too long, don't#154
If autolinking would make posts too long, don't#154elyscape wants to merge 2 commits intomattermost-community:masterfrom
Conversation
hanzei
left a comment
There was a problem hiding this comment.
Good catch on this issue.:+1:
| return nil, "" | ||
| } | ||
|
|
||
| if runes := utf8.RuneCountInString(postText); runes > model.POST_MESSAGE_MAX_RUNES_V1 { |
There was a problem hiding this comment.
For newer Mattermost instances or the one that updates, this will be longer:
This release includes support for post messages longer than the default of 4000 characters, but may require a manual database migration. This migration is entirely optional, and need only be done if you want to enable post messages up to 16383 characters. For many installations, no migration will be required, or the old limit remains sufficient.
https://docs.mattermost.com/administration/important-upgrade-notes.html
I'm hesitant to cap at the old limit as that might render the plugin useless for some instances.
There was a problem hiding this comment.
This is fair, but we currently have no way to find the actual limit from a plug-in, and that excerpt notes that upgrading from 4000 characters may require a manual migration, which we can't expect every deployment to have performed.
There was a problem hiding this comment.
From looking at the server code base the UpdatePost RPC method does return an model.post.is_valid.msg.app_error error. (https://github.com/mattermost/mattermost-server/blob/ee3f986da0d9fbc69769dcec0c66d8493589757a/model/post.go#L299) Can we check for the specific error and return the original message in that case?
There was a problem hiding this comment.
The problem is that this function is effectively the handler for the MessageWillBePosted() and MessageWillBeUpdated() hooks, meaning we can alter the Post object but need to allow persistence to be handled further down the chain.
There was a problem hiding this comment.
I think the ideal solution is to first provide a way for plugins to get the result of GetMaxPostSize(), and then have the plugin:
- Retrieve that value
- Update the
Postobject - Call Post.IsValid() with its value
- Revert the object if the result is
false
There was a problem hiding this comment.
That is a concern to me as it unexpectedly renders the plugin useless in some cases that previously worked. I'm 2/5 that it's not worth breaking that cases for the bug fix that the PR includes.
There was a problem hiding this comment.
From looking at the server code base the
UpdatePostRPC method does return anmodel.post.is_valid.msg.app_errorerror. (mattermost/mattermost-server@ee3f986/model/post.go#L299) Can we check for the specific error and return the original message in that case?
@elyscape Do you think it's feasible to refactor the code and use that approach?
There was a problem hiding this comment.
I do not. This function is effectively the handler for the MessageWillBePosted and MessageWillBeUpdated hooks, meaning we can alter the Post object but need to allow persistence to be handled further down the chain. From the documentation:
To reject a post, return an non-empty string describing why the post was rejected. To modify the post, return the replacement, non-nil *model.Post and an empty string. To allow the post without modification, return a nil *model.Post and an empty string. To dismiss the post, return a nil *model.Post and the const DismissPostError string.
We could call UpdatePost from MessageHasBeenPosted or MessageHasBeenUpdated, because those are events that fire after a message occurs, but not here.
There was a problem hiding this comment.
@hanzei As a side complication, even once we get access to the result of GetMaxPostSize(), we'll need a fallback path for versions of Mattermost that don't support it.
| return nil, "" | ||
| } | ||
|
|
||
| if runes := utf8.RuneCountInString(postText); runes > model.POST_MESSAGE_MAX_RUNES_V1 { |
There was a problem hiding this comment.
I like the simplicity of the current implementation. 0/5 we add it in "as is". We should probably open a ticket to make the MaxPostSize available to plugins, and to update Autolink once it's done; until the, we document the limitation? cc @aaronrothschild @justinegeffen
5bb970b to
bfa2b6c
Compare
|
I updated the PR to fix the tests and also include the post ID logged when a message would be too long. Edit: Well, that broke the build differently because we aren't populating Edit 2: Turns out that the field is never expected to have a value. Oh well. |
bfa2b6c to
4eadd40
Compare
Substitutions that increase message length have the potential to grow a post past the ability of the database to store it. This manifests to users as their posts inexplicably failing. To avoid this fail state, we check to see if the post-substitution message is too long and, if so, don't apply the changes. Unfortunately, the actual maximum post size is not currently accessible to plugins. In the meantime, we use the smallest value for which the server guarantees support, which is exposed through model.POST_MESSAGE_MAX_RUNES_V1 and is in practice 4000 runes.
4eadd40 to
7c930fa
Compare
|
Okay, tests fixed. |
If the first return value of MessageWillBeUpdated is nil, the update is rejected, with the second return value providing an explanation for the rejection. To allow the update to occur without any changes, the function should return the value of newPost that was passed in to it. We don't reject any post updates, but if we did then even then we would have to provide a rejection reason. As such, we don't need to alter the logic of ProcessPost, and can instead simply put a check on its return values.
|
@levb Sounds good. I'll figure out how to implement that in the next week. |
|
@levb @hanzei @iomodo I started looking into this and realized that I don't think there's actually a good way to implement it. As I understand it, the proposal is to implement this setting on a per- |
|
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
|
0/5 change the semantics, and just let the processing stop at the point where it'd have exceeded the max post size. I understand that it is unpredictable in the sense of what links will be processed, but IMO it can be a simple, sufficent solution? |
|
@elyscape Coming back to this PR: The solution in #154 (comment) seems good to me. Do you still want to work on it? |
mattermost-community#192) * Revert "Update main.go (mattermost-community#154)" This reverts commit be4a281d0cc791d10e6e5ae917b325b2f054e475. * Revert "[MM-33506] Use embed package to include plugin manifest (mattermost-community#145)" This reverts commit ca9ee3c17c6920a636a33f378e17395afd6f329f. * Revert "Don't generate manifest.ts (mattermost-community#127)" This reverts commit 18d30b50bc7ba800c9f05bfd82970781db0aea3e. * install-go-tools target, adopt gotestsum * bring back make apply + automatic versioning * Update build/manifest/main.go Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> * suppress git describe error when no tags match * make version/release notes opt-in * fix whitespace in Makefile * document version management options --------- Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com>
* [MM-98] Update plugin with respect to phase 1 upgrades * [MM-98] Fix lint * [MM-98] Update Readme * [MM-98] Review fixes regarding constant for golangci-lint * Sync with playbooks: install-go-tools, gotestsum, and dynamic versions (#192) * Revert "Update main.go (#154)" This reverts commit be4a281d0cc791d10e6e5ae917b325b2f054e475. * Revert "[MM-33506] Use embed package to include plugin manifest (#145)" This reverts commit ca9ee3c17c6920a636a33f378e17395afd6f329f. * Revert "Don't generate manifest.ts (#127)" This reverts commit 18d30b50bc7ba800c9f05bfd82970781db0aea3e. * install-go-tools target, adopt gotestsum * bring back make apply + automatic versioning * Update build/manifest/main.go Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> * suppress git describe error when no tags match * make version/release notes opt-in * fix whitespace in Makefile * document version management options --------- Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> * Fetch plugin logs from server (#193) Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> --------- Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Summary
Substitutions that increase message length have the potential to grow a post past the ability of the database to store it. This manifests to users as their posts inexplicably failing. To avoid this fail state, we check to see if the post-substitution message is too long and, if so, don't apply the changes.
Unfortunately, the actual maximum post size is not currently accessible to plugins. In the meantime, we use the smallest value for which the server guarantees support, which is exposed through
model.POST_MESSAGE_MAX_RUNES_V1and is in practice 4000 runes.Ticket Link
None.