From 2a6c6866999b1f9b9b3504f1deb377be74217c0c Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Fri, 1 Nov 2024 09:31:57 +0800 Subject: [PATCH] update 320 ua Signed-off-by: Patrick Zhao --- pkg/cli/initconfig/cmd/init.go | 5 ---- pkg/cli/upgradeassistant/cmd/migrate/320.go | 23 +++++++++++++++++++ .../core/sprint_management/service/sprint.go | 17 -------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pkg/cli/initconfig/cmd/init.go b/pkg/cli/initconfig/cmd/init.go index ef350a3b55..d42efbd100 100644 --- a/pkg/cli/initconfig/cmd/init.go +++ b/pkg/cli/initconfig/cmd/init.go @@ -32,11 +32,9 @@ import ( "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" vmcommonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/vm" statrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/stat/repository/mongodb" - "github.com/koderover/zadig/v2/pkg/shared/handler" systemrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/system/repository/mongodb" systemservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/system/service" templateservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/templatestore/service" - sprintservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/sprint_management/service" workflowservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow" configmongodb "github.com/koderover/zadig/v2/pkg/microservice/systemconfig/core/email/repository/mongodb" userdb "github.com/koderover/zadig/v2/pkg/microservice/user/core/repository/mongodb" @@ -254,9 +252,6 @@ func initSystemData() error { templateservice.InitWorkflowTemplate() - ctx := handler.NewBackgroupContext() - sprintservice.InitAllProjectSprintTemplate(ctx) - // update offical plugins workflowservice.UpdateOfficalPluginRepository(log.SugaredLogger()) diff --git a/pkg/cli/upgradeassistant/cmd/migrate/320.go b/pkg/cli/upgradeassistant/cmd/migrate/320.go index 1998c66049..59664ed351 100644 --- a/pkg/cli/upgradeassistant/cmd/migrate/320.go +++ b/pkg/cli/upgradeassistant/cmd/migrate/320.go @@ -23,6 +23,8 @@ import ( "gorm.io/gorm" "github.com/koderover/zadig/v2/pkg/cli/upgradeassistant/internal/upgradepath" + templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" + sprintservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/sprint_management/service" "github.com/koderover/zadig/v2/pkg/microservice/user/core/repository" usermodels "github.com/koderover/zadig/v2/pkg/microservice/user/core/repository/models" "github.com/koderover/zadig/v2/pkg/shared/handler" @@ -36,6 +38,12 @@ func init() { func V310ToV320() error { ctx := handler.NewBackgroupContext() ctx.Logger.Infof("-------- start init existed project's sprint template --------") + if err := initAllProjectSprintTemplate(ctx); err != nil { + ctx.Logger.Errorf("failed to init existed project's sprint template, error: %s", err) + return err + } + + ctx.Logger.Infof("-------- start add get_sprint action for read-only role --------") if err := addGetSprintActionForReadOnlyRole(ctx); err != nil { ctx.Logger.Errorf("failed to add get_sprint action for read-only role, error: %s", err) return err @@ -48,6 +56,21 @@ func V320ToV310() error { return nil } +func initAllProjectSprintTemplate(ctx *handler.Context) error { + projects, err := templaterepo.NewProductColl().List() + if err != nil { + err = fmt.Errorf("failed to list project list, error: %s", err) + ctx.Logger.Error(err) + return err + } + + for _, project := range projects { + sprintservice.InitSprintTemplate(ctx, project.ProductName) + } + + return nil +} + func addGetSprintActionForReadOnlyRole(ctx *handler.Context) error { action := &usermodels.Action{} err := repository.DB.Where("action = ? AND resource = ?", "get_sprint", "SprintManagement").First(&action).Error diff --git a/pkg/microservice/aslan/core/sprint_management/service/sprint.go b/pkg/microservice/aslan/core/sprint_management/service/sprint.go index d25c74fa6d..d69ad03ea7 100644 --- a/pkg/microservice/aslan/core/sprint_management/service/sprint.go +++ b/pkg/microservice/aslan/core/sprint_management/service/sprint.go @@ -17,7 +17,6 @@ package service import ( - "fmt" "time" "github.com/pkg/errors" @@ -26,7 +25,6 @@ import ( "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" - templaterepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template" "github.com/koderover/zadig/v2/pkg/shared/handler" e "github.com/koderover/zadig/v2/pkg/tool/errors" "github.com/koderover/zadig/v2/pkg/types" @@ -355,18 +353,3 @@ func ListSprint(ctx *handler.Context, opt *ListSprintOption) (*ListSprintResp, e Total: total, }, nil } - -func InitAllProjectSprintTemplate(ctx *handler.Context) { - projects, err := templaterepo.NewProductColl().List() - if err != nil { - err = fmt.Errorf("failed to list project list, error: %s", err) - ctx.Logger.Error(err) - return - } - - for _, project := range projects { - InitSprintTemplate(ctx, project.ProductName) - } - - return -}