Skip to content

Commit

Permalink
fix check approval initiator
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ committed Jan 24, 2025
1 parent adb945a commit 437e0ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ func waitForLarkApprove(ctx context.Context, spec *commonmodels.JobTaskApprovalS

var userID string
if approval.DefaultApprovalInitiator == nil {
if workflowCtx.WorkflowTaskCreatorMobile == "" {
return config.StatusFailed, errors.New("审批发起人手机号码未找到,请正确配置您的手机号码")
}
userInfo, err := client.GetUserIDByEmailOrMobile(lark.QueryTypeMobile, workflowCtx.WorkflowTaskCreatorMobile, setting.LarkUserOpenID)
if err != nil {
return config.StatusFailed, fmt.Errorf("get user lark id by mobile-%s, error: %s", workflowCtx.WorkflowTaskCreatorMobile, err)
Expand Down Expand Up @@ -535,6 +538,9 @@ func waitForDingTalkApprove(ctx context.Context, spec *commonmodels.JobTaskAppro

var userID string
if approval.DefaultApprovalInitiator == nil {
if workflowCtx.WorkflowTaskCreatorMobile == "" {
return config.StatusFailed, errors.New("审批发起人手机号码未找到,请正确配置您的手机号码")
}
userIDResp, err := client.GetUserIDByMobile(workflowCtx.WorkflowTaskCreatorMobile)
if err != nil {
return config.StatusFailed, fmt.Errorf("get user dingtalk id by mobile-%s error: %s", workflowCtx.WorkflowTaskCreatorMobile, err)
Expand Down
10 changes: 10 additions & 0 deletions pkg/microservice/aslan/core/release_plan/service/approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func createDingTalkApproval(approval *models.DingTalkApproval, manager, phone, c

var userID string
if approval.DefaultApprovalInitiator == nil {
if phone == "" {
return errors.New("审批发起人手机号码未找到,请正确配置您的手机号码")
}
userIDResp, err := client.GetUserIDByMobile(phone)
if err != nil {
return errors.Wrapf(err, "get user dingtalk id by mobile-%s", phone)
Expand Down Expand Up @@ -414,6 +417,10 @@ func createWorkWXApproval(approval *models.WorkWXApproval, manager, phone, conte
if approval.CreatorUser != nil {
applicant = approval.CreatorUser.ID
} else {
if phone == "" {
return errors.New("审批发起人手机号码未找到,请正确配置您的手机号码")
}

content = fmt.Sprintf("审批发起人: %s\n%s", manager, content)
phoneInt, err := strconv.Atoi(phone)
if err != nil {
Expand Down Expand Up @@ -477,6 +484,9 @@ func createLarkApproval(approval *models.LarkApproval, manager, phone, content s

var userID string
if approval.DefaultApprovalInitiator == nil {
if phone == "" {
return errors.New("审批发起人手机号码未找到,请正确配置您的手机号码")
}
userInfo, err := client.GetUserIDByEmailOrMobile(lark.QueryTypeMobile, phone, setting.LarkUserOpenID)
if err != nil {
return errors.Wrapf(err, "get user lark id by mobile-%s", phone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ func CheckWorkflowV4ApprovalInitiator(workflowName, uid string, log *zap.Sugared
return errors.New("failed to get user info by id")
}

if len(userInfo.Phone) == 0 {
return e.ErrCheckApprovalPhoneNotFound.AddDesc("phone not configured")
}

// If default approval initiator is not set, check whether the user's mobile phone number can be queried
// and only need to check once for each im app type
isMobileChecked := map[string]bool{}
Expand All @@ -362,6 +358,10 @@ func CheckWorkflowV4ApprovalInitiator(workflowName, uid string, log *zap.Sugared
}

if initiator := spec.LarkApproval.DefaultApprovalInitiator; initiator == nil {
if len(userInfo.Phone) == 0 {
return e.ErrCheckApprovalPhoneNotFound.AddDesc("phone not configured")
}

if isMobileChecked[spec.LarkApproval.ID] {
continue
}
Expand All @@ -382,6 +382,10 @@ func CheckWorkflowV4ApprovalInitiator(workflowName, uid string, log *zap.Sugared
}

if initiator := spec.DingTalkApproval.DefaultApprovalInitiator; initiator == nil {
if len(userInfo.Phone) == 0 {
return e.ErrCheckApprovalPhoneNotFound.AddDesc("phone not configured")
}

if isMobileChecked[spec.DingTalkApproval.ID] {
continue
}
Expand All @@ -403,6 +407,10 @@ func CheckWorkflowV4ApprovalInitiator(workflowName, uid string, log *zap.Sugared
}

if initiator := spec.WorkWXApproval.CreatorUser; initiator == nil {
if len(userInfo.Phone) == 0 {
return e.ErrCheckApprovalPhoneNotFound.AddDesc("phone not configured")
}

if isMobileChecked[spec.DingTalkApproval.ID] {
continue
}
Expand Down

0 comments on commit 437e0ee

Please sign in to comment.