Filter group template projects by user visibility and membership
What does this MR do and why?
Filter group template projects by user visibility and membership
templates_available? lacked a nil-user guard, causing NoMethodError
for unauthenticated callers. The execute query chain also omitted a
visibility scope, so private template projects were surfaced to users
who weren't project members, and the template picker showed templates
from groups the user had no access to.
Add user && guard to templates_available? and chain
.public_or_visible_to_user(user) onto the execute query so that
public and internal templates are visible to any authenticated user
while private templates are restricted to project members.
Resolves #601253 (closed)
Changelog: fixed EE: true
Query Plan
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/52064/commands/153369
How to set up and validate locally
Test Setup
Groups required:
root-group(Public, Developers can create projects)project-templates-groupsubgroup (Public) — configured as the custom templates grouppublic-templateproject (Public)internal-templateproject (Internal)private-templateproject (Private)
sub-groupsubgroup (Public, Developers can create projects) — where the developer creates projectsproject-templates-groupsubgroup (Public) - configured as the custom templates group for the sub-grouppublic-templateproject (Public)internal-templateproject (Internal)private-templateproject (Private)
Users required:
root-developer— Developer of the root groupsubgroup-developer— Developer ofsub-grouponly (not a root group member)
What to test
While attempting to create a project within the sub-group:
- with
subgroup-developeryou should see allsub-grouptemplates and thepublicandinternalroot-grouptemplates
- with
root-developeryou should see allroot-groupandsub-grouptemplates
Set the groups to private (all projects and template groups also need to be set to private, can also delete public/internal projects if you prefer)



