feat(api): add PurgeUnused RPC for bulk-deleting unused workflow contracts#3071
Open
migmartri wants to merge 1 commit intochainloop-dev:mainfrom
Open
feat(api): add PurgeUnused RPC for bulk-deleting unused workflow contracts#3071migmartri wants to merge 1 commit intochainloop-dev:mainfrom
migmartri wants to merge 1 commit intochainloop-dev:mainfrom
Conversation
…racts Adds a new PurgeUnused RPC to WorkflowContractService that soft-deletes all contracts with no associated workflows, scoped by RBAC visibility. Includes CLI support via --purge-unused flag on the delete command. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
There was a problem hiding this comment.
1 issue found across 18 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/controlplane/pkg/data/workflowcontract.go">
<violation number="1" location="app/controlplane/pkg/data/workflowcontract.go:326">
P1: `SoftDeleteUnused` reuses list filtering semantics and includes global contracts in purge scope, which can bypass RBAC restrictions for global contract deletion.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
Comment on lines
+326
to
+335
| query := applyProjectFilter( | ||
| tx.Organization.Query(). | ||
| Where(organization.ID(orgID)). | ||
| QueryWorkflowContracts(). | ||
| Where( | ||
| workflowcontract.DeletedAtIsNil(), | ||
| workflowcontract.Not(workflowcontract.HasWorkflowsWith(workflow.DeletedAtIsNil())), | ||
| ), | ||
| filter, | ||
| ) |
There was a problem hiding this comment.
P1: SoftDeleteUnused reuses list filtering semantics and includes global contracts in purge scope, which can bypass RBAC restrictions for global contract deletion.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/controlplane/pkg/data/workflowcontract.go, line 326:
<comment>`SoftDeleteUnused` reuses list filtering semantics and includes global contracts in purge scope, which can bypass RBAC restrictions for global contract deletion.</comment>
<file context>
@@ -331,6 +320,59 @@ func (r *WorkflowContractRepo) SoftDelete(ctx context.Context, id uuid.UUID) err
+func (r *WorkflowContractRepo) SoftDeleteUnused(ctx context.Context, orgID uuid.UUID, filter *biz.WorkflowContractListFilters) (int, error) {
+ var n int
+ if err := WithTx(ctx, r.data.DB, func(tx *ent.Tx) error {
+ query := applyProjectFilter(
+ tx.Organization.Query().
+ Where(organization.ID(orgID)).
</file context>
Suggested change
| query := applyProjectFilter( | |
| tx.Organization.Query(). | |
| Where(organization.ID(orgID)). | |
| QueryWorkflowContracts(). | |
| Where( | |
| workflowcontract.DeletedAtIsNil(), | |
| workflowcontract.Not(workflowcontract.HasWorkflowsWith(workflow.DeletedAtIsNil())), | |
| ), | |
| filter, | |
| ) | |
| query := tx.Organization.Query(). | |
| Where(organization.ID(orgID)). | |
| QueryWorkflowContracts(). | |
| Where( | |
| workflowcontract.DeletedAtIsNil(), | |
| workflowcontract.Not(workflowcontract.HasWorkflowsWith(workflow.DeletedAtIsNil())), | |
| ) | |
| if filter != nil && len(filter.FilterByProjects) > 0 { | |
| query = query.Where( | |
| workflowcontract.And( | |
| workflowcontract.ScopedResourceTypeIn(biz.ContractScopeProject), | |
| workflowcontract.ScopedResourceIDIn(filter.FilterByProjects...), | |
| ), | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3072
PurgeUnusedRPC toWorkflowContractServicethat soft-deletes all contracts with no associated workflows, respecting RBAC project scopingworkflow contract deletewith--purge-unusedflag for bulk cleanupWorkflowContractPurgedaudit events and include integration tests for all purge scenarios