Merge branch 'master' into mark-as-unread

Этот коммит содержится в:
Harrison Healey
2019-11-12 14:20:50 -05:00
родитель 6e6174a9ee 0c8b580458
Коммит df7cbcb440
45 изменённых файлов: 1002 добавлений и 792 удалений

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

@@ -574,7 +574,9 @@ func CheckEtag(t *testing.T, data interface{}, resp *model.Response) {
func CheckNoError(t *testing.T, resp *model.Response) {
t.Helper()
require.Nil(t, resp.Error)
if resp.Error != nil {
require.FailNow(t, "Expected no error, got %q", resp.Error.Error())
}
}
func checkHTTPStatus(t *testing.T, resp *model.Response, expectedStatus int, expectError bool) {
@@ -637,8 +639,8 @@ func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
t.Helper()
require.NotNil(t, resp.Error)
require.Equal(t, resp.Error.Id, errorId, "incorrect error message")
require.NotNilf(t, resp.Error, "should have errored with message: %s", errorId)
require.Equalf(t, resp.Error.Id, errorId, "incorrect error message, actual: %s, expected: %s", resp.Error.Id, errorId)
}
func CheckStartsWith(t *testing.T, value, prefix, message string) {

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

@@ -27,6 +27,7 @@ func (api *API) InitChannel() {
api.BaseRoutes.ChannelsForTeam.Handle("/deleted", api.ApiSessionRequired(getDeletedChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/ids", api.ApiSessionRequired(getPublicChannelsByIdsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/search", api.ApiSessionRequired(searchChannelsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/search_archived", api.ApiSessionRequired(searchArchivedChannelsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/autocomplete", api.ApiSessionRequired(autocompleteChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/search_autocomplete", api.ApiSessionRequired(autocompleteChannelsForTeamForSearch)).Methods("GET")
api.BaseRoutes.User.Handle("/teams/{team_id:[A-Za-z0-9]+}/channels", api.ApiSessionRequired(getChannelsForTeamForUser)).Methods("GET")
@@ -681,12 +682,7 @@ func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Reques
return
}
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
return
}
channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage)
channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage, c.App.Session.UserId)
if err != nil {
c.Err = err
return
@@ -860,6 +856,42 @@ func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(channels.ToJson()))
}
func searchArchivedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {
return
}
props := model.ChannelSearchFromJson(r.Body)
if props == nil {
c.SetInvalidParam("channel_search")
return
}
var channels *model.ChannelList
var err *model.AppError
if c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session.UserId)
} else {
// If the user is not a team member, return a 404
if _, err = c.App.GetTeamMember(c.Params.TeamId, c.App.Session.UserId); err != nil {
c.Err = err
return
}
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session.UserId)
}
if err != nil {
c.Err = err
return
}
// Don't fill in channels props, since unused by client and potentially expensive.
w.Write([]byte(channels.ToJson()))
}
func searchAllChannels(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.ChannelSearchFromJson(r.Body)
if props == nil {

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

@@ -678,9 +678,6 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
Client := th.Client
team := th.BasicTeam
_, resp := Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckForbiddenStatus(t, resp)
th.LoginTeamAdmin()
channels, resp := Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
@@ -706,6 +703,31 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
t.Fatal("should be 2 deleted channels")
}
th.LoginBasic()
privateChannel1 := th.CreatePrivateChannel()
Client.DeleteChannel(privateChannel1.Id)
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
if len(channels) != numInitialChannelsForTeam+3 {
t.Fatal("should be 3 deleted channels")
}
// Login as different user and create private channel
th.LoginBasic2()
privateChannel2 := th.CreatePrivateChannel()
Client.DeleteChannel(privateChannel2.Id)
// Log back in as first user
th.LoginBasic()
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
if len(channels) != numInitialChannelsForTeam+3 {
t.Fatal("should still be 3 deleted channels", len(channels), numInitialChannelsForTeam+3)
}
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 1, "")
CheckNoError(t, resp)
if len(channels) != 1 {
@@ -1060,6 +1082,100 @@ func TestSearchChannels(t *testing.T) {
})
}
func TestSearchArchivedChannels(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
search := &model.ChannelSearch{Term: th.BasicChannel.Name}
Client.DeleteChannel(th.BasicChannel.Id)
channels, resp := Client.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
found := false
for _, c := range channels {
if c.Type != model.CHANNEL_OPEN {
t.Fatal("should only return public channels")
}
if c.Id == th.BasicChannel.Id {
found = true
}
}
if !found {
t.Fatal("didn't find channel")
}
search.Term = th.BasicPrivateChannel.Name
Client.DeleteChannel(th.BasicPrivateChannel.Id)
channels, resp = Client.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
found = false
for _, c := range channels {
if c.Id == th.BasicPrivateChannel.Id {
found = true
}
}
if !found {
t.Fatal("couldn't find private channel")
}
search.Term = ""
_, resp = Client.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
search.Term = th.BasicDeletedChannel.Name
_, resp = Client.SearchArchivedChannels(model.NewId(), search)
CheckNotFoundStatus(t, resp)
_, resp = Client.SearchArchivedChannels("junk", search)
CheckBadRequestStatus(t, resp)
_, resp = th.SystemAdminClient.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
// Check the appropriate permissions are enforced.
defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
// Remove list channels permission from the user
th.RemovePermissionFromRole(model.PERMISSION_LIST_TEAM_CHANNELS.Id, model.TEAM_USER_ROLE_ID)
t.Run("Search for a BasicDeletedChannel, which the user is a member of", func(t *testing.T) {
search.Term = th.BasicDeletedChannel.Name
channelList, resp := Client.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
channelNames := []string{}
for _, c := range channelList {
channelNames = append(channelNames, c.Name)
}
require.Contains(t, channelNames, th.BasicDeletedChannel.Name)
})
t.Run("Remove the user from BasicDeletedChannel and search again, should still return", func(t *testing.T) {
th.App.RemoveUserFromChannel(th.BasicUser.Id, th.BasicUser.Id, th.BasicDeletedChannel)
search.Term = th.BasicDeletedChannel.Name
channelList, resp := Client.SearchArchivedChannels(th.BasicTeam.Id, search)
CheckNoError(t, resp)
channelNames := []string{}
for _, c := range channelList {
channelNames = append(channelNames, c.Name)
}
require.Contains(t, channelNames, th.BasicDeletedChannel.Name)
})
}
func TestSearchAllChannels(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@@ -86,7 +86,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
user.SanitizeInput()
user.SanitizeInput(c.IsSystemAdmin())
tokenId := r.URL.Query().Get("t")
inviteId := r.URL.Query().Get("iid")

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

@@ -110,10 +110,15 @@ func TestCreateUserInputFilter(t *testing.T) {
_, resp := th.SystemAdminClient.CreateUser(user)
CheckBadRequestStatus(t, resp)
})
t.Run("AuthServiceFilter", func(t *testing.T) {
user := &model.User{Email: "foobar+testdomainrestriction@mattermost.org", Password: "Password1", Username: GenerateTestUsername(), AuthService: "ldap"}
t.Run("ValidAuthServiceFilter", func(t *testing.T) {
user := &model.User{Email: "foobar+testdomainrestriction@mattermost.org", Username: GenerateTestUsername(), AuthService: "ldap", AuthData: model.NewString("999099")}
_, resp := th.SystemAdminClient.CreateUser(user)
CheckNoError(t, resp)
})
t.Run("InvalidAuthServiceFilter", func(t *testing.T) {
user := &model.User{Email: "foobar+testdomainrestriction@mattermost.org", Password: "Password1", Username: GenerateTestUsername(), AuthService: "ldap"}
_, resp := th.Client.CreateUser(user)
CheckBadRequestStatus(t, resp)
})
})