Skip to content

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

feat: allow issue last approver to rollout (#8773)

p0ny7f896abfd0bb
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 27f5af7107..39e492a530 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -1209,7 +1209,6 @@ func (s *RolloutService) createPipeline(ctx context.Context, project *store.Proj
}
// canUserRunStageTasks returns if a user can run the tasks in a stage.
-// TODO(p0ny): support roles/LAST_APPROVER.
func canUserRunStageTasks(ctx context.Context, s *store.Store, user *store.UserMessage, issue *store.IssueMessage, stageEnvironmentID int) (bool, error) {
// the workspace owner and DBA roles can always run tasks.
if user.Role == api.Owner || user.Role == api.DBA {
@@ -1249,6 +1248,14 @@ func canUserRunStageTasks(ctx context.Context, s *store.Store, user *store.UserM
}
}
+ if lastApproverUID := getLastApproverUID(issue.Payload.GetApproval()); lastApproverUID != nil && *lastApproverUID == user.ID {
+ for _, issueRole := range p.IssueRoles {
+ if issueRole == "roles/LAST_APPROVER" {
+ return true, nil
+ }
+ }
+ }
+
return false, nil
}
@@ -1260,3 +1267,20 @@ func canUserCancelStageTaskRun(ctx context.Context, s *store.Store, user *store.
}
return canUserRunStageTasks(ctx, s, user, issue, stageEnvironmentID)
}
+
+func getLastApproverUID(approval *storepb.IssuePayloadApproval) *int {
+ if approval == nil {
+ return nil
+ }
+ if !approval.ApprovalFindingDone {
+ return nil
+ }
+ if approval.ApprovalFindingError != "" {
+ return nil
+ }
+ if len(approval.Approvers) > 0 {
+ id := int(approval.Approvers[len(approval.Approvers)-1].PrincipalId)
+ return &id
+ }
+ return nil
+}