Protected branch "security policies" popover link 404s
Summary
On Settings > Repository > Protected branches, the popover shown when a branch can't be unprotected because of security policy enforcement includes a "security policies" link. The link is broken: it 404s instead of opening the project's (or group's) security policies page.
Steps to reproduce
- Set up a policy that enforces
block_branch_modification: trueon a project or group. - Go to Settings > Repository > Protected branches for an affected project.
- Hover the info icon next to a protected branch that can't be unprotected.
- Click the "security policies" link in the popover text.
What is the current bug behavior?
The link points at /groups/<protected_branch_id>/-/security/policies and 404s. In ee/app/views/protected_branches/ee/_protected_branch.html.haml:8, the link is built with security_policies_path(protected_branch), passing the ProtectedBranch record. security_policies_path (ee/app/helpers/ee/security_orchestration_helper.rb:95) only special-cases Project:
def security_policies_path(container)
container.is_a?(::Project) ? project_security_policies_path(container) : group_security_policies_path(container)
endA ProtectedBranch is never a Project, so it always falls through to group_security_policies_path(protected_branch), which uses the protected branch's id as if it were a group id.
What is the expected correct behavior?
The link should open the security policies page for the container the enforcing policy actually applies to: the project's security policies page for a project-level protected branch, or the group's security policies page for a group-level (inherited) protected branch.
Possible fixes
Pass the actual project or group to security_policies_path instead of the ProtectedBranch record, e.g. security_policies_path(is_inherited ? protected_branch.group : protected_branch.project), using the same is_inherited flag the view already computes a few lines above.