Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support view workflow task parameters #3939

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ func CloneSprintWorkItemTask(ctx *handler.Context, workitemTaskID string) (*Clon
}
resp.SprintWorkItemIDs = task.SprintWorkItemIDs

workflow, err := workflowservice.CloneWorkflowTaskV4(task.WorkflowName, task.WorkflowTaskID, ctx.Logger)
workflow, err := workflowservice.CloneWorkflowTaskV4(task.WorkflowName, task.WorkflowTaskID, false, ctx.Logger)
if err != nil {
return nil, e.ErrCloneSprintWorkItemTask.AddErr(errors.Wrapf(err, "Clone workflow task %s/%d", task.WorkflowName, task.WorkflowTaskID))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/microservice/aslan/core/workflow/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (*Router) Inject(router *gin.RouterGroup) {
taskV4.GET("/workflow/:workflowName/task/:taskID", GetWorkflowTaskV4)
taskV4.DELETE("/workflow/:workflowName/task/:taskID", CancelWorkflowTaskV4)
taskV4.GET("/clone/workflow/:workflowName/task/:taskID", CloneWorkflowTaskV4)
taskV4.GET("/view/workflow/:workflowName/task/:taskID", ViewWorkflowTaskV4)
taskV4.POST("/retry/workflow/:workflowName/task/:taskID", RetryWorkflowTaskV4)
taskV4.POST("/manualexec/workflow/:workflowName/task/:taskID", ManualExecWorkflowTaskV4)
taskV4.GET("/manualexec/workflow/:workflowName/task/:taskID", GetManualExecWorkflowTaskV4Info)
Expand Down
42 changes: 41 additions & 1 deletion pkg/microservice/aslan/core/workflow/handler/workflow_task_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,47 @@ func CloneWorkflowTaskV4(c *gin.Context) {
}
}

ctx.Resp, ctx.RespErr = workflow.CloneWorkflowTaskV4(workflowName, taskID, ctx.Logger)
ctx.Resp, ctx.RespErr = workflow.CloneWorkflowTaskV4(workflowName, taskID, false, ctx.Logger)
}

func ViewWorkflowTaskV4(c *gin.Context) {
ctx, err := internalhandler.NewContextWithAuthorization(c)
defer func() { internalhandler.JSONResponse(c, ctx) }()

if err != nil {
ctx.RespErr = fmt.Errorf("authorization Info Generation failed: err %s", err)
ctx.UnAuthorized = true
return
}

projectKey := c.Query("projectName")
workflowName := c.Param("workflowName")

taskID, err := strconv.ParseInt(c.Param("taskID"), 10, 64)
if err != nil {
ctx.RespErr = e.ErrInvalidParam.AddDesc("invalid task id")
return
}

// authorization check
if !ctx.Resources.IsSystemAdmin {
if _, ok := ctx.Resources.ProjectAuthInfo[projectKey]; !ok {
ctx.UnAuthorized = true
return
}

if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Workflow.View {
// check if the permission is given by collaboration mode
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeWorkflow, workflowName, types.WorkflowActionView)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

ctx.Resp, ctx.RespErr = workflow.CloneWorkflowTaskV4(workflowName, taskID, true, ctx.Logger)
}

func GetManualExecWorkflowTaskV4Info(c *gin.Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,14 @@ func GetManualExecWorkflowTaskV4Info(workflowName string, taskID int64, logger *
return task.OriginWorkflowArgs, nil
}

func CloneWorkflowTaskV4(workflowName string, taskID int64, logger *zap.SugaredLogger) (*commonmodels.WorkflowV4, error) {
func CloneWorkflowTaskV4(workflowName string, taskID int64, isView bool, logger *zap.SugaredLogger) (*commonmodels.WorkflowV4, error) {
originalWorkflow, err := commonrepo.NewWorkflowV4Coll().Find(workflowName)
if err != nil {
logger.Errorf("find workflowV4 error: %s", err)
return nil, e.ErrFindWorkflow.AddErr(err)
}

if originalWorkflow.EnableApprovalTicket {
if originalWorkflow.EnableApprovalTicket && !isView {
return nil, e.ErrCloneTask.AddDesc("无法克隆开启了预审批的工作流")
}

Expand Down
Loading