mirror of https://github.com/harness/drone.git
feat: [CODE-2245] (Public Access) Enforce repo-review permission (#2522)
* updated permission with review wherever is neededpull/3545/head
parent
0952d00a31
commit
d2dcc9213b
|
@ -105,7 +105,7 @@ func (c *Controller) CommentCreate(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (c *Controller) CommentDelete(
|
|||
prNum int64,
|
||||
commentID int64,
|
||||
) error {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func (c *Controller) CommentStatus(
|
|||
commentID int64,
|
||||
in *CommentStatusInput,
|
||||
) (*types.PullReqActivity, error) {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func (c *Controller) CommentUpdate(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (c *Controller) FileViewAdd(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func (c *Controller) FileViewDelete(
|
|||
prNum int64,
|
||||
filePath string,
|
||||
) error {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (c *Controller) AssignLabel(
|
|||
pullreqNum int64,
|
||||
in *types.PullReqCreateInput,
|
||||
) (*types.PullReqLabel, error) {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to target repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (c *Controller) UnassignLabel(
|
|||
pullreqNum int64,
|
||||
labelID int64,
|
||||
) error {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to acquire access to target repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (c *Controller) ReviewSubmit(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func (c *Controller) ReviewerAdd(
|
|||
prNum int64,
|
||||
in *ReviewerAddInput,
|
||||
) (*types.PullReqReviewer, error) {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func (c *Controller) ReviewerAdd(
|
|||
if err = apiauth.CheckRepo(ctx, c.authorizer, &auth.Session{
|
||||
Principal: *reviewerPrincipal,
|
||||
Metadata: nil,
|
||||
}, repo, enum.PermissionRepoView); err != nil {
|
||||
}, repo, enum.PermissionRepoReview); err != nil {
|
||||
log.Ctx(ctx).Info().Msgf("Reviewer principal: %s access error: %s", reviewerInfo.UID, err)
|
||||
return nil, usererror.BadRequest("The reviewer doesn't have enough permissions for the repository.")
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func (c *Controller) ReviewerDelete(
|
|||
var reqPermission enum.Permission
|
||||
switch {
|
||||
case session.Principal.ID == reviewer.PrincipalID:
|
||||
reqPermission = enum.PermissionRepoView // Anybody should be allowed to remove their own reviews.
|
||||
reqPermission = enum.PermissionRepoReview // Anybody can remove their own reviews with RepoReview permission.
|
||||
case reviewer.ReviewDecision == enum.PullReqReviewDecisionPending:
|
||||
reqPermission = enum.PermissionRepoPush // The reviewer was asked for a review but didn't submit it yet.
|
||||
default:
|
||||
|
|
|
@ -48,7 +48,7 @@ func (c *Controller) DefineLabelValue(
|
|||
|
||||
permission := enum.PermissionRepoEdit
|
||||
if label.Type == enum.LabelTypeDynamic {
|
||||
permission = enum.PermissionRepoPush
|
||||
permission = enum.PermissionRepoReview
|
||||
}
|
||||
|
||||
if err = apiauth.CheckRepo(
|
||||
|
|
|
@ -42,7 +42,7 @@ func (c *Controller) Upload(ctx context.Context,
|
|||
file io.Reader,
|
||||
) (*Result, error) {
|
||||
// Permission check to see if the user in request has access to the repo.
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoView)
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue