Skip to content

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

feat: allow creators to update/delete changelist (#10354)

p0nya6002f781735
diff --git a/backend/api/v1/acl_iam.go b/backend/api/v1/acl_iam.go
index 2d9436f716..55bbb133c1 100644
--- a/backend/api/v1/acl_iam.go
+++ b/backend/api/v1/acl_iam.go
@@ -135,9 +135,7 @@ func (in *ACLInterceptor) checkIAMPermission(ctx context.Context, fullMethod str
projectIDsGetter = in.getProjectIDsForIssueService
case
v1pb.ChangelistService_CreateChangelist_FullMethodName,
- v1pb.ChangelistService_UpdateChangelist_FullMethodName,
- v1pb.ChangelistService_GetChangelist_FullMethodName,
- v1pb.ChangelistService_DeleteChangelist_FullMethodName:
+ v1pb.ChangelistService_GetChangelist_FullMethodName:
projectIDsGetter = in.getProjectIDsForChangelistService
case
@@ -264,6 +262,11 @@ func isSkippedMethod(fullMethod string) bool {
case
v1pb.IssueService_GetIssue_FullMethodName:
return true
+ // handled in the method because we need to consider changelist.Creator.
+ case
+ v1pb.ChangelistService_UpdateChangelist_FullMethodName,
+ v1pb.ChangelistService_DeleteChangelist_FullMethodName:
+ return true
// handled in the method because we need to consider issue.Creator.
case
v1pb.IssueService_UpdateIssue_FullMethodName,
@@ -334,12 +337,8 @@ func (*ACLInterceptor) getProjectIDsForChangelistService(_ context.Context, req
switch r := req.(type) {
case *v1pb.CreateChangelistRequest:
projects = append(projects, r.GetParent())
- case *v1pb.UpdateChangelistRequest:
- changelists = append(changelists, r.GetChangelist().GetName())
case *v1pb.GetChangelistRequest:
changelists = append(changelists, r.GetName())
- case *v1pb.DeleteChangelistRequest:
- changelists = append(changelists, r.GetName())
}
var projectIDs []string
diff --git a/backend/api/v1/changelist_service.go b/backend/api/v1/changelist_service.go
index e2c3274c22..43bbdc0717 100644
--- a/backend/api/v1/changelist_service.go
+++ b/backend/api/v1/changelist_service.go
@@ -201,12 +201,28 @@ func (s *ChangelistService) UpdateChangelist(ctx context.Context, request *v1pb.
return nil, status.Errorf(codes.NotFound, "changelist %q not found", changelistID)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
+ return nil, status.Errorf(codes.Internal, "user not found")
+ }
+
+ if s.profile.DevelopmentIAM {
+ ok, err := func() (bool, error) {
+ if changelist.CreatorID == user.ID {
+ return true, nil
+ }
+ return s.iamManager.CheckPermission(ctx, iam.PermissionChangelistsUpdate, 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 update changelist")
+ }
}
+
update := &store.UpdateChangelistMessage{
- UpdaterID: principalID,
+ UpdaterID: user.ID,
ProjectID: project.ResourceID,
ResourceID: changelistID,
}
@@ -261,6 +277,26 @@ func (s *ChangelistService) DeleteChangelist(ctx context.Context, request *v1pb.
return nil, status.Errorf(codes.NotFound, "changelist %q not found", changelistID)
}
+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
+ if !ok {
+ return nil, status.Errorf(codes.Internal, "user not found")
+ }
+
+ if s.profile.DevelopmentIAM {
+ ok, err := func() (bool, error) {
+ if changelist.CreatorID == user.ID {
+ return true, nil
+ }
+ return s.iamManager.CheckPermission(ctx, iam.PermissionChangelistsDelete, 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 delete changelist")
+ }
+ }
+
if err := s.store.DeleteChangelist(ctx, project.ResourceID, changelistID); err != nil {
return nil, err
}