MM-51482_Create Apps Category and link to bots DM (#22918)

Этот коммит содержится в:
Julian Mondragón
2023-04-27 19:44:14 -05:00
коммит произвёл GitHub
родитель 13f1d0fdc5
Коммит 1051925eec
17 изменённых файлов: 3650 добавлений и 113 удалений

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

@@ -25,13 +25,17 @@ func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarC
func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
var appErr *model.AppError
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, &store.SidebarCategorySearchOpts{
TeamID: teamID,
ExcludeTeam: false,
})
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
options := &store.SidebarCategorySearchOpts{
TeamID: teamID,
ExcludeTeam: false,
AppsCategoryEnabled: appsCategoryEnabled,
}
categories, err := a.Srv().Store().Channel().GetSidebarCategoriesForTeamForUser(userID, teamID, options)
if err == nil && (len(categories.Categories) == 0 || (appsCategoryEnabled && checkMissingSystemSidebarCategories(categories))) {
// A user must always have system categories, so migration must not have happened yet, and we should run it ourselves
categories, appErr = a.createInitialSidebarCategories(userID, options)
if appErr != nil {
return nil, appErr
}
@@ -52,10 +56,17 @@ func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID s
func (a *App) GetSidebarCategories(c request.CTX, 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)
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
options := &store.SidebarCategorySearchOpts{
TeamID: opts.TeamID,
ExcludeTeam: opts.ExcludeTeam,
AppsCategoryEnabled: appsCategoryEnabled,
}
categories, err := a.Srv().Store().Channel().GetSidebarCategories(userID, options)
if err == nil && (len(categories.Categories) == 0 || (appsCategoryEnabled && checkMissingSystemSidebarCategories(categories))) {
// A user must always have system categories, so migration must not have happened yet, and we should run it ourselves
categories, appErr = a.createInitialSidebarCategories(userID, options)
if appErr != nil {
return nil, appErr
}
@@ -90,7 +101,8 @@ func (a *App) GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]s
}
func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
category, err := a.Srv().Store().Channel().GetSidebarCategory(categoryId)
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
category, err := a.Srv().Store().Channel().GetSidebarCategory(categoryId, &store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled})
if err != nil {
var nfErr *store.ErrNotFound
switch {
@@ -105,7 +117,8 @@ func (a *App) GetSidebarCategory(c request.CTX, categoryId string) (*model.Sideb
}
func (a *App) CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
category, err := a.Srv().Store().Channel().CreateSidebarCategory(userID, teamID, newCategory)
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
category, err := a.Srv().Store().Channel().CreateSidebarCategory(userID, teamID, newCategory, &store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled})
if err != nil {
var nfErr *store.ErrNotFound
switch {
@@ -142,7 +155,13 @@ func (a *App) UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, c
}
func (a *App) UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
updatedCategories, originalCategories, err := a.Srv().Store().Channel().UpdateSidebarCategories(userID, teamID, categories)
appsCategoryEnabled := a.Config().FeatureFlags.AppsSidebarCategory
updatedCategories, originalCategories, err := a.Srv().Store().Channel().UpdateSidebarCategories(
userID,
teamID,
categories,
&store.SidebarCategorySearchOpts{AppsCategoryEnabled: appsCategoryEnabled},
)
if err != nil {
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@@ -286,3 +305,17 @@ func (a *App) DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId st
return nil
}
func checkMissingSystemSidebarCategories(categories *model.OrderedSidebarCategories) bool {
missingSystemCategories := make(map[model.SidebarCategoryType]struct{})
for _, systemSidebarCategory := range model.SystemSidebarCategories {
missingSystemCategories[systemSidebarCategory] = struct{}{}
}
for _, category := range categories.Categories {
delete(missingSystemCategories, category.Type)
}
return len(missingSystemCategories) != 0
}