[MM-7968] restrict creation of direct channels to team members (#17222)

* restrict creation of direct channels to team members

* run make i18n-extract

* add suggestions from hahmadia

* place common-team-check logic in app layer

* use flat SQL query

* show more specific error message to user

* MM-7968: Fmt file.

* MM-7968: Fix for moved session field.

Co-authored-by: Max Erenberg <max.erenberg@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Martin Kraft <martinkraft@gmail.com>
Co-authored-by: Martin Kraft <martin@upspin.org>
Этот коммит содержится в:
Max Erenberg
2021-05-19 08:45:03 -04:00
коммит произвёл GitHub
родитель 3681cd3688
Коммит 9ef41a55e2
13 изменённых файлов: 175 добавлений и 4 удалений

Просмотреть файл

@@ -418,12 +418,24 @@ func TestCreateDirectChannel(t *testing.T) {
require.NotNil(t, err)
require.Equal(t, http.StatusBadRequest, r.StatusCode)
_, resp = th.SystemAdminClient.CreateDirectChannel(user3.Id, user2.Id)
CheckNoError(t, resp)
// Normal client should not be allowed to create a direct channel if users are
// restricted to messaging members of their own team
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.RestrictDirectMessage = model.DIRECT_MESSAGE_TEAM
})
user4 := th.CreateUser()
_, resp = th.Client.CreateDirectChannel(user1.Id, user4.Id)
CheckForbiddenStatus(t, resp)
th.LinkUserToTeam(user4, th.BasicTeam)
_, resp = th.Client.CreateDirectChannel(user1.Id, user4.Id)
CheckNoError(t, resp)
Client.Logout()
_, resp = Client.CreateDirectChannel(model.NewId(), user2.Id)
CheckUnauthorizedStatus(t, resp)
_, resp = th.SystemAdminClient.CreateDirectChannel(user3.Id, user2.Id)
CheckNoError(t, resp)
}
func TestCreateDirectChannelAsGuest(t *testing.T) {