Commit Graph

2345 Commits

Author SHA1 Message Date
Nick Misasi
3099128bbd [MM-29845] Add a new handler to allow authentication via CWS API Key (#16319)
* Add a new handler to allow authentication via CWS API Key

* Make error better

* Add tests and cases for new handler functions

* Move some code around

* Add test for GetCloudSession function

* unset the env after test completion

* Remove white space

* Change Info to Warn

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-23 14:34:10 -05:00
Deep Baldha
27462bbfc9 MM-30819: Change to idiomatic receiver names for slashcommands.PurposeProvider (#16344)
Automatic Merge
2020-11-23 19:45:17 +01:00
Deep Baldha
c4891bdb51 MM-30817: Change to idiomatic receiver names for slashcommands.OfflineProvider (#16342)
Automatic Merge
2020-11-23 15:45:17 +01:00
Agniva De Sarker
d9e8402dc2 MM-30319: Fix race in ensureAsymmetricSigningKey (#16354)
A cluster changed listener always runs in a separate goroutine.
This causes a race condition when a new member gets added in the cluster.

We fix it by accessing the value atomically.

I tried to write a test for this, but it wasn't triggering at all.
The best way is to just start the server with cluster enabled in race mode,
and verify that the race doesn't happen.

https://mattermost.atlassian.net/browse/MM-30319

```release-notes
NONE
```
2020-11-23 19:18:24 +05:30
OgmaJ
d28e7ec870 [MM-30136] Issuing /dnd consecutively should not toggle the user status between dnd and online (#16258)
Summary
/dnd will only do a do not disturb

Ticket Link
Fixes #16253
JIRA https://mattermost.atlassian.net/browse/MM-30136

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-23 15:06:43 +05:30
Jesús Espino
9ec09c2bcd Remove unneeded Err field in the store result struct (#16322)
* Remove unneeded Err field in the store result struct

* Fixing references to old errors in the tests
2020-11-23 09:26:01 +01:00
Harrison Healey
c54ab6da21 Revert "[MM-29224] Fix bug where markdown image link doesn't show preview (#15862)" (#16326)
This reverts commit 07948ae7bc.
2020-11-20 11:23:21 -05:00
Agniva De Sarker
4cdf239139 MM-29107: Fix race in LDAP login (#16239)
* MM-29107: Fix race in LDAP login

We remove the goroutine to make things synchronous.

This removes the race and makes things more reliable.
It is already tested by TestLogin in ldap_test.go in -race mode.

https://mattermost.atlassian.net/browse/MM-29107

```release-note
NONE
```

* Address review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-20 18:07:31 +05:30
Eli Yukelzon
cf4df5fcd2 MM-30048 added thread related socket messages (#16234)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-20 11:00:52 +02:00
Deep Baldha
7b515d27f2 MM-30705: remove receiver names for empty struct- InvitePeopleProvider (#16300)
Automatic Merge
2020-11-20 00:15:17 -05:00
Ibrahim Serdar Acikgoz
213345fa2c add manage_remote_clusters permission (#16252) 2020-11-18 18:40:12 +03:00
Ibrahim Serdar Acikgoz
50e29cb47a app/user: fix update user error when an e-mail address already in use (#16269)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-18 12:31:57 +03:00
Agniva De Sarker
221f70a6cb MM-29487: Fix racy TestMuteCommandSpecificChannel (#16290)
The code was doing `go fakeApp.UpdateProductNotices()`
due to which the Store object was accessed in a racy manner
when it was reset if the localcachelayer flag was set.

We fix this by using the StoreOverride functionality
to pre-define what store to use while initializing the server
itself so that there isn't a need to reset the store _after_
the server is set.

We also apply the same fix in the app and api4 layers too
to prevent similar things from happening there.

https://mattermost.atlassian.net/browse/MM-29487

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-17 21:13:35 +05:30
Ben Schumacher
4063f407a1 Use different user-agent for twitter links (#16210) 2020-11-17 14:48:51 +01:00
Rodrigo Villablanca
95221d9ace GroupStore migration (#15795)
* Migration completed

* Fix tests

* Fix tests

* Fix tests

* Suggestions

* Trigger CI

* Suggestions

* Merge with master

* Migration completed

* Fix typo

* fix err check

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-11-17 09:02:36 +05:30
Harrison Healey
2ebc8ec90f MM-20897 Add category muting (#16225)
* Make UpdateSidebarCategories return the original categories

* MM-20897 Add category muting

* Prevent muting the DMs category

* Fix muted state not being stored in the database

* Address feedback

* Address some feedback

* Fix unit tests

* MM-20897 Mute/unmute channels in the database in bulk

* Satisfy golangci-lint
2020-11-16 15:19:01 -05:00
Miguel de la Cruz
6c857a4525 [MM-30436] Add support for configuration custom defaults (#16265)
* [MM-30436] Add support for configuration custom defaults

* Addressing review comments

* Addressing PR comments

* Soft fail if the configuration defaults cannot be read

* Directly print error in log message

* Fix linter

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-16 15:25:48 +01:00
Agniva De Sarker
c82c37a36e MM-28067: Optimize app server startup in tests (#16263)
* MM-28067: Optimize app server startup in tests

For every test, we would wipe out the database and then start
the server again. This would run through all the migrations
and create new rows in Systems and Roles table every time.
As a result, this was consuming a lot of setup time for every test.

We optimize this by preloading the DB with dummy data in the roles
and systems table so that the server code just skips over those migrations.
This is completely forward compatible and adding new migrations does not
need to generate the sql files again. Only in case of schema changes to the
roles or systems table, this would need to be done.

It is unlikely the Systems table schema will get changed. The Roles table
might change in future but it's a comparatively rare event. Given the reduction
in CI runtime we are seeing, it's a worthy optimization.

We also apply some more optimizations:
- Coalesce multiple UpdateConfig calls into a single one. Each UpdateConfig call
has to do a json marshal which would take precious CPU cycles. It's much more
efficient to do everything in a single call.
- Remove unnecessary debug.FreeOSMemory in reload config. This was an artifact
from old days and is no longer required.

Numbers:
Results show a full **2 minutes** shaved off the test runtime. Earlier, tests
would take around 16 minutes. Now they take 14 minutes.

```release-note
NONE
```

* fix app package
2020-11-16 13:55:32 +01:00
Dexter Chua
e162c6c787 Indicate deleteBy in post_deleted websocket event (#15332)
This lets the client know who deleted the post. This information is
stored in the database, but cannot be retrieved from an API endpoint
because the API does not return information about deleted post.

Currently, the information is only sent to system administrators.
2020-11-16 11:56:29 +01:00
Doug Lauder
277f886b3f MM-30212 Support dynamic autocomplete for built-in slash commands (#16196)
Support added for dynamic auto-completion lists for built-in slash commands.

* a moniker within the fetch url determines whether the request should be sent via HTTP(S) or routed internally to a built-in command. The moniker is of the form builtin: followed by the name of the built-in command to use. e.g. builtin:share would be become a call to the share command to fetch auto-completion items.

* command providers implement the optional DynamicListProvider interface to indicate they can provide dynamic auto-completion.
2020-11-13 21:10:07 -05:00
Ibrahim Serdar Acikgoz
46a409aef6 app/server_test: make sure sentry is ready to be setup (#16260) 2020-11-13 19:10:10 +03:00
Farhan Munshi
c9a4a475d3 [MM-28717] Refactor applyMultiRoleFilters to use sq builder (#15500)
* Refactor apply multi role filters and add role filters to get all profiles

* Add some tests

* Fix tests

* Fix lint

* Trigger CI

* Rename param to make more sense

* Tie get filtered user stats to usermanagement read users

* Dont filter out other system roles when searching for team members or team admins only filter out system admins

* add new permissions

* add migration

* fix test

* remove system roles as default permissions

* implement changes discussed with dennis

* add read only and fix i18n

* use model consts instead of strings

* turn the permissions into pseudo constants

* Update read only default permissions

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Hossein Ahmadian-Yazdi <hyazdi1997@gmail.com>
2020-11-13 10:57:57 -05:00
Nick Misasi
1d15900f84 [MM-29999] User Limit Email Notifications (Part 2) (#16220)
* Adding files commiting to do something else

* Stashing to merge master

* Adding files, commit of working code, pre-test

* Changing up logic according to new conversations, adding template and functions for 7 day and 14 day emails

* Add subscription active check

* Add a comment around subscription status

* Fix i18n

* Update jobs/cloud/worker.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Add a check for cloud license and exit early

* remove log

* Update jobs/cloud/worker.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Remove case for 91st day

* Change var name

* Fix i18n

* Change value for dates in email

* Add email template and send logic for support email on 30th day of arrears

* Fix EETests?

* add one to the day so the count starts on first day of next cycle

* use the license for the enabled check

* Moved scheduler and worker into enterprise

* Add the user count to the support email

* remove a line

* Use the date for the 14 day email

* Fix for design review

* More font changes

* Fixes for PR

* Change feature flag name

* Add cloud_interface to einterfaces/jobs

* Add back & for running job server

* Remove unused constant

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-12 09:07:31 -05:00
Agniva De Sarker
cae59d327c MM-29486: Fix racy test TestPatchChannelModeration (#16256)
* MM-29486: Fix racy test TestPatchChannelModeration

- We avoid appending to the slice in `(r *Role) IsValidWithoutId`
by just iterating the 2 slices separately.
- We pass deep copies of channels to prevent racy modification.

https://mattermost.atlassian.net/browse/MM-29486

```release-note
NONE
```

* fix lint

* simplify perm check

* improve more

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-12 15:26:35 +05:30
Agniva De Sarker
87a5510adc MM-29479: Fix racy test TestSidebarCategory (#16255)
Automatic Merge
2020-11-11 12:49:56 -05:00
Agniva De Sarker
0ca8cb36b4 MM-26425: Make URL parsing for image proxy more robust (#16197)
* MM-26425: Make URL parsing for image proxy more robust

- We don't bypass protocol relative URLs.
- We don't bypass hostnames with a similar prefix.

https: //mattermost.atlassian.net/browse/MM-26425

```release-note
NONE
```

* fix tests and incorporate review comments

* Handle opaque URLs

* Fix path tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-10 13:06:59 +05:30
Agniva De Sarker
39b5b601f8 MM-30026: Use DB master when getting team members from a session (#16170)
* MM-30026: Use DB master when getting team members from a session

A race condition happens when the read-replica isn't updated yet
by the time a session expiry message reaches another node in the cluster.

Here is the sequence of events that can cause it:
- Server1 gets any request which has to wipe session cache.

- The SQL query is written to DB master, and a cluster message is propagated
to clear the session cache for that user.

- Now before the read-replica is updated with the master’s update,
the cluster message reaches Server2. The session cache is wiped out for that user.

- _Any random_ request for that user hits Server2. Does NOT have to be
the update team name request. The request does not find the value
in session cache, because it’s wiped off, and picks it up from the DB.
Surprise surprise, it gets the stale value. Sticks it into the cache.

By now, the read-replica is updated. But guess what, we aren’t going to
ask the DB anymore, because we have it in the cache. And the cache has the stale value.

We use a temporary approach for now by introducing a context in the DB calls so that
the useMaster information can be easily passed. And this has the added advantage of
reusing the same context for future DB calls in case it happens. And we can also
add more context keys as needed.

A proper approach needs some architectural changes. See the issue for more details.

```release-note
Fixed a bug where a session will hold on to a cached value
in an HA setup with read-replicas configured.
```

* incorporate review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-10 10:43:45 +05:30
Eli Yukelzon
45e340b5be MM-29987 Implement new collapsed threads API (#16091) 2020-11-08 10:36:46 +02:00
sowmiyamuthuraman
5a6d8387f5 MM-29379 Ignore channel mentions when channel is muted and channel mention setting is not updated by the user (#15992) 2020-11-04 10:13:24 +01:00
Agniva De Sarker
4758408699 MM-29979: make websocket writes zero-alloc (#16115)
This reverts commit 31dac80e66.
2020-11-04 10:05:10 +05:30
Jared Shields
3515b4d6c9 GH-15624: Added plugin hooks for ReationHasBeenAdded and ReactionHasBeenRemoved (#15765) 2020-10-31 07:06:43 +01:00
Eli Yukelzon
fe352ab57f MM-29703 Mark threads as read when channels are marked (#15994)
Co-authored-by: Jesús Espino <jespinog@gmail.com>
2020-10-30 17:00:21 +02:00
Agniva De Sarker
325bff1176 MM-30041: Return correct error message for user save (#16117)
* MM-30041: Return correct error message for user save

We were collapsing all types of user conflict into a single
error message. Fixed it by inspecting the field of the invalidError type
and returning the correct message.

https://mattermost.atlassian.net/browse/MM-30041

```release-note
NONE
```

* Fix test errors

* Fix wrong message in test when comparing error messages

Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com>
2020-10-30 11:14:06 +05:30
Christopher Speller
1aadd36644 MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)
* Add feature flag managment system using split.io and remove viper.

* Fixing tests.

* Attempt to fix postgres tests.

* Fix watch filepath for advanced logging.

* Review fixes.

* Some error wrapping.

* Remove unessisary store interface.

* Desanitize SplitKey

* Simplify.

* Review feedback.

* Rename split mlog adatper to split logger.

* fsInner

* Style.

* Restore oldcfg test.

* Downgrading non-actionable feature flag errors to warnings.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-29 15:54:39 -07:00
Christopher Speller
31dac80e66 Revert "MM-29979: make websocket writes zero-alloc (#16098)" (#16110)
Automatic Merge
2020-10-28 16:24:01 -04:00
Agniva De Sarker
f964be699f MM-29979: make websocket writes zero-alloc (#16098)
* MM-29979: make websocket writes zero-alloc

Instead of allocating a new slice every time we write a message,
we create a json encoder for a byte buffer and then reset the buffer
every time we write a new message.

This allocates a buffer of a constant size per-connection, but gets rid
of a new allocation for every single write, reducing pressure on GC.

After taking a distrbution of message sizes from a load test, it was seen that
2k is a good enough buffer size within which 98.5% of messages remain.

Taking a look at the alloc profiles for (*webconn).writepump:
- master branch: 8.01% of total allocations totalling 64GB
- with this PR: 4.92% and 10GB.

https://mattermost.atlassian.net/browse/MM-29979

* Skip writing in case of an encoding error
2020-10-28 21:42:13 +05:30
Agniva De Sarker
27dbe9e182 MM-28984: Add fallback text to push notification (#16089)
We read the fallback text from message attachments and append that as part
of a push notification.

https://mattermost.atlassian.net/browse/MM-28984

```release-note
NONE
```
2020-10-28 10:42:08 +05:30
Claudio Costa
165c4d2dd1 [MM-29295] Fix data race in app.CreatePost() (#15880)
* Fix data race

* Better naming

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-27 20:11:38 +01:00
Ben Schumacher
76f1bfb941 [MM-29361] Send cloud flag with Marketplace requests (#15913) 2020-10-26 21:57:19 +01:00
Nick Misasi
3697f92045 [MM-28363] User Limit Overage Warning Emails (#16053)
* Adding files, commit of UI in good shape

* Translations added, working with activation and deactivation

* Add check for error

* Fix i18n?

* Push without subscription check so Steve and Matt can look at it

* Fix font-weight in chrome

* Fix font-weight on button

* UX fixes

* Fixes for PR

* Add back subscription stuff

* Fix tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-26 13:24:26 -04:00
Agniva De Sarker
72432ab3ff MM-27909: Add manage_shared_channels permission (#15601)
* MM-27909: Add manage_shared_channels permission

We add a new permission to manage shared channels.

It's a channel scoped permission and only the system admin
has that by default.

https://mattermost.atlassian.net/browse/MM-27909

* change to system scoped

* Trigger CI

* Trigger CI

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-26 15:54:50 +05:30
Rodrigo Villablanca
96f1739f8f UserStore migration (#15563)
* Migration completed

* Fix tests

* Fix tests

* Fix tests

* Suggestions

* Trigger CI

* Suggestions

* Merge with master

* Trigger CI

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-10-26 15:11:27 +05:30
Daniel Espino García
910de96a33 Thread autoresponse posts with the post they are autoresponding to (#15625)
* Thread autoresponse posts with the post they are autoresponding to

* Remove unneeded if

* Remove ParentID references

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-23 16:21:21 +02:00
Scott Bishel
efc3304fe1 MM-29522:fix typo in constant name (#15933)
* fix type in constant name

* fix lint

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-21 16:59:54 -06:00
George Goldberg
9b23ee659f MM-29812: Fix a panic in auth code if GetChannel returns an error. (#16010)
* MM-29812: Don't panic if GetChannel returns an error in auth code.

* Fix gofmt

* Add further mocking.

* Another mock.

* More mocks.
2020-10-21 16:59:32 +01:00
Ed Trist
91bb7d3b11 [MM-24391] Render icon_emoji names surrounded by colons in incoming webhooks (#15753) 2020-10-21 14:13:10 +02:00
Ibrahim Serdar Acikgoz
c05ee81c9f [MM-28125] einterface/oauthprovide: return parsing errors (#15426)
* einterface/oauthprovide: return parsing errors

* Update app/oauth.go

* reflect review comments

* fix var name error

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-19 18:07:20 +03:00
Eli Yukelzon
8844141df3 MM-28249 Auto follow threads (#15878)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-15 18:01:16 +03:00
camgraff
07948ae7bc [MM-29224] Fix bug where markdown image link doesn't show preview (#15862)
* Fix bug where markdown image has no preview

* go fmt

* Fix failing test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-14 20:36:46 +08:00
Eli Yukelzon
c9257b858e MM-29560 Correct Cloud detection in InProduct Notices (#15938)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-13 16:42:21 +03:00