diff options
author | Martin Kraft <mkraft@users.noreply.github.com> | 2018-07-30 15:06:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-30 15:06:08 -0400 |
commit | 5872bf9c2f9b81c7aad761d40a6970f6267f1424 (patch) | |
tree | 2f850c0678f9fbd8979d41cb758503ca6cb1a2d7 /app/channel.go | |
parent | 65cd447a61efa852da2c0e7db25f385c2436e236 (diff) | |
download | chat-5872bf9c2f9b81c7aad761d40a6970f6267f1424.tar.gz chat-5872bf9c2f9b81c7aad761d40a6970f6267f1424.tar.bz2 chat-5872bf9c2f9b81c7aad761d40a6970f6267f1424.zip |
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
Diffstat (limited to 'app/channel.go')
-rw-r--r-- | app/channel.go | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/app/channel.go b/app/channel.go index 619cc09eb..830dbb8b7 100644 --- a/app/channel.go +++ b/app/channel.go @@ -393,7 +393,7 @@ func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest) } - channel, err := a.GetChannelByName(model.GetGroupNameFromUserIds(userIds), "") + channel, err := a.GetChannelByName(model.GetGroupNameFromUserIds(userIds), "", true) if err != nil { return nil, err } @@ -1011,16 +1011,26 @@ func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) { } } -func (a *App) GetChannelByName(channelName, teamId string) (*model.Channel, *model.AppError) { - if result := <-a.Srv.Store.Channel().GetByName(teamId, channelName, true); result.Err != nil && result.Err.Id == "store.sql_channel.get_by_name.missing.app_error" { +func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError) { + var result store.StoreResult + + if includeDeleted { + result = <-a.Srv.Store.Channel().GetByNameIncludeDeleted(teamId, channelName, false) + } else { + result = <-a.Srv.Store.Channel().GetByName(teamId, channelName, false) + } + + if result.Err != nil && result.Err.Id == "store.sql_channel.get_by_name.missing.app_error" { result.Err.StatusCode = http.StatusNotFound return nil, result.Err - } else if result.Err != nil { + } + + if result.Err != nil { result.Err.StatusCode = http.StatusBadRequest return nil, result.Err - } else { - return result.Data.(*model.Channel), nil } + + return result.Data.(*model.Channel), nil } func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model.Channel, *model.AppError) { @@ -1035,7 +1045,7 @@ func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model } } -func (a *App) GetChannelByNameForTeamName(channelName, teamName string) (*model.Channel, *model.AppError) { +func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError) { var team *model.Team if result := <-a.Srv.Store.Team().GetByName(teamName); result.Err != nil { @@ -1045,19 +1055,28 @@ func (a *App) GetChannelByNameForTeamName(channelName, teamName string) (*model. team = result.Data.(*model.Team) } - if result := <-a.Srv.Store.Channel().GetByName(team.Id, channelName, true); result.Err != nil && result.Err.Id == "store.sql_channel.get_by_name.missing.app_error" { + var result store.StoreResult + if includeDeleted { + result = <-a.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false) + } else { + result = <-a.Srv.Store.Channel().GetByName(team.Id, channelName, false) + } + + if result.Err != nil && result.Err.Id == "store.sql_channel.get_by_name.missing.app_error" { result.Err.StatusCode = http.StatusNotFound return nil, result.Err - } else if result.Err != nil { + } + + if result.Err != nil { result.Err.StatusCode = http.StatusBadRequest return nil, result.Err - } else { - return result.Data.(*model.Channel), nil } + + return result.Data.(*model.Channel), nil } -func (a *App) GetChannelsForUser(teamId string, userId string) (*model.ChannelList, *model.AppError) { - if result := <-a.Srv.Store.Channel().GetChannels(teamId, userId); result.Err != nil { +func (a *App) GetChannelsForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) { + if result := <-a.Srv.Store.Channel().GetChannels(teamId, userId, includeDeleted); result.Err != nil { return nil, result.Err } else { return result.Data.(*model.ChannelList), nil @@ -1494,7 +1513,9 @@ func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *mod } func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelList, *model.AppError) { - if result := <-a.Srv.Store.Channel().AutocompleteInTeam(teamId, term); result.Err != nil { + includeDeleted := *a.Config().TeamSettings.ViewArchivedChannels + + if result := <-a.Srv.Store.Channel().AutocompleteInTeam(teamId, term, includeDeleted); result.Err != nil { return nil, result.Err } else { return result.Data.(*model.ChannelList), nil @@ -1502,7 +1523,9 @@ func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelLi } func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) { - if result := <-a.Srv.Store.Channel().SearchInTeam(teamId, term); result.Err != nil { + includeDeleted := *a.Config().TeamSettings.ViewArchivedChannels + + if result := <-a.Srv.Store.Channel().SearchInTeam(teamId, term, includeDeleted); result.Err != nil { return nil, result.Err } else { return result.Data.(*model.ChannelList), nil |