Read and save the policy store editor through Vue Apollo

What does this MR do and why?

Summary

This change migrates the policy editor from using direct REST/fetch API calls to using GraphQL queries and mutations for loading and saving policies.

Loading policies: Instead of a manual fetchPolicy() call in a lifecycle hook, the editor now uses Vue Apollo's declarative query system to automatically fetch the policy when an ID is present. The loading state is also smarter — it only shows a spinner on the initial load, not on background refreshes, so a user's in-progress edits are never replaced by a spinner.

Saving policies: The separate createPolicy() and updatePolicy() helper functions are replaced by direct GraphQL mutations (governPolicyCreate / governPolicyUpdate). Error handling now reads errors from the mutation's response payload rather than catching thrown exceptions.

Cache fix: This was planned here, but the Group half of the policyStore merge type policy in apollo.js landed first via !258427 (merged). This MR's copy of the line was dropped at the 2026-10-05 rebase because it was already on master. The diff touches three files: editor/app.vue, editor/app_spec.js and mock_data.js.

Tests: The test suite is updated to match — mocked REST helpers are replaced with mock Apollo handlers, and new test cases are added to cover scenarios like a policy not being found in the store's response.

References

Screenshots or screen recordings

No visual change; the editor page renders and behaves the same as before.

How to set up and validate locally

Pages are behind the security_policies_v2 feature flag, default off: Feature.enable(:security_policies_v2) in the Rails console. The policy store experiment must be active for the organization or a top-level group.

Pages: /organizations/<org-path>/-/security/policy_store and /groups/<group-path>/-/security/policy_store.

  • Open New policy and confirm in the network tab that no policies query fires and the wizard renders empty.
  • Create a policy and confirm one governPolicyCreate request followed by navigation to the list with the success alert.
  • Open Edit on a policy and confirm a single getPolicyStorePolicies (or getGroupPolicyStorePolicies) request with ids: [<id>], then the wizard prefilled. On a group, also confirm the console shows no Apollo "Cache data may be lost" warning and the wizard does not reset after the catalogs load.
  • Change the name only and save, confirm the governPolicyUpdate request carries policyId as a number and no policyScope.
  • Try a duplicate name and confirm the inline error under the name field.
  • Repeat a save on a group page and confirm groupPath and no organizationId.

Local verification: jest ee/spec/frontend/policy_store/components/editor/app_spec.js passed with 29 tests; eslint clean on the three touched files. The whole ee/spec/frontend/policy_store area passed (32 suites, 646 tests). A browser check of a group edit page in GDK was not done; the Edit step above covers it.

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 Artur Fedorov

Merge request reports

Loading
Loading