Skip to content

Commit

Permalink
fix:task executor check
Browse files Browse the repository at this point in the history
  • Loading branch information
taolx0 committed Jul 28, 2023
1 parent 3af45c7 commit b3a7279
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
"database/sql"
e "errors"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -520,6 +521,31 @@ func GetNeedExecTaskIds(s *model.Storage, workflow *model.Workflow, user *model.
return needExecTaskIds, nil
}

func PrepareForTaskExecution(c echo.Context, projectName string, workflow *model.Workflow, user *model.User, TaskId int) error {
if workflow.Record.Status != model.WorkflowStatusWaitForExecution {
return errors.New(errors.DataInvalid, e.New("workflow need to be approved first"))
}

err := CheckCurrentUserCanOperateWorkflow(c, &model.Project{Name: projectName}, workflow, []uint{model.OP_WORKFLOW_EXECUTE})
if err != nil {
return err
}

for _, record := range workflow.Record.InstanceRecords {
if record.TaskId != uint(TaskId) {
continue
}

for _, u := range record.ExecutorUserList {
if u.ID == user.ID {
return nil
}
}
}

return e.New("you are not allow to execute the task")
}

func PrepareForWorkflowExecution(c echo.Context, projectName string, workflow *model.Workflow, user *model.User) error {
err := CheckCurrentUserCanOperateWorkflow(c, &model.Project{Name: projectName}, workflow, []uint{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func ExecuteOneTaskOnWorkflowV2(c echo.Context) error {
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
err = v1.PrepareForWorkflowExecution(c, projectName, workflow, user)
err = v1.PrepareForTaskExecution(c, projectName, workflow, user, taskId)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
Expand Down
2 changes: 1 addition & 1 deletion sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (s *Storage) getWorkflowStepsByRecordIds(ids []uint) ([]*WorkflowStep, erro

func (s *Storage) getWorkflowInstanceRecordsByRecordId(id uint) ([]*WorkflowInstanceRecord, error) {
instanceRecords := []*WorkflowInstanceRecord{}
err := s.db.Preload("Instance").Preload("Task").Where("workflow_record_id = ?", id).
err := s.db.Preload("Instance").Preload("Task").Preload("ExecutorUserList").Where("workflow_record_id = ?", id).
Find(&instanceRecords).Error
if err != nil {
return nil, errors.New(errors.ConnectStorageError, err)
Expand Down

0 comments on commit b3a7279

Please sign in to comment.