Fix compliance framework deletion blocked by archived policy projects

What does this MR do and why?

Compliance framework deletion was blocked whenever a linked security policy existed, even when every project assigned to that policy was archived. Archived projects are inactive and pose no active compliance risk, so the deletion block should only apply when at least one assigned project is active.

This MR:

  • Checks the archived state of assigned projects through the policy project links in Framework#linked_to_security_policy?, so a framework whose linked policies only target archived projects can be deleted.
  • Exposes a per-policy hasActiveProjects field on the framework policy summary GraphQL type.
  • Updates the compliance frameworks table so the delete action is enabled when linked policies only target archived projects; deletion remains blocked when at least one assigned project is active.
  • Uses BatchLoader::GraphQL to batch-load active project checks and avoid N+1 queries.

Database changes

This MR introduces a new scope Security::Policy.with_active_projects that joins the projects table:

scope :with_active_projects, -> { joins(:projects).where(projects: { archived: false }) }

The scope is used in combination with for_type_and_policy_index in a batched GraphQL resolver to check whether policies have any non-archived assigned projects. The batched query pattern ensures one query per page of frameworks rather than one query per policy.

Example query generated by the batch loader:

SELECT DISTINCT security_orchestration_policy_configuration_id, type, policy_index
FROM security_policies
INNER JOIN security_policy_project_links ON security_policy_project_links.security_policy_id = security_policies.id
INNER JOIN projects ON projects.id = security_policy_project_links.project_id
WHERE security_policies.security_orchestration_policy_configuration_id IN (...)
  AND projects.archived = false

References

Screenshots or screen recordings

Before After
Delete action disabled with tooltip "Compliance frameworks that are linked to an active policy can't be deleted", even when all projects assigned to the linked policy are archived Delete action enabled when every project assigned to the linked policies is archived; still disabled when at least one assigned project is active

How to set up and validate locally

  1. Create a compliance framework in a group.
  2. Create a security policy and link it to the framework.
  3. Assign the policy to one or more projects.
  4. Archive all projects that are assigned to the policy.
  5. Navigate to Compliance center → Frameworks.
  6. The Delete action for the framework is now enabled (previously disabled).
  7. Unarchive one of the assigned projects and confirm the delete action becomes blocked again.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Nate Rosandich

Merge request reports

Loading
Loading