From 5872bf9c2f9b81c7aad761d40a6970f6267f1424 Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Mon, 30 Jul 2018 15:06:08 -0400 Subject: Pr 9039 (#9187) * MM-11065: Allow to search and get archived channels from the API * Fixing more tests * Add some unit tests * Add includeDeleted parameter to session permissions check function * More test fixing * Adding archive channels list in channels search * Add restriction for archived channel edition * Reverting permissions checks modification * Changed the query parameter to include_deleted * Enable search archive channels as true by default * Adding tests for verify search on deleted channels * Allowing to override archive channels during the imports * Fixed test * Search in archive channels from the API must be explicitly requested * Removing includeDeleted parameter from GetChannelByName and GetChannelByNameForTeam * Back to ViewArchivedChannels config * Fixing tests * Reverting GetChannelByName parameter * Add include deleted parameter on GetChannel functions in plugins api * Fixing tests --- app/post.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/post.go') diff --git a/app/post.go b/app/post.go index 0344d8f0d..8c44436aa 100644 --- a/app/post.go +++ b/app/post.go @@ -638,8 +638,9 @@ func (a *App) DeletePostFiles(post *model.Post) { } } -func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostSearchResults, *model.AppError) { +func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool) (*model.PostSearchResults, *model.AppError) { paramsList := model.ParseSearchParams(terms) + includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ViewArchivedChannels esInterface := a.Elasticsearch if license := a.License(); esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && license != nil && *license.Features.Elasticsearch { @@ -651,7 +652,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr if params.Terms != "*" { // Convert channel names to channel IDs for idx, channelName := range params.InChannels { - if channel, err := a.GetChannelByName(channelName, teamId); err != nil { + if channel, err := a.GetChannelByName(channelName, teamId, includeDeleted); err != nil { mlog.Error(fmt.Sprint(err)) } else { params.InChannels[idx] = channel.Id @@ -677,7 +678,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr } // We only allow the user to search in channels they are a member of. - userChannels, err := a.GetChannelsForUser(teamId, userId) + userChannels, err := a.GetChannelsForUser(teamId, userId, includeDeleted) if err != nil { mlog.Error(fmt.Sprint(err)) return nil, err @@ -710,6 +711,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr channels := []store.StoreChannel{} for _, params := range paramsList { + params.IncludeDeletedChannels = includeDeleted params.OrTerms = isOrSearch // don't allow users to search for everything if params.Terms != "*" { -- cgit v1.2.3-1-g7c22