Commit Graph

133 Commits

Author SHA1 Message Date
Jesse Hallam
4286456077 MM-10856: deduplicate posts with the same pending post id (#10006)
* MM-10856: deduplicate posts with the same pending post id

Leverage a fixed size cache with a window of 30 seconds to deduplicate posts received by a single app server. Clients that duplicate the same pending post id will see one request potentially delayed until the first finishes, after which the same payload should be returned by both.  Duplicate posts outside the 30 second window will not be de-duplicated.

Note that the cache is not synchronized between app servers. In an HA cluster consisting of more than one app server, sticky load balancing (e.g. hashing by IP or Session ID) is required to route the users to the same app instance for multiple requests.

Other options considered for this feature:
* adding a column to the `Posts` table: rejected as being too heavyweight
* maintaining a `PendingPostIds` table: similarly rejected for the database impact
* using the pending post id as the post id and relying on the unique constraints on the Post table: rejected for being difficult to show that it's safe to use a client-provided value as the row identifier

* utils/lru: simplify to ttl internally and for new methods

* move seenPendingPostIdsCache to App.Server

* just fail concurrent post requests, vs. trying to wait

* add debug log when create post is deduplicated
2018-12-17 15:16:57 -08:00
Harrison Healey
ea8e9497a8 MM-13253/MM-13254 Call PreparePostForClient in app.UpdatePost (#9983) 2018-12-13 09:47:30 -05:00
Christopher Speller
aba194188f MM-12855 Plugin Context (#9922)
* Basic plugin context.

* Adding more useful fields to plugin context.

* Fix spelling

Co-Authored-By: crspeller <crspeller@gmail.com>

* Fixing location of context creation.
2018-12-05 10:46:08 -08:00
Joram Wilander
2d8cb45ff3 Temporary fix for slack attachment fields being clobbered by plugins (#9935) 2018-12-04 11:08:10 +01:00
Joram Wilander
2b99627026 Revert temporary webhook debugging (#9934)
* Revert "More temporary debugging (#9932)"

This reverts commit eab2336bb1.

* Revert "Add temporary webhook debug logs (#9931)"

This reverts commit 043a455ce3.
2018-12-03 15:05:52 -05:00
Joram Wilander
eab2336bb1 More temporary debugging (#9932) 2018-12-03 17:27:26 +01:00
Carlos Tadeu Panato Junior
1bcf08aa4b Refactor Get/Create Direct Channel into one function (#9867)
* refactor GetDirectChannel and CreateDirectChannel in one function

* remove CreateDirectChannel plugin api and update GetDirectChannel and GetGroupChannel plugin api

* update tests
2018-11-28 18:01:49 +01:00
Harrison Healey
ba627c0f92 Skip getting the post again when getting file metadata for a post (#9879) 2018-11-26 10:47:01 +00:00
Harrison Healey
d018554ef3 MM-11434 Only call PreparePostForClient once when creating a post (#9868) (#9876)
* MM-11434 Only call PreparePostForClient once when creating a post

* Have PreparePostForClient provide new metadata when a post already has it and update tests
2018-11-23 10:20:02 -05:00
Harrison Healey
c9f3d03b6d Merge branch 'master' into post-metadata 2018-11-22 13:11:55 -05:00
Jesse Hallam
c46d8ec892 MM-12974: guard app plugins with mutex (#9818)
* guard app plugins with mutex

Shutting down the app could race with a goroutine that uses the plugins environment, since we shut down the plugins first before cleaning up goroutines.

* fix go vet issues
2018-11-20 08:52:51 -05:00
Harrison Healey
8dc865b917 Merge branch 'master' into post-metadata 2018-11-19 16:51:56 -05:00
Joram Wilander
8cfca681b0 MM-12843 Add interactive dialogs (#9816)
* Add interactive dialogs

* Fix unit test

* Updates per feedback

* Fix typo

* Updates per feedback, add icon_url and error returns

* Updates per feedback

* Update per feedback
2018-11-19 15:27:17 -05:00
Harrison Healey
23c8950312 MM-11434 Performance improvements for post metadata (#9849)
* Remove unused error return value from PreparePostForClient

* Remove unused error return value from PreparePostListForClient

* MM-11434 Parallelize PreparePostListForClient

* MM-11434 Skip looking reactions and files on post whenever possible

* Add note about the use of deprecated fields
2018-11-19 13:26:40 -05:00
Harrison Healey
7aef759fd8 Merge branch 'master' into post-metadata 2018-11-16 09:34:35 -05:00
George Goldberg
f0351f23f1 MM-12818: Delete FileInfos when deleting the post they belong to. (#9828) 2018-11-14 13:01:44 -05:00
Harrison Healey
d07def5169 Merge branch 'master' into post-metadata 2018-11-14 09:58:56 -05:00
Christopher Speller
ecade2f1ec MM-12849 Moving all non request scoped items to Server struct (#9806)
* Moving goroutine pool

* Auto refactor

* Moving plugins.

* Auto refactor

* Moving fields to server

* Auto refactor

* Removing siteurl duplication.

* Moving reset of app fields

* Auto refactor

* Formatting

* Moving niling of Server to after last use

* Fixing unit tests.
2018-11-07 10:20:07 -08:00
Harrison Healey
2959b53d98 MM-11272 Add OpenGraph and image dimension metadata to posts (#9313)
* Move OpenGraph code into its own file

* Move OpenGraph image proxying to app layer

* Move test file code out of api4 package

* MM-11272 Add OpenGraph and image dimension metadata to posts
2018-11-01 15:25:11 -04:00
Harrison Healey
48f16b6401 MM-11272 Added initial post metadata (#9175)
* MM-11272 Added app.PreparePostForClient

* MM-11272 Added app.PreparePostListForClient

* MM-11272 Added EmojiStore.GetMultipleByName

* MM-11272 Added emojis to PreparePostForClient

* MM-11272 Added unit tests for getting reaction counts

* MM-11272 Added unit tests for TestPreparePostForClient

* MM-11272 Added emojis from reactions to Post.Emojis

* MM-11272 Always update post.UpdateAt when reactions change to bust cache

* Fixed merge conflicts

* Moved post metadata-related code into its own file

* Update store mocks

* Fixed typo

* Add missing license headers

* Updated post metadata tests when custom emojis are disabled

* Fix unreliable unit tests

* Fix inconsistent casing in SQL statements

* Fix blank line

* Invalidate store cache after making changes

* Clear post cache synchronously with reactions
2018-11-01 15:22:33 -04:00
Hanzei
6c6638f05e GH-9688: Migrate to idiomatic error handling in app/post.go (#9697)
* Migrate to idiomatic error handling in app/post.go

* Revert import changes
2018-10-19 16:29:39 +01:00
Andreas Linz
cf9b9802a8 Set a proper HTTP user-agent header (#9482)
Previously, mattermost-server would always request with the default
user-agent of Go's net/http package that is `Go-http-client/1.1` or
something similar.
This has several disadvantages, one is that the default user-agent
made it pretty hard to distinguish mattermost requests from other
service requests in a network log for example.

Now a user-agent of the form `mattermost-<current-version>` is set in
the client.

- [x] Added or updated unit tests (required for all new features)
2018-10-03 10:28:44 -07:00
Christopher Speller
4546423427 Fixing non elastic search paging. (#9471) 2018-09-27 15:11:19 -04:00
Jesús Espino
49e0473753 MM-11567: Autocomplete search in: for DMs and GMs (#9430)
* MM-11567: Autocomplete search in: for DMs and GMs

* Adding unit tests

* Allowing to search Direct Messages in the autocompletion

* Fix it in TE
2018-09-27 16:15:41 +02:00
Jesús Espino
15d64fb201 MM-7188: Cleaning push notification on every read, not only on channel switch (#9348)
* MM-7188: Cleaning push notification on every read, not only on channel switch

* Removed unnecesary goroutine

* Fixing tests

* Applying suggestion from PR
2018-09-26 16:34:12 +02:00
Christopher Speller
37e00ef916 Adding paging to elasticsearch API. (#9425) 2018-09-26 10:27:04 -04:00
Hanzei
1463df21a5 Add ChannelId and TeamId to PostActionIntegrationRequest (#9384)
* Add ChannelId and TeamId to PostActionIntegrationRequest

* Add tests
2018-09-19 08:39:36 -04:00
Charles Birk
a755bcdde6 [MM-11860]: Expose slack attachment parsing functions in the model package (#9351)
Refactored parseSlackAttachment functions from https://github.com/mattermost/mattermost-server/blob/master/app/post.go#L312
into model/slack_attachments.go so that plugins have access to them.
2018-09-17 10:15:28 -04:00
Carlos Tadeu Panato Junior
1f87596e75 Merge release-5.3 2018-09-10 16:13:21 +02:00
Christopher Speller
a8d116b381 Speed up search results post selection. (#9380) 2018-09-10 15:20:01 +02:00
Harrison Healey
0027d99855 MM-11855 Add App.HTTPService to allow mocking of HTTP client (#9359)
* MM-11855 Add App.HTTPService to allow mocking of HTTP client

* Initialize HTTPService earlier
2018-09-07 09:24:18 -04:00
Christopher Speller
9f46512759 MM-11693 Allow connections to /plugins for interactive message buttons. (#9333)
* Allow connetions to /plugins for interactive message buttons.

* Adding siteurl to exclusions for AllowedUntrustedInternalConnections

* Adding subpath support for allowing interactive message buttons plugin connections.
2018-09-02 09:30:10 +02:00
Dmitry Samuylov
42806ae965 Feature/search after before on (#9219)
* initial implementation of after, before, on search flags allowing to restrict the search to a specific day or a date range

* missed setting beforeDate in SearchParams in one place

* fixed condition when only flags are used for search without any plain terms

* changed date format used for after/before/on flags to be in ISO8601 format as suggested in PR comments, added a helper function to pad month and day with zeroes allowing the user user either format, with or without leading zeroes

* corrected expected compare to date setting for the TestParseDateFilterToTimeISO8601 test

* fixed a bug for the scenario when you only have the date flags without any terms, added a couple of tests for that scenario

* updated the date filter logic to use parameters to construct the query instead of simply appending strings together, as suggested in the pull request comments

* added search unit test using date flags

* added a helper function to create a test post with a createat date manually set, updated the test for search using date flags to create test posts with different createat dates to be able to better test the functionality

* MM-11817 Add support for after/before/on search flags with Elasticsearch

* add support to search posts to perform the search in context of the client's timezone when filtering by createat date using on: after: before: flags

* updated tests to match the new signature
2018-08-28 13:09:32 -04:00
Joram Wilander
4de2e5206e Support for interactive menus in message attachments (#9285) 2018-08-24 11:16:17 +01:00
Carlos Tadeu Panato Junior
5876b52ecd Merge release-5.2 2018-08-24 11:36:39 +02:00
George Goldberg
d2945cdd77 MM-11782: Make archived channels experimental and off-by-default. (#9281)
* MM-11782: Make archived channels experimental and off-by-default.

* Fix test.
2018-08-22 21:12:51 +02:00
Hanzei
c2f2fda8a1 Add PostId to PostActionIntegrationRequest (#9270) 2018-08-18 08:35:32 -04:00
Jesse Hallam
04749027f6 MM-11575: change plugin nil semantics (#9212)
* change MessageWillBePosted nil return semantics

* change FileWillBeUploaded nil return semantics

* use LogDebug to verify plugin inputs vs. the confusing Delete(User|Team)
2018-08-03 13:15:51 -04:00
Martin Kraft
5872bf9c2f Pr 9039 (#9187)
* MM-11065: Allow to search and get archived channels from the API

* Fixing more tests

* Add some unit tests

* Add includeDeleted parameter to session permissions check function

* More test fixing

* Adding archive channels list in channels search

* Add restriction for archived channel edition

* Reverting permissions checks modification

* Changed the query parameter to include_deleted

* Enable search archive channels as true by default

* Adding tests for verify search on deleted channels

* Allowing to override archive channels during the imports

* Fixed test

* Search in archive channels from the API must be explicitly requested

* Removing includeDeleted parameter from GetChannelByName and GetChannelByNameForTeam

* Back to ViewArchivedChannels config

* Fixing tests

* Reverting GetChannelByName parameter

* Add include deleted parameter on GetChannel functions in plugins api

* Fixing tests
2018-07-30 15:06:08 -04:00
JoramWilander
b78b216a3c Merge branch 'master' into plugins-2 2018-07-07 12:04:18 -04:00
Christopher Speller
4c1ddcff10 MM-10703 Adding blank request context to plugin hooks for future use. (#9043)
* Adding blank request context to plugin hooks for future use.

* Rename RequestContext to Context

* Adding context to ServeHTTP and ExecuteCommand

* Fixing import cycle in test.
2018-07-06 09:07:09 -04:00
Declan Freeman-Gleason
4de50ddfc3 MM-10603: Ignore Redirects and Other Changes when Displaying Link Previews (#9025)
* Don't use redirected URL in link preview.

* Only show preview if OG data is provided.
2018-07-05 09:45:08 -04:00
Christopher Speller
1e5c432e10 MM-10702 Moving plugins to use hashicorp go-plugin. (#8978)
* Moving plugins to use hashicorp go-plugin.

* Tweaks from feedback.
2018-06-25 12:33:13 -07:00
Harrison Healey
226d4b2ac8 MM-6992 Added highlighting to elasticsearch results (#8861)
* MM-6992 Added highlighting to elasticsearch results

* Added a unique type for post search matches

* Fixed Elasticsearch matches not being sent through API
2018-06-19 11:46:29 +02:00
Martin Kraft
260d7a0f85 MM-10412: Adds deleteBy prop to posts. (#8896) 2018-06-01 12:45:46 -04:00
Christopher Speller
df6a7f8b19 MM-10249 Adding plugin ability to intercept posts before they reach the DB. (#8791)
* Adding plugin ability to intercept posts before they reach the DB.

* s/envoked/invoked/
2018-05-15 13:33:47 -07:00
Hyeseong Kim
e73f1d7314 MM-9072/MM-10185 Force-convert the encoding of OpenGraph metadata to UTF-8 (#8631)
* Force-convert non-UTF8 HTML to UTF8 before opengraph processing

* Split the force-encoding function

* Add benchmark Test for the forceHTMLEncodingToUTF8()

```
Running tool: /home/comet/go-v1.9.2/bin/go test -benchmem -run=^$ github.com/mattermost/mattermost-server/app -bench ^BenchmarkForceHTMLEncodingToUTF8$

[03:32:58 KST 2018/04/21] [INFO] (github.com/mattermost/mattermost-server/app.TestMain:28) -test.run used, not creating temporary containers
goos: linux
goarch: amd64
pkg: github.com/mattermost/mattermost-server/app
BenchmarkForceHTMLEncodingToUTF8/with_converting-4         	  100000	     11201 ns/op	   18704 B/op	      32 allocs/op
BenchmarkForceHTMLEncodingToUTF8/without_converting-4      	  300000	      3931 ns/op	    4632 B/op	      13 allocs/op
PASS
ok  	github.com/mattermost/mattermost-server/app	2.703s
Success: Benchmarks passed.
```

* Remove an unnecessary constraint

* Add pre-check if content-type header is already utf-8

* Move the checking for utf-8 into forceHTMLEncodingToUTF8() for testing

* Revert df3f347213faa0d023c26d201fa6531f46391086..HEAD, without Gopkg.lock
2018-04-30 09:54:11 -07:00
Christopher Speller
686c2fbab7 Structured logging (#8673)
* Implementing structured logging

* Changes to en.json to allow refactor to run.

* Fixing global logger

* Structured logger initalization.

* Add caller.

* Do some log redirection.

* Auto refactor

* Cleaning up l4g reference and removing dependancy.

* Removing junk.

* Copyright headers.

* Fixing tests

* Revert "Changes to en.json to allow refactor to run."

This reverts commit fd8249e99b.

* Fixing some auto refactor strangeness and typo.

* Making keys more human readable.
2018-04-27 12:49:45 -07:00
Martin Kraft
e13e64711f Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-1 2018-03-27 09:01:42 -04:00
Jesse Hallam
8491ba5740 Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1

* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests

* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2

* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)

This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.

* MM-9661: emit MaxPostSize in client config

This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.

* MM-9661: introduce and use SqlPostStore.GetMaxPostSize

Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).

* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore

* address feedback from code review:

* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition

* modify upgrade semantics to match new db semantics

gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
  * gorp uses TEXT for string columns without a maximum length
  * gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
  * gorp uses TEXT for string columns with a maximum length >= 256
  * gorp uses VARCHAR(N) for string columns with a maximum length of N
  * gorp defaults to a maximum length of 255, implying VARCHAR(255)

So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.

Ideally, we'd revisit the gorp behaviour at a later time.

* allow TestMaxPostSize test cases to actually run in parallel

* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics

* fix casting error

* MM-9661: skip the schema migration for Postgres

It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00