Show effective project access in group children list

What does this MR do and why?

On a group's Subgroups and projects list, project rows now show the user's effective role, including access inherited from the parent group.

The badge now matches Your work > Projects and the group's Shared projects tab.

Problem

Currently on master, the role badge on a project row can show the wrong role. It affects every user who inherits access to the project from its parent group.

The badge goes wrong in two ways:

  • It shows the lower role. A group Owner who is also a direct Maintainer of the project sees Maintainer.
  • It shows nothing. A user whose access is only inherited sees no badge.

The badge reads the direct project membership, not project_authorizations.

Authorization is unaffected.

Review notes

  • Why do group rows keep the direct membership? Group rows keep it to match Types::GroupType#max_access_level. That method reads direct group members only. Changing only this list would make the same badge mean different things here and in GraphQL. Changing both is a product decision. Should group rows change in a separate MR?

  • What happens to pending access requests? A pending requester no longer sees a role on project rows. Before, the lookup read User#members unscoped. A requester therefore saw the role they had asked for. project_authorizations has no row for a requester.

  • Why does permission lose the EE custom role name? The field now comes from the effective level, not a member record. Nothing renders the name, because both frontend readers use permission_integer.

  • Does the preload cover every row? Yes, for every request the UI sends. The group children resolver never sends per_page.

    One gap remains. It appears only when per_page is above 20 and the result fits on one page. Kaminari then truncates the finder's array to 20 rows. The serializer re-pages to per_page. Rows past 20 then run one query each. This is existing pagination behavior, left alone.

  • Why is there no EE: true trailer, although Danger asks for one? Only an EE spec changed. The fix ships in CE.

🛠️ with ❤️ at Siemens

References

  • Closes #519610
  • Related: #502818. Creating a project from a template writes the lower direct membership that this badge then shows.
  • Related: !256559 (merged). It applies the same project_authorizations source of truth to the project members page.
  • Related: #630000. It tracks the members page symptom of the same customer report.
  • Out of scope: #497370. It covers the members page Source wording for direct members.

Screenshots or screen recordings

User's roles Before After
Group Owner, direct project Maintainer Maintainer
Project row with a Maintainer badge
Owner
Project row with an Owner badge
Group Owner, no direct project role No badge
Project row with no role badge
Owner
Project row with an Owner badge

Database review

Project rows used to run one query each. They now share one query per page.

The new query is the one RendersProjectsList#prepare_projects_for_rendering already runs for other project lists.

Both queries were captured with ActiveRecord::QueryRecorder in a local spec run. The IDs are swapped for the gitlab-qa user and the gitlab-org/gitlab and gitlab-org/gitlab-foss projects.

Before (master), once per project row, from GroupChildEntity#membership
SELECT "members"."id", "members"."access_level", "members"."source_id", "members"."source_type",
  "members"."user_id", "members"."notification_level", "members"."type", "members"."created_at",
  "members"."updated_at", "members"."created_by_id", "members"."invite_email", "members"."invite_token",
  "members"."invite_accepted_at", "members"."requested_at", "members"."expires_at", "members"."ldap",
  "members"."override", "members"."state", "members"."invite_email_success", "members"."member_namespace_id",
  "members"."member_role_id", "members"."expiry_notified_at", "members"."request_accepted_at"
FROM "members"
WHERE "members"."user_id" = 1614863
  AND "members"."source_type" = 'Project'
  AND "members"."source_id" = 278964
LIMIT 1
After (this MR), once per page, from User#max_member_access_for_project_ids
SELECT MAX("project_authorizations"."access_level") AS "maximum_access_level",
  "project_authorizations"."project_id" AS "project_authorizations_project_id"
FROM "project_authorizations"
WHERE "project_authorizations"."user_id" = 1614863
  AND "project_authorizations"."project_id" IN (278964, 13083)
GROUP BY "project_authorizations"."project_id"
Preload coverage, measured locally

The test group has 25 projects. The user is signed in as the group Owner. The table counts the project_authorizations aggregate queries per request.

Request Rows Aggregate queries
No per_page, page 1 20 1
No per_page, page 2 5 1
per_page=10, page 1 10 1
per_page=10, page 3 5 1
per_page=50, one page 25 6

How to set up and validate locally

  1. As an administrator, create group A and add a test user as Owner.
  2. As an administrator, create a project in another group and add the same user to it as Maintainer.
  3. As an administrator, transfer the project into group A.
  4. As the test user, open group A and check the project's badge in Subgroups and projects. It shows Owner.
  5. As an administrator, remove the user's direct project membership. The test user's badge still shows Owner.

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 Gerardo Navarro

Merge request reports

Loading
Loading