Skip to content

Commit

Permalink
validate role actions on resource for updates (#230)
Browse files Browse the repository at this point in the history
Validate role actions on the resource not the role type when updating a
role.

Signed-off-by: Mike Mason <[email protected]>
  • Loading branch information
mikemrm authored Mar 18, 2024
1 parent 8c2f94f commit 3b579d3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/query/relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ func (e *engine) UpdateRole(ctx context.Context, actor, roleResource types.Resou

defer span.End()

if err := e.validateResourceActions(roleResource, newActions...); err != nil {
return types.Role{}, err
}

dbCtx, err := e.store.BeginContext(ctx)
if err != nil {
return types.Role{}, err
Expand All @@ -433,6 +429,20 @@ func (e *engine) UpdateRole(ctx context.Context, actor, roleResource types.Resou
return types.Role{}, err
}

res, err := e.NewResourceFromID(role.ResourceID)
if err != nil {
logRollbackErr(e.logger, e.store.RollbackContext(dbCtx))

return types.Role{}, err
}

// Validate actions against role resource
if err := e.validateResourceActions(res, newActions...); err != nil {
logRollbackErr(e.logger, e.store.RollbackContext(dbCtx))

return types.Role{}, err
}

newName = strings.TrimSpace(newName)

if newName == "" {
Expand Down

0 comments on commit 3b579d3

Please sign in to comment.