Commit Graph

94 Commits

Author SHA1 Message Date
dantepippi
aae3b9650f [MM-25477] - Migrate command webhook store AppError to error (#14703)
* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Changes requested in the review.

* Changing http status

* fix i18n

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-07-19 08:42:03 +05:30
Joshua Bezaleel Abednego
48f0b7fd76 MM-25476: Migrate AppError from command_store.go (#14643)
Automatic Merge
2020-07-16 15:26:07 +02:00
Rodrigo Villablanca
e342b5a2f2 Migrate multiples methods from ChannelStore to return error interface (#14708)
Automatic Merge
2020-06-16 10:56:35 +02:00
Jesús Espino
f5eab1271b Removing all FakeApp usages (#14174)
* Removing some other fake apps

* More FakeApp removed

* Removing entirely FakeApp

* Fixing some tests

* Fixing get Cluster id from get plugin status

* Fixing failing tests

* Fixing tests

* Fixing test initialization for web

* Fixing InitServer for server tests

* Fixing InitServer for server tests

* Reverting go.sum and go.mod

* Removing unneded HTMLTemplates function in App layer

* Moving back some functions to its old place to easy the review

* Moving back some functions to its old place to easy the review

* Using the last struct2interface version

* Generating store layers

* Fixing merge problems

* Addressing PR comments

* Small fix

* Fixing app tests build

* Fixing tests

* fixing tests

* Fix tests

* Fixing tests

* Fixing tests

* Fixing tests

* Moving license to server struct

* Adding some fixes to the test compilation

* Fixing cluster and some jobs initialization

* Fixing some license tests compilation problems

* Fixing recursive cache invalidation

* Regenerating app layers

* Fix test compilation

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-12 13:43:50 +02:00
Rodrigo Villablanca
85a69d6112 Migrate Get/GetFromMaster methods from ChannelStore to return error interface (#14688)
* Advances

* Migration finished

* Rename err to normalized error

* fix imports

* Renamed key

* Renamed key

* Suggestions

* Fix i18n

* Fix tests

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-06-02 21:58:29 +05:30
Doug Lauder
65733f4969 MM-24644 fix infinite loop splitting post attachments (#14542) 2020-05-12 09:58:19 -04:00
Claudio Costa
1e53fe85ad [MM-21378] Add mutex to model.Post to guard against race conditions on Post.Props (#13884)
* Add mutex to model.Post to guard against race conditions on Post.Props

* Rename mutex

* Add GetProp() method to Post

* Fix more tests

* Fix flaky test

Benchmarks:

BenchmarkPostPropsGet_indirect
BenchmarkPostPropsGet_indirect-2     	85026746	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-4     	90273747	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-8     	88324293	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-16    	91427720	        13.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct
BenchmarkPostPropsGet_direct-2       	1000000000	         0.242 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-4       	1000000000	         0.241 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-8       	1000000000	         0.240 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-16      	1000000000	         0.241 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_indirect
BenchmarkPostPropsAdd_indirect-2     	 5602224	       203 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-4     	 5959496	       206 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-8     	 5833999	       205 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-16    	 5802493	       225 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_direct
BenchmarkPostPropsAdd_direct-2       	100000000	        11.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-4       	100000000	        11.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-8       	100000000	        11.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-16      	99840794	        11.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_indirect
BenchmarkPostPropsDel_indirect-2     	18824002	        61.9 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-4     	19470736	        63.8 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-8     	17640460	        65.3 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-16    	18692962	        65.4 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_direct
BenchmarkPostPropsDel_direct-2       	516257440	         2.34 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-4       	514865216	         2.43 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-8       	511330477	         2.37 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-16      	499504010	         2.38 ns/op	       0 B/op	       0 allocs/op
2020-03-13 21:12:20 +01:00
Jesús Espino
c9a0418a32 Making private some methods that are not needed publicly (#13959)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-03 22:43:48 +01:00
Eli Yukelzon
17523fa5d9 MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
2020-02-13 13:26:58 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Nikhil Ranjan
9f54e8267f Converting to structured logging the file app/webhook.go (#12142) 2019-09-13 01:31:59 -04:00
Maria A Nunez
3187907b67 MM-16990 - Fix webhooks visible to users without viewing permissions (#11698)
* Filtered incoming webhooks for users wihtout PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS

* Filtered outgoing webhooks for users without PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS

* Refactored GetOutgoingByTeamByUser to its own method in app and store

* Fixed paging condition for outgoing webhooks in store

* Separated test cases into separate t.run in WebhookStore

* Improved unit test. PR Feedback

* Filtered outgoing webhooks by channel for users without PERMISSION_MANAGE_OTHERS

* Filtered getting full list of outgoing webhooks for users without PERMISSION_MANAGE_OTHERS

* Added missing signature for GetOutgoingWebhooksPage in app

* Expanded permissions in test to SYSTEM_USER_ROLE

* Filtered getting full list of incoming webhooks for users without PERMISSION_MANAGE_OTHERS

* Removed unnecessary sq.and operator
2019-07-29 12:32:26 -04:00
Jesús Espino
e067272e16 Cleaning the store from functions returning StoreResult (#11602)
* Cleaning the store from functions returning StoreResult

* Removing unnecesary StoreChannel type
2019-07-29 12:38:46 +02:00
krjn
dd30488a09 [MM-16389] Add icon_emoji parameter to webhooks (#11586)
[MM-16389] Add icon_emoji field to posts from incoming webhooks

To be used to substitute the profile picture on posts.
2019-07-17 11:01:18 +02:00
Taufiq Rahman
9ce5b28c63 [MM-16667] Migrate User.GetByUsername to Sync by default #11453 (#11520)
* Migrate User.GetByUsername to Sync by default #11453

* fix app errors #11453

* fix app errors #11453

* fix cmd error #11453

* fix shadow var #11453

* fix shadow user var #11453

* fix test error

* fix test error #11453
2019-07-10 10:46:03 +02:00
Rodrigo Villablanca Vásquez
678c8f4f84 Migrate CommandWebhook.TryUse to sync by default (#11593) 2019-07-09 22:57:05 +02:00
Rodrigo Villablanca Vásquez
0ec609d159 Migrate CommandWebhook.Get to sync by default (#11594) 2019-07-09 11:54:25 -04:00
Rodrigo Villablanca Vásquez
25a2e7e981 Migrate CommandWebhook.Save to sync by default (#11595) 2019-07-09 09:42:10 -05:00
Rodrigo Villablanca Vásquez
59e7bf1c23 Migrates Channel.GetByName to sync by default (#11187)
* Channel.GetByName and Channel.GetByNameIncludedDeleted sync by default

* Suggested changes

* Fix some vars shadowing

* Rename of vars inside goroutine

* Shadow variable corrected
2019-06-20 15:21:36 +02:00
Puneeth Reddy
4f7f7070c0 MM 15185 - Migrate "WebHook.GetOutgoingByChannel" to Sync by default (#10704) 2019-05-07 13:50:03 +02:00
Puneeth Reddy
2d3fb4f426 MM-15288: Migrate CommandStore.Get to sync by default (#10739)
* MM-15288: Migrate Command.Get to sync by default

* addressing review comments, updating status code of err returned by Get Method
2019-05-06 18:12:41 +02:00
Puneeth Reddy
eb3923c835 MM-15118: Migrates the "WebHook.DeleteIncoming" to Sync by default. (#10706)
* cherry commit for DeleteIncoming and generate store mocks

* go fmt the code and fix go vet issue
2019-04-30 07:34:08 +02:00
Puneeth Reddy
9f9620b4c8 MM-15186: Migrate "WebHook.GetOutgoingByTeam" to Sync by defa (#10707) 2019-04-26 21:20:36 +02:00
Puneeth Reddy
dc0441e28c change UpdateOutgoing func signature to return OutgoingWebhook and fix formatting (#10710) 2019-04-26 09:28:04 +02:00
Puneeth Reddy
caf0c0d375 MM 15187: Migrate "WebHook.DeleteOutgoing" to Sync by default (#10708)
* cherry commit for DeleteOutgoing and generate store mocks

* go fmt the code
2019-04-26 07:44:00 +02:00
Puneeth Reddy
9fc05b5865 GH-10652: Migrate WebHookStore.GetOutgoingList method to sync by default (#10703)
* Migrate WebHookStore.GetOutgoingList  method to sync by default

* go fmt the code
2019-04-26 07:41:45 +02:00
Syerikjan Kh
9c9c00b020 GH-10614 getoutgoing to sync (#10628) 2019-04-25 08:19:38 +02:00
Andres Orozco
928ecba2d4 MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default (#10667)
* MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default

* MM-15198 - Update store/storetest/post_store.go

fix error handling in post_store.go test case

Co-Authored-By: andresoro <ao15@my.fsu.edu>
2019-04-24 20:28:06 +01:00
Andres Orozco
357065e202 [MM-15121] Migrate "WebHook.GetIncomingList" to Sync by default (#10666)
* SyncStore: migrate WebHooks.SaveIncoming method to Sync

* MM-15121 Migrate WebHook.GetIncomingList to Sync by default

* MM-15121 Migrate WebHook.GetIncomingList to Sync by default - add review changes

* Revert "SyncStore: migrate WebHooks.SaveIncoming method to Sync"

This reverts commit 626a7d1a25.
2019-04-24 09:32:30 +01:00
Andres Orozco
105e8647f8 MM-15116 Migrate WebHook.SaveIncoming Method to Sync by default (#10663)
* SyncStore: migrate WebHooks.SaveIncoming method to Sync

* MM-15116 Migrates the WebHook.SaveIncoming method to Sync by default

* MM-15116 Migrate Webhook.SaveIncoming to Sync by default - fix minor typo

* MM-15116 Migrate WebHook.SaveIncoming to sync -  update test case
2019-04-24 09:30:41 +01:00
Siyuan Liu
eaef1952b0 [MM-15183] Migrate "WebHook.SaveOutgoing" to Sync (#10675) 2019-04-23 16:39:59 +08:00
Siyuan Liu
434f343f69 [MM-15122] Migrate "WebHook.GetIncomingByTeam" to Sync by default (#10631) 2019-04-22 11:29:55 -04:00
Fede
17092e7e48 [MM-15117] Migrate "WebHook.UpdateIncoming" to Sync by default (#10637)
* SyncStore: Migrate Webhooks.UpdateIncoming method to Sync

* Changes requested by @jespino
2019-04-18 13:03:59 +01:00
Jesús Espino
13fba10eb8 SyncStore: Migrate Webhooks.GetIncomming method to Sync (#10613) 2019-04-16 10:16:30 -07:00
Jesús Espino
12c50eb830 Initial migration of the store to be sync (#10592)
* Migrating audit store

* Final migration example for the audit store

* async example

* Ending migration

* Removing Async helper

* Fixing tests

* Fixing govet problems with the StoreResult instanstiation
2019-04-15 22:53:52 +02:00
Joram Wilander
2ca222033c MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898)

* Change fields of config structs to pointers and set defaults

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix tests that go broken during switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Apply changes of current master while switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix new config pointer uses

* Fix app tests

* Fix mail test

* remove debugging statement

* fix TestUpdateConfig

* assign config consistently

* initialize AmazonS3Region in TestS3TestConnection

* initialize fields for TestEmailTest

* fix TestCheckMandatoryS3Fields
2019-01-31 08:12:01 -05:00
Harrison Healey
1a3ccaf305 MM-13606 Remove consumeAndClose and clean up integration response handling (#10066)
* MM-13606 Remove consumeAndClose

* Allow overriding HTTPService's request timeout

* MM-13606 Clean up integration response handling

* Properly close httptest servers

* Address feedback

* Only call buf.Bytes when necessary

* Properly check for errors in doOutgoingWebhookRequest

* Add comment explaining ignored ioutil.ReadAll errors
2019-01-09 17:07:08 -05: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
043a455ce3 Add temporary webhook debug logs (#9931) 2018-12-03 14:50:37 +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
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
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
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
Pradeep Murugesan
b3c2ecd9b9 added the custom icon and username for the outgoing webhook and its response (#9141)
* 8272 added the username and icon as part of the model and persisted the same

* 8272 added the custome icon and name when set to the web hook response

* 8272 changed the infinte loop to timeout after 5 seconds

* 8272  fixed review comments
2018-07-25 08:31:41 -04:00
George Goldberg
0896b5c64e MM-11106: Allow systeadmin webook to post to read only town square. (#9051) 2018-07-06 10:07:36 +02:00
George Goldberg
8fb070fecf MM-10352: Add locking incoming webhooks to a single channel. (#8835) 2018-05-22 11:06:14 -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
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
Carlos Tadeu Panato Junior
cb1b8fc333 [MM-9725] Slack compatibility code in webhooks captures incorrect text (#8428) 2018-03-12 07:40:11 -04:00