* 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>
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
```
* 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>
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>
* 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
* 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
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.
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.
* 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>
* 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>
* 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>
* 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>
* 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>
* 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
* 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>
* 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>
* 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>