Граф коммитов

2036 Коммитов

Автор SHA1 Сообщение Дата
Doug Lauder
5e59b5f70c MM-23935 extend session expiry on user activity (#14275)
* MM-23935  extend session expiry on user activity

- if user types anything before a session expires the session will be extended to now + session length

- ensures new session expiries are not written to DB too frequently

- new session store func for updating session ExpiresAt

- session length defaults for mobile and web/ldap changed from 180 days to 30 days
2020-05-06 15:41:10 -04:00
catalintomai
58305b080f Check license expiration, disable license and notify administrator (#14420)
* Check license expiration and notify administrator
2020-05-06 10:28:49 -07:00
Hossein Ahmadian-Yazdi
40b20c3eaf [MM-24177] Adds props to post for front end to know if highlight or not (#14348)
* Add props to post

* Address PR comments

* address PR comments

* Fix styling problems

* Address PR comments

* address PR comments

* Add PR suggestion

* fix usage

* fix error

* remove err

* fix golang lint
2020-05-05 06:00:59 -04:00
Doug Lauder
a6a58f99e7 MM-24707 fix reply import bug (#14442) 2020-05-01 14:13:06 -04:00
Eli Yukelzon
7800116429 MM-23093 Implement Server Setup telemetry - server configuration (#14374)
* added advanced first day diagnostics reporting

* typo

* config corrected

* defaults

* moved from config to system db table

* missing file

* added error handling

* tests

* typos

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-30 18:18:12 +03:00
Agniva De Sarker
03a55367d9 MM-24312: Fix Dependency updates (#14391)
Automatic Merge
2020-04-29 14:06:09 -07:00
Doug Lauder
a3cf490a4d MM-24575 handle auto-respond to self (#14410) 2020-04-29 14:19:18 -04:00
Jesús Espino
8781c36eb3 Fixing system messages about non-visible users (#14254)
* Fixing system messages about non-visible users

* Adding unit tests to verify the new behavior

* Regenerating app layers

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-28 12:58:34 +02:00
Jesús Espino
224b72c61e MM-24037 Adding getKnowUsers API endpoint (#14332)
* Adding getKnowUsers API endpoint

* Adding i18n strings

* Fixing golint errors

* Adding doc strings

* Remove debug line

* Updating app_iface

* Fixing gofmt
2020-04-28 12:52:43 +02:00
Agniva De Sarker
d3b36e3455 app: outdent skipSend condition (#14377)
We invert the skipSend condition and outdent the remaining block
to make the code a bit more idiomatic.

While here, we also change the dropping message level from info to
warn because that's what it should be.
2020-04-28 15:27:58 +05:30
Agniva De Sarker
f79b7567b1 MM-23896: Fix clearing of batched emails on user activity (#14340)
On user activity, we were clearing the job.pendingNotifications map.
But we had already created a copy of the notifications slice while
iterating the map. Therefore, if we pass the copied slice, it would
still have the old notifications which were originally deleted.

The unit tests would not catch this because it was testing the
job.pendingNotifications map and not actually checking if the email
handler was being called or not. We fix that now.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-28 00:59:48 +05:30
Farhan Munshi
b29b70da09 MM-23605 Create new team scheme updated socket event (#14305) 2020-04-27 13:26:52 -04:00
Farhan Munshi
7bc630a600 [MM-23727] Make channel validation consistent on the server (#14230)
* MM-23727 Ensure user ids not allowed in channel name:

MM-23727 Move channel name validation to model level

* MM-23727 Update wording
2020-04-26 12:38:33 -04:00
Agniva De Sarker
e39569b358 MM-23805: Refactor web_hub (#14277)
* MM-23800: remove goroutineID and stack printing

Each hub has a goroutineID which is calculated with a known hack.
The FAQ clearly explains why goroutines don't have an id:
https://golang.org/doc/faq#no_goroutine_id.

We only added that because sometimes the hub would be deadlocked and
having the goroutineID would be useful when getting the stack trace.
This is also problematic in stress tests because the hubs would
frequently get overloaded and the logs would unnecessarily have stack traces.

But that was in the past, and we have done extensive testing with
load tests and fuzz testing to smooth any rough edges remaining.
Including adding additional metrics for hub buffer size.

Monitoring the metrics is a better way to approach this problem.
Therefore, we remove these kludges from the code.

* Also remove deadlock checking code

There is no need for that anymore since
we are getting rid of the stack printing anyways.

Let's do a wholesale refactor and clean up the codebase.

* MM-23805: Refactor web_hub

This is a beginning of the refactoring of the websocket code.

To start off with, we unexport some methods and constants which did not
need to be exported. There are more remaining but some are out of scope for this PR.

The main chunk of refactor is to unexport the webconn send channel
which was the main cause of panics. Since we were directly sending
to the connection from various parts of the codebase, it would be possible
that the send channel would be closed and we could still send a message.
This would crash the server.

To fix this, we refactor the code to centralize all sending from the main
hub goroutine. This means we can leverage the connections map to check
if the connection exists or not, and only then send the message.

We also move the cluster calls to cluster.go.

* bring back cluster code inside hub

* Incorporate review comments

* Address review comments

* rename index

* MM-23807: Refactor web_conn

- Unexport some struct fields and constants which are not necessary
to be accessed from outside the package. This will help us moving
the entire websocket handling code to a separate package later.

- Change some empty string checks to check for empty string rather
than doing a len check which is more idiomatic. Both of them compile
to the same code. So it doesn't make a difference performance-wise.

- Remove redundant ToJson calls to get the length.

- Incorporate review comments

- Unexport some more methods

* Fix field name

* Run make app-layers

* Add note on hub check
2020-04-23 13:16:18 +05:30
Jesse Hallam
636d168b84 MM-23926: avoid setting last viewed for bots (#14253)
The current code path for `CreatePostAsUser` tries to update the `LastViewedAt` for bots, which logs a warning message if the bot isn't actually in the channel.

This pull request changes the semantics of bot posting to not update the bot's `LastViewedAt` timestamp, avoiding this log altogether. It matches the semantics of `from_webhook`, but notably makes bots slightly less like users in that they no longer "read" channels when they post. This seems reasonable, but I'm both looking for validation of this semantic change in addition to the code review.

Fixes: https://mattermost.atlassian.net/browse/MM-23926

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-22 12:28:31 -03:00
Doug Lauder
d390942581 MM-24217 ensure updating Mfa secret and status invalidates cache (#14334) 2020-04-22 09:09:13 -04:00
Agniva De Sarker
d9713792ba MM-23800: remove goroutineID and stack printing (#14268)
* MM-23800: remove goroutineID and stack printing

Each hub has a goroutineID which is calculated with a known hack.
The FAQ clearly explains why goroutines don't have an id:
https://golang.org/doc/faq#no_goroutine_id.

We only added that because sometimes the hub would be deadlocked and
having the goroutineID would be useful when getting the stack trace.
This is also problematic in stress tests because the hubs would
frequently get overloaded and the logs would unnecessarily have stack traces.

But that was in the past, and we have done extensive testing with
load tests and fuzz testing to smooth any rough edges remaining.
Including adding additional metrics for hub buffer size.

Monitoring the metrics is a better way to approach this problem.
Therefore, we remove these kludges from the code.

* Also remove deadlock checking code

There is no need for that anymore since
we are getting rid of the stack printing anyways.

Let's do a wholesale refactor and clean up the codebase.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-22 00:20:44 +05:30
George Goldberg
6cabc40e62 MM-23568: Add rudder to server diagnostics. (#14151)
* MM-23568: Add rudder to server diagnostics.

* Add unit test.

* Go mod tidy.

* CSP Header fix.

* Fix review comments.

* Update web/handlers.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* Partially address review comments.

* fix tests.

* Finish implementing review suggestions and then fixing tests.

* Fix CSP Header tests.

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
2020-04-21 09:23:00 +01:00
Carlos Tadeu Panato Junior
0d0ab51876 license: dropping PhoneNumber field from the license (#14307)
Per request of the bix team and checking the code this field is not used
in any place and also is one information that is not needed at all.
2020-04-20 14:20:35 +02:00
Jesse Hallam
4582823f87 fix /test command (#14169)
Automatic Merge
2020-04-18 00:08:57 -07:00
Farhan Munshi
e88ba85d60 [MM-23017] Add check for groups to SendNotifications (#14039)
* MM-23017 Check group mentions as part of notification logic

* Add nil groups to existing test cases

* MM-23017 Add tests for insertGroupMention and addGroupMention

* MM-23017 Add tests for getExplicitMentions that have groups

* Add tests for group store GetMemberUsersNotInChannel

* MM-23017 Add tests for AllowGroupMentions

* MM-23017 Fix error message name

* MM-23017 Swap Checks to Name

* MM-23017 Code review fixes

* Rename var and fix allowGroupMentions test

* MM-23017 Use GetMemberUsersInTeam inside of insertGroupMentions

* MM-23017 use group mentions permission

* Actually call GetMemberUsersInTeam

* Remove unnecessary new line

* Uncomment filter allow reference

* MM-23017 Fix group channel notifications

* Update store layer

* MM-23017 Improve test coverage for group channels

* Trigger CI

* Trigger CI
2020-04-17 19:22:54 -04:00
Eli Yukelzon
be7ee97dd3 MM-24094 EnableOpenTracing config setting missing from teleme… (#14298) 2020-04-16 20:17:46 +03:00
Jesús Espino
7ea637be10 MM-20934: Fixing int overflow in 32 bits on MaxImageSize check (#14280)
* MM-20934: Fixing int overflow in 32 bits on MaxImageSize check

* Adding comments explaining the casting and the bug fixed there

* Apply suggestions from code review

Co-Authored-By: Juho Nurminen <juhonurm@gmail.com>

* Fixing store layers

Co-authored-by: Juho Nurminen <juhonurm@gmail.com>
2020-04-16 15:23:27 +02:00
Doug Lauder
cd63c1153f MM-24096 add telemetry for audit log config (#14282)
* MM-24096 add telemetry for audit log config

* added audit config telemetry to unit test
2020-04-14 22:30:27 -04:00
Ibrahim Serdar Acikgoz
eb5b04c86a app/diagnostics: add telemetry for smtp_server_timeout (#14283)
Automatic Merge
2020-04-13 12:08:57 -07:00
catalintomai
b90f4f46e2 MM-23015: Enable or disable group mentions (#14010)
* MM-23015: Enable or disable group mentions + show them in suggestion list


Co-authored-by: Catalin Tomai <catalin.tomai@mattermost.com>
2020-04-13 11:37:29 -07:00
Agniva De Sarker
0bfb063c78 MM-24095: Add IdleTimeout to telemetry (#14279)
Automatic Merge
2020-04-13 11:08:57 -07:00
Martin Kraft
a9ea3587bb MM-23244: Validate that AuthData and AuthService fields are mutually inclusive. (#14175)
* MM-23244: Validate that either both or neither AuthData and AuthService fields are set.

* MM-23244: Readability improvement.

* MM-23244: Adds translation. Tests for error id.

* MM-23244: Fix test.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-09 18:51:27 -04:00
Mario de Frutos Dieguez
698b4b6934 [MM-23882] Include database server version in telemetry (#14258)
* Add database server version to telemetry

Also added a new query in the store to retrieve the database version

* Add test for the GetDbVersion function

* More drivers in the tests

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-09 11:08:15 +02:00
Jesús Espino
f6f025aeaa Adding guest accounts count telemetry (#14257)
* Adding guest accounts count telemetry

* Adding missed methods to the opentracing an timer layer
2020-04-09 11:05:43 +02:00
Eli Yukelzon
819f57037b fixed app-layer generator, re-enabled struct2interface in make… (#14260)
* fixed app-layer generator, re-enabled struct2interface in makefile
2020-04-09 11:08:39 +03:00
Agniva De Sarker
583daeb132 MM-23547: remove redundant JSON parsing in push notifications (#14181)
Automatic Merge
2020-04-08 08:38:57 -07:00
Doug Lauder
6a27ed4a1d MM-22785 audit server CLI (#14144)
Add auditing to server CLI.

Also:
- simplify auditing in API layer
- reduce number of AddMeta calls
- have models serialize themselves
- more consistent field naming
2020-04-08 00:52:30 -04:00
Agniva De Sarker
4210ae60ab MM-22056: Fix flaky test TestUploadFiles (#14234)
Automatic Merge
2020-04-07 07:09:04 -07:00
Martin Kraft
f92d3fa518 MM-23876: Fix for patching channel moderations with a null team schem… (#14239)
* MM-23876: Fix for patching channel moderations with a null team scheme channel guest role.

* MM-23876: Tests the moderations response.
2020-04-07 17:35:03 +05:30
Agniva De Sarker
6f6793e579 MM-22782: Write fuzz testing for websockets (#14203)
* MM-22782: Write fuzz testing for websockets

* Moved to fuzz function

* incorporate review comments

* Remove some more comments
2020-04-07 14:41:55 +05:30
Agniva De Sarker
ef209c5e0b MM-23620: Handle error from GetUser (#14204)
* MM-23620: Handle error from GetUser

In case of high DB load, the DB will start to throw errors.
Unless we handle the error appropriately, the server will crash.

* Removing unnecessary lines
2020-04-06 21:07:30 +05:30
Martin Kraft
19cf3e85b7 MM-23770: Fix for blank DefaultChannelGuestRole on team schemes. (#14210)
* MM-23770: Fix for blank DefaultChannelGuestRole on team schemes.

* MM-23770: Adds test for an team scheme with a blank DefaultChannelGuestRole field.

* MM-23770: Fix for unexpected Schemes.Get.
2020-04-02 08:09:23 -04:00
Eli Yukelzon
c0fc6c13d5 Opentracing layer generator improvement (#14206) 2020-04-02 11:33:43 +03:00
Michael Kochell
005cc00ccc [MM-23281] Persist registeredPlugin in plugin.Environment when plugin is deactivated (#14110)
* store failed timestamps on health check job instead of on registeredPlugin

Update test

* change EnsurePlugin calls

* Make env.SetPluginState private

* Write test for plugin deactivate and PluginStateFailedToStayRunning

* Add license comment

* adjust comments, use time.Since

* Additional PR feedback:

time.Since cleanup
test cleanup
remove duplicate .Store() call

* PR Feedback

- Add test case for reactivating the failed plugin
- Change `crashed` to `healthy` and `hasPluginCrashed` to `isPluginHealthy`
- remove stale timestamps from health check job

* Keep registeredPlugins in env when plugin is deactivated, so the crashed state of a plugin can be persisted.

* PR feedback

* PR feedback from Jesse

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-31 21:20:22 -03:00
Doug Lauder
8e5b626854 MM-23747 fix Sprintf linter errors (#14196)
- replace all instances of `fmt.Sprintf("whatever")` with simply "whatever".

- replace all instances of `fmt.Println(fmt.Sprintf("whatever %d", i))` with `fmt.Printf("whatever %d\n", i)`
2020-03-31 16:50:06 -04:00
Jesús Espino
07c1e76b02 Adding team_name to post props for channel mentions (#14150)
* Adding team_name to post props for channel mentions

* Fixing tests

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-31 15:25:53 +02:00
Farhan Munshi
ab338e8417 [MM-23019] Create use_group_mentions permission and migrate existing roles (#13987)
* MM-22962 Create use_group_mentions permission and give to all non guest roles that can create post

* Add use_group_mentions to team admin role for test

* Trigger CI

* MM-22962 Remove old migration keys
2020-03-30 23:08:48 -04:00
Jesse Hallam
f149ada16a MM-23261 plugin stderr debug logs (#14166)
* explicitly assert panic as error log

* Revert "[MM-18150] plugin panic trace should not be lost (#13559)"

This reverts commit 5d928b4f94, while leaving the unit tests intact
and now asserting debug logs instead.

* missing license header
2020-03-30 15:00:45 -03:00
Miguel de la Cruz
4fe25b1cdd [MM-21551] Add search tests structure to test the search engines (#14031)
* WIP

* Adding bleve to go modules

* WIP

* Adding missing files from searchengine implementation

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* User and channel indexing and searches implemented

* Make bleve tests run with in-memory indexes

* Implement post index and deletion tests

* Initial commits for the search layer

* Removing unnecesary indexing

* WIP

* WIP

* More fixes for tests

* Adding the search layer

* Finishing the migration of searchers to the layer

* Removing unnecesary code

* Allowing multiple engines active at the same time

* WIP

* Add simple post search

* Print information when using bleve

* Adding some debugging to understand better how the searches are working

* Making more dynamic config of search engines

* Add post search basics

* Adding the Purge API endpoint

* Fixing bleve config updates

* Adding missed file

* Regenerating search engine mocks

* Adding missed v5 to modules imports

* fixing i18n

* Fixing some test around search engine

* Removing all bleve traces

* Cleaning up the vendors directory and go.mod/go.sum files

* Regenerating timer layer

* Adding properly the license

* Fixing govet shadow error

* Fixing some tests

* Fixing TestSearchPostsFromUser

* Fixing another test

* Fixing more tests

* Fixing more tests

* Removing SearchEngine redundant text from searchengine module code

* Fixing some reindexing problems in members updates

* Fixing tests

* Addressing PR comments

* Reverting go.mod and go.sum

* Addressing PR comments

* Fixing tests compilation

* Fixing govet

* Adding search engine stop method

* Being more explicit on where we use includeDeleted

* Adding GetSqlSupplier test helper method

* Mocking elasticsearch start function

* Fixing tests

* Search tests

* Fix tests

* Fix mod

* Fixing searchEngine for test helpers with store mocks

* Remove loglines

* Fix i18n strings

* Migrate search posts tests

* Fix linter

* Do not run search tests if -short flag is enabled

* Migrate back store tests that didn't belong to the searchlayer

* Fix scopelint issues

Co-authored-by: Jesús Espino <jespinog@gmail.com>
2020-03-30 19:17:40 +02:00
Hossein Ahmadian-Yazdi
bd2c1f4522 [MM-21517] Team Member Manage User Modal not display correct roles (#14043)
* join on the users table and order by username

* don't inclue users who have been deleted

* Address PR comments

* update tests

* fix linting

* fix linting

* include ExcludeDeletedUsers flag

* fix gofmt

* fix nil teamMembersGetOptions

* fix gofmt error

* Add Unit Tests

* fix gofmt bugs

* partially address comments

* fix incorrect import

* Address Comments and fix golint errors

* store mocks

* address PR comments about tests and styling

* Update model/team_member.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* Address PR comments

* update client function name

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
2020-03-30 10:48:03 -04:00
Agniva De Sarker
7ce68e89d7 MM-22044: Fix panic on web_conn send hello (#13799)
* MM-22044: Fix panic on web_conn send hello

(*Hub).Start is the central place for sending all web connection
related traffic. However, there was this one call to (*WebConn).Hello
which tried to send a message to a webconn separately.

This was a rare case, but it did occur under stress conditions generated
from a load test.

When the websocket send SEND_QUEUE_SIZE would get filled up and we would
attempt to make a broadcast, the non-blocking send would close the Send
channel of the web connection. During that time, if a web connection
would try to perform a broadcast, it would try to send to a closed channel
and cause a panic.

The solution is to bring back the sending of hello into the same goroutine
inside (*Hub).Start so that all state is centralised and we avoid
sending to a closed channel by sending the hello message inside the registering
code itself.

* Adding non-blocking send

* Simplify things

* Remove test

* Bring sendHello back

* Improve code further

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-30 18:12:40 +05:30
Agniva De Sarker
b754fdb3e1 MM-23460: Reuse a single HTTP client across all push notifications (#14122)
Before this, for every single request we would create a new http.Client
from scratch. This was costly because every new client has internal
TCP connections which it reuses.

Therefore, originally, beyond a throughput of 800-1200 rps with a
concurrency of 50, beyond which it would run out of file descriptors.

Now it can support upto 8000-10000 rps.
An improvement by a factor of 10.

Throughput numbers:
BenchmarkPushNotification
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 11445.091601 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9190.761518 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 8334.394764 reqs/s
BenchmarkPushNotification-8   	     219	   5999304 ns/op	 3369224 B/op	   42127 allocs/op
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9590.399780 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9347.137463 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9053.784250 reqs/s
BenchmarkPushNotification-8   	     223	   5522636 ns/op	 3368470 B/op	   42034 allocs/op
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 10250.783365 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9123.292899 reqs/s
    BenchmarkPushNotification: notification_push_test.go:1478: throughput: 9173.553180 reqs/s

This is the aggregate count using benchstat.
The number is for a single run of sending 50 requests.

name                time/op
PushNotification-8  5.61ms ± 7%

name                alloc/op
PushNotification-8  3.36MB ± 1%

name                allocs/op
PushNotification-8   42.0k ± 1%

Tested on a machine with ulimit -n = 4096.
2020-03-28 09:33:38 +05:30
Jesús Espino
9a531fa0fb Removing some unneded FakeApp instance (#14139) 2020-03-27 14:52:57 +01:00
Jesús Espino
cfe65a33a5 Team/Channel members bulk save/update/delete (#14053)
* Members Save Multiple

* Multiple Channel Members implemented

* Working version with member multi save and multi update

* Adding tests to the save multiple team members store methods

* Tests passing for SaveMember

* Adding remove members tests

* Working on channel store tests

* More work on testing properly SaveMember and SaveMultipleMembers on channels

* More work on testing properly SaveMember and SaveMultipleMembers on teams

* Adding tests for update multiple members for team

* Adding tests for update multiple members for channel

* Fixing some tets

* Fixing tests

* Fixing tests

* Fixing i18n

* Addressing govet problems

* Addressing govet problems

* Addressing govet problems

* Addressing govet problems

* Addressing PR comments (and removing TODO)

* Addressing PR comments

* Fixed broken test

* Removing unnecesary i18n translation string
2020-03-27 13:29:17 +01:00