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(api): return right error on add workflow group #4931

Merged
merged 1 commit into from
Feb 3, 2020
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
3 changes: 3 additions & 0 deletions engine/api/group/workflow_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func LoadRoleGroupInWorkflowNode(db gorp.SqlExecutor, nodeID, groupID int64) (in
func AddWorkflowGroup(ctx context.Context, db gorp.SqlExecutor, w *sdk.Workflow, gp sdk.GroupPermission) error {
link, err := LoadLinkGroupProjectForGroupIDAndProjectID(ctx, db, gp.Group.ID, w.ProjectID)
if err != nil {
if sdk.ErrorIs(err, sdk.ErrNotFound) {
return sdk.ErrGroupNotFoundInProject
}
return sdk.WrapError(err, "cannot load role for group %d in project %d", gp.Group.ID, w.ProjectID)
}
if link.Role == sdk.PermissionReadWriteExecute && gp.Permission < link.Role {
Expand Down
8 changes: 4 additions & 4 deletions engine/api/workflow_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (api *API) postWorkflowGroupHandler() service.Handler {

var gp sdk.GroupPermission
if err := service.UnmarshalBody(r, &gp); err != nil {
return sdk.WrapError(err, "postWorkflowGroupHandler")
return sdk.WrapError(err, "cannot unmarshal body")
}

proj, err := project.Load(api.mustDB(), api.Cache, key, project.LoadOptions.WithIntegrations)
Expand All @@ -151,19 +151,19 @@ func (api *API) postWorkflowGroupHandler() service.Handler {
options := workflow.LoadOptions{}
wf, err := workflow.Load(ctx, api.mustDB(), api.Cache, proj, name, options)
if err != nil {
return sdk.WrapError(err, "postWorkflowGroupHandler")
return sdk.WrapError(err, "cannot load workflow")
}

for _, gpr := range wf.Groups {
if gpr.Group.Name == gp.Group.Name {
return sdk.WrapError(sdk.ErrGroupPresent, "postWorkflowGroupHandler")
return sdk.WrapError(sdk.ErrGroupPresent, "group is already present")
}
}

if gp.Group.ID == 0 {
g, errG := group.LoadByName(ctx, api.mustDB(), gp.Group.Name)
if errG != nil {
return sdk.WrapError(errG, "postWorkflowGroupHandler")
return sdk.WrapError(errG, "cannot load group by name")
}
gp.Group = *g
}
Expand Down