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

fix approval notification and phone check #3979

Merged
merged 2 commits into from
Jan 26, 2025
Merged
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 @@ -201,14 +201,17 @@ 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)
}
userID = util.GetStringFromPointer(userInfo.UserId)
} else {
userID = approval.DefaultApprovalInitiator.ID
formContent = fmt.Sprintf("审批发起人: %s\n%s", workflowCtx.WorkflowTaskCreatorUsername, formContent)
formContent = fmt.Sprintf("工作流执行人: %s\n%s", workflowCtx.WorkflowTaskCreatorUsername, formContent)
}
log.Infof("waitForLarkApprove: ApproveNodes num %d", len(approval.ApprovalNodes))
instance, err := client.CreateApprovalInstance(&lark.CreateApprovalInstanceArgs{
Expand Down Expand Up @@ -535,14 +538,17 @@ 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)
}
userID = userIDResp.UserID
} else {
userID = approval.DefaultApprovalInitiator.ID
formContent = fmt.Sprintf("审批发起人: %s\n%s", workflowCtx.WorkflowTaskCreatorUsername, formContent)
formContent = fmt.Sprintf("工作流执行人: %s\n%s", workflowCtx.WorkflowTaskCreatorUsername, formContent)
}

log.Infof("waitForDingTalkApprove: ApproveNode num %d", len(approval.ApprovalNodes))
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
Loading