10000 feat(api): add checks for workflow groups by richardlt · Pull Request #6077 · ovh/cds · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(api): add checks for workflow groups #6077

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

Merged
merged 1 commit into from
Feb 9, 2022
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
8000 28 changes: 26 additions & 2 deletions engine/api/workflow_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,24 @@ func (api *API) putWorkflowGroupHandler() service.Handler {
return sdk.WrapError(sdk.ErrNotFound, "no permission found for group %q on workflow", gp.Group.Name)
}

g, err := group.LoadByName(ctx, api.mustDB(), gp.Group.Name, group.LoadOptions.WithOrganization)
g, err := group.LoadByName(ctx, api.mustDB(), gp.Group.Name, group.LoadOptions.WithOrganization, group.LoadOptions.WithMembers)
if err != nil {
return sdk.WrapError(err, "cannot load group with name %q", gp.Group.Name)
}
gp.Group = *g

if !isGroupAdmin(ctx, g) && gp.Permission > oldGp.Permission {
if isAdmin(ctx) {
trackSudo(ctx, w)
} else {
return sdk.WithStack(sdk.ErrInvalidGroupAdmin)
}
}

if group.IsDefaultGroupID(g.ID) && gp.Permission > sdk.PermissionRead {
return sdk.NewErrorFrom(sdk.ErrDefaultGroupPermission, "only read permission is allowed to default group")
}

tx, err := api.mustDB().Begin()
if err != nil {
return sdk.WrapError(err, "cannot start transaction")
Expand Down Expand Up @@ -164,12 +176,24 @@ func (api *API) postWorkflowGroupHandler() service.Handler {
}
}

g, err := group.LoadByName(ctx, api.mustDB(), gp.Group.Name, group.LoadOptions.WithOrganization)
g, err := group.LoadByName(ctx, api.mustDB(), gp.Group.Name, group.LoadOptions.WithOrganization, group.LoadOptions.WithMembers)
if err != nil {
return sdk.WrapError(err, "cannot load group with name %q", gp.Group.Name)
}
gp.Group = *g

if !isGroupAdmin(ctx, g) && gp.Permission > sdk.PermissionRead {
if isAdmin(ctx) {
trackSudo(ctx, w)
} else {
return sdk.WithStack(sdk.ErrInvalidGroupAdmin)
}
}

if group.IsDefaultGroupID(g.ID) && gp.Permission > sdk.PermissionRead {
return sdk.NewErrorFrom(sdk.ErrDefaultGroupPermission, "only read permission is allowed to default group")
}

tx, err := api.mustDB().Begin()
if err != nil {
return sdk.WrapError(err, "cannot start transaction")
Expand Down
Loading
0