feat: [CODE-1132]: dryrun requires view permission (#819)

rkapoor10-patch-1
Marko Gacesa 2023-11-22 22:38:44 +00:00 committed by Harness
parent e162112a29
commit 3d97474dcf
2 changed files with 12 additions and 2 deletions

View File

@ -86,7 +86,12 @@ func (c *Controller) Merge(
return nil, nil, err
}
targetRepo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush)
requiredPermission := enum.PermissionRepoPush
if in.DryRun {
requiredPermission = enum.PermissionRepoView
}
targetRepo, err := c.getRepoCheckAccess(ctx, session, repoRef, requiredPermission)
if err != nil {
return nil, nil, fmt.Errorf("failed to acquire access to target repo: %w", err)
}

View File

@ -61,7 +61,12 @@ func (c *Controller) CommitFiles(ctx context.Context,
repoRef string,
in *CommitFilesOptions,
) (types.CommitFilesResponse, []types.RuleViolations, error) {
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush, false)
requiredPermission := enum.PermissionRepoPush
if in.DryRunRules {
requiredPermission = enum.PermissionRepoView
}
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, requiredPermission, false)
if err != nil {
return types.CommitFilesResponse{}, nil, err
}