Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: allow project developer to merge self branch to main branch (#12100)

h3n4l3322713c2c31
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index e27f741998..c1a3d19781 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -391,18 +391,6 @@ func (s *BranchService) MergeBranch(ctx context.Context, request *v1pb.MergeBran
if !ok {
return nil, status.Errorf(codes.Internal, "user not found")
}
- ok, err = func() (bool, error) {
- if baseBranch.CreatorID == user.ID {
- return true, nil
- }
- return s.iamManager.CheckPermission(ctx, iam.PermissionBranchesUpdate, user, project.ResourceID)
- }()
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to check permission, error: %v", err)
- }
- if !ok {
- return nil, status.Errorf(codes.PermissionDenied, "permission denied to merge branch")
- }
headProjectID, headBranchID, err := common.GetProjectAndBranchID(request.HeadBranch)
if err != nil {
@@ -427,6 +415,22 @@ func (s *BranchService) MergeBranch(ctx context.Context, request *v1pb.MergeBran
return nil, status.Errorf(codes.NotFound, "branch %q not found", headBranchID)
}
+ ok, err = func() (bool, error) {
+ if baseBranch.CreatorID == user.ID {
+ return true, nil
+ }
+ if headBranch.CreatorID == user.ID {
+ return true, nil
+ }
+ return s.iamManager.CheckPermission(ctx, iam.PermissionBranchesUpdate, user, project.ResourceID)
+ }()
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to check permission, error: %v", err)
+ }
+ if !ok {
+ return nil, status.Errorf(codes.PermissionDenied, "permission denied to merge branch")
+ }
+
// Restrict merging only when the head branch is not updated.
// Maybe we can support auto-merging in the future.