Skip to content

Commit

Permalink
fix(api): fix permission coherence (close #4035) (#4044)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj authored and richardlt committed Mar 19, 2019
1 parent 030343c commit 7b5b7b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions engine/api/group/node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func LoadGroupsByNode(db gorp.SqlExecutor, nodeID int64) ([]sdk.GroupPermission,
rows, err := db.Query(query, nodeID)
if err != nil {
if err == sql.ErrNoRows {
return nil, err
return nil, nil
}
return nil, err
return nil, sdk.WithStack(err)
}
defer rows.Close()

Expand All @@ -32,7 +32,7 @@ func LoadGroupsByNode(db gorp.SqlExecutor, nodeID int64) ([]sdk.GroupPermission,
var group sdk.Group
var perm int
if err := rows.Scan(&group.ID, &group.Name, &perm); err != nil {
return groups, err
return groups, sdk.WithStack(err)
}
groups = append(groups, sdk.GroupPermission{
Group: group,
Expand Down
9 changes: 9 additions & 0 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ func (w *Workflow) PostGet(db gorp.SqlExecutor) error {
w.WorkflowData = data
}

nodes := w.WorkflowData.Array()
for i := range nodes {
var err error
nodes[i].Groups, err = group.LoadGroupsByNode(db, nodes[i].ID)
if err != nil {
return sdk.WrapError(err, "cannot load node groups")
}
}

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions engine/api/workflow_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ func (api *API) deleteWorkflowGroupHandler() service.Handler {
key := vars["key"]
name := vars["permWorkflowName"]
groupName := vars["groupName"]
u := deprecatedGetUser(ctx)

proj, err := project.Load(api.mustDB(), api.Cache, key, deprecatedGetUser(ctx), project.LoadOptions.WithIntegrations)
proj, err := project.Load(api.mustDB(), api.Cache, key, u, project.LoadOptions.WithIntegrations)
if err != nil {
return sdk.WrapError(err, "unable to load projet")
}

options := workflow.LoadOptions{
WithoutNode: true,
}
wf, err := workflow.Load(ctx, api.mustDB(), api.Cache, proj, name, deprecatedGetUser(ctx), options)
wf, err := workflow.Load(ctx, api.mustDB(), api.Cache, proj, name, u, options)
if err != nil {
return sdk.WrapError(err, "deleteWorkflowGroupHandler")
}
Expand Down

0 comments on commit 7b5b7b6

Please sign in to comment.