GraphQL: Create dedicated top-level filter for sidebar categories (#20353)
We add the excludeTeam switch to allow user to get all sidebar categories from other teams excluding a given team. ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ade2271442
Коммит
bd6acf04a9
@@ -743,7 +743,8 @@ type AppIface interface {
|
||||
GetSharedChannelRemotesStatus(channelID string) ([]*model.SharedChannelRemoteStatus, error)
|
||||
GetSharedChannels(page int, perPage int, opts model.SharedChannelFilterOpts) ([]*model.SharedChannel, *model.AppError)
|
||||
GetSharedChannelsCount(opts model.SharedChannelFilterOpts) (int64, error)
|
||||
GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError)
|
||||
GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
|
||||
@@ -113,14 +113,14 @@ func TestHasPermissionToCategory(t *testing.T) {
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.GetSession(session.Token)
|
||||
require.Nil(t, err)
|
||||
require.True(t, th.App.SessionHasPermissionToCategory(*session, th.BasicUser.Id, th.BasicTeam.Id, categories.Order[0]))
|
||||
|
||||
categories2, err := th.App.GetSidebarCategories(th.BasicUser2.Id, th.BasicTeam.Id)
|
||||
categories2, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser2.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
require.False(t, th.App.SessionHasPermissionToCategory(*session, th.BasicUser.Id, th.BasicTeam.Id, categories2.Order[0]))
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
)
|
||||
|
||||
func (a *App) createInitialSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(userID, teamID)
|
||||
func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(userID, opts)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -22,12 +22,39 @@ func (a *App) createInitialSidebarCategories(userID, teamID string) (*model.Orde
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
func (a *App) GetSidebarCategoriesForTeamForUser(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userID, teamID)
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, teamID)
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
})
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetSidebarCategoriesForTeamForUser", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
var appErr *model.AppError
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userID, opts)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, opts)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Len(t, categories.Categories, 4)
|
||||
})
|
||||
@@ -113,7 +113,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
}, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, team.Id)
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, team.Id)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Len(t, categories.Categories, 3)
|
||||
})
|
||||
@@ -131,7 +131,7 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, appErr := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "app.channel.sidebar_categories.app_error", appErr.Id)
|
||||
@@ -143,7 +143,7 @@ func TestUpdateSidebarCategories(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
channelsCategory := categories.Categories[1]
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestMoveChannel(t *testing.T) {
|
||||
assert.Equal(t, []string{}, updatedCategory.Channels)
|
||||
|
||||
// And it should be on the new team instead
|
||||
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, targetTeam.Id)
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, targetTeam.Id)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
|
||||
assert.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
@@ -8951,7 +8951,7 @@ func (a *OpenTracingAppLayer) GetSharedChannelsCount(opts model.SharedChannelFil
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSidebarCategories(userID string, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSidebarCategories")
|
||||
|
||||
@@ -8963,7 +8963,29 @@ func (a *OpenTracingAppLayer) GetSidebarCategories(userID string, teamID string)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSidebarCategories(userID, teamID)
|
||||
resultVar0, resultVar1 := a.app.GetSidebarCategories(userID, opts)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSidebarCategoriesForTeamForUser(userID string, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSidebarCategoriesForTeamForUser")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
||||
@@ -493,7 +493,7 @@ func (api *PluginAPI) CreateChannelSidebarCategory(userID, teamID string, newCat
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetChannelSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
return api.app.GetSidebarCategories(userID, teamID)
|
||||
return api.app.GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateChannelSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
|
||||
@@ -804,7 +804,11 @@ func (a *App) JoinUserToTeam(c *request.Context, team *model.Team, user *model.U
|
||||
return nil, model.NewAppError("JoinUserToTeam", "app.user.update_update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := a.createInitialSidebarCategories(user.Id, team.Id); err != nil {
|
||||
opts := &store.SidebarCategorySearchOpts{
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
if _, err := a.createInitialSidebarCategories(user.Id, opts); err != nil {
|
||||
mlog.Warn(
|
||||
"Encountered an issue creating default sidebar categories.",
|
||||
mlog.String("user_id", user.Id),
|
||||
|
||||
@@ -185,7 +185,7 @@ func TestAddUserToTeam(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, team.Id, user.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
res, err := th.App.GetSidebarCategories(user.Id, team.Id)
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(user.Id, team.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
@@ -429,7 +429,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, user.Id, token.Token)
|
||||
require.Nil(t, err)
|
||||
|
||||
res, err := th.App.GetSidebarCategories(user.Id, team.Id)
|
||||
res, err := th.App.GetSidebarCategoriesForTeamForUser(user.Id, team.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, res.Categories, 3)
|
||||
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
|
||||
|
||||
Ссылка в новой задаче
Block a user