Show the enforced role when listing direct members only
What does this MR do and why?
Show the role GitLab enforces on the project Members page in every view that lists direct members only, so a member is no longer shown at a role they do not have.
Problem
Currently on master, the project Members page can show a role the user does not have, see Project members page shows a role the user does... (#630000).
A user who is a direct Guest on a project, and a Developer through an invited group, is listed as Guest on the Direct members tab and under the direct-membership filter. The unfiltered Members tab lists the same user as Developer, which is the role that applies. MembersFinder returns early when a caller asks only for direct members, so it skips the step that takes the role from the project authorization. An owner deciding who to promote or remove reads the wrong role in two of the three views.
Review notes
- Why not fix this once for every caller? The same finder call serves the namespace membership export, which lists one row per way a user got access. That export needs the role written on each membership, not the role that wins. The new behaviour is therefore off by default, and only the Members page turns it on.
- Why resolve in the query instead of when the row renders? The finder applies the
max_roleandaccess_levelsfilters after it builds the relation. Resolving later would show Developer while the role filter still matched Guest. The count behind the Direct members tab badge is switched on for the same reason, so the badge cannot disagree with the rows. - Does this collide with the two open merge requests on this file? Fix wrong membership source shown for project members and Fix project Members page missing users with access via group-to-group share both change
MembersFinder, and neither touches the direct-only branch. Whichever lands first, the other rebases. - The After screenshots say Developer but Source still says Direct member. Is that wrong? No. Source names the membership the row came from, and that is the direct Guest membership either way. Which membership it should name when a user has more than one way in is still open in Incorrect membership source attribution. The role can be corrected without settling that.
References
Screenshots or screen recordings
Every row below is the same user (csc7123-jona) on the same project, seen in a different view of the Members page. That user is a direct Guest on the project and a Developer through a group invited to the parent group. Developer is the role GitLab enforces, so Developer is the correct value in all three rows.
The Before column is master. The After column is this branch. The two Guest cells are the bug.
How to set up and validate locally
- Create two unrelated groups, X and Y. X is not a subgroup of Y.
- On Y's Members page, select Invite a group and invite X with the Developer role.
- Create a project in Y, add a user to X as Developer, then add that user to the project directly as Guest. The Guest is accepted because the higher role comes from an invited group; GitLab refuses a direct membership below a role inherited from an ancestor group membership.
- Open the project's Members page, its Direct members tab, and the Members page with
?with_inherited_permissions=exclude. All three show Developer.
Database review
Paginated list
- The members page view with
?with_inherited_permissions=excluderuns the same SQL as the paginated list.
Paginated list, before (master)
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",
"users"."name" AS member_user_full_name
FROM "members"
LEFT OUTER JOIN "users" ON "users"."id" = "members"."user_id"
WHERE "members"."type" = 'ProjectMember'
AND "members"."member_namespace_id" = 15846663
AND "members"."requested_at" IS NULL
AND "members"."invite_token" IS NULL
ORDER BY "users"."name" ASC NULLS LAST, "members"."id" DESC
LIMIT 20 OFFSET 0Paginated list, after (this MR)
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",
"users"."name" AS member_user_full_name
FROM (
SELECT DISTINCT ON (user_id, invite_email)
member_union.id,
COALESCE(project_authorizations.access_level, member_union.access_level) access_level,
member_union.source_id, member_union.source_type, member_union.user_id,
member_union.notification_level, member_union.type, member_union.created_at,
member_union.updated_at, member_union.created_by_id, member_union.invite_email,
member_union.invite_token, member_union.invite_accepted_at, member_union.requested_at,
member_union.expires_at, member_union.ldap, member_union.override, member_union.state,
member_union.invite_email_success, member_union.member_namespace_id,
member_union.member_role_id, member_union.expiry_notified_at,
member_union.request_accepted_at
FROM (
(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"."type" = 'ProjectMember'
AND "members"."member_namespace_id" = 15846663
AND "members"."requested_at" IS NULL)
) AS member_union
LEFT JOIN project_authorizations
ON project_authorizations.user_id = member_union.user_id
AND project_authorizations.project_id = 278964
ORDER BY user_id,
invite_email,
CASE
WHEN type = 'ProjectMember' THEN 1
WHEN type = 'GroupMember' THEN 2
ELSE 3
END
) AS members
LEFT OUTER JOIN "users" ON "users"."id" = "members"."user_id"
WHERE "members"."invite_token" IS NULL
ORDER BY "users"."name" ASC NULLS LAST, "members"."id" DESC
LIMIT 20 OFFSET 0Badge count
Badge count, before (master)
SELECT COUNT(*)
FROM "members"
WHERE "members"."type" = 'ProjectMember'
AND "members"."member_namespace_id" = 15846663
AND "members"."requested_at" IS NULL
AND "members"."invite_token" IS NULLBadge count, after (this MR)
SELECT COUNT(*)
FROM (
SELECT DISTINCT ON (user_id, invite_email)
member_union.id,
COALESCE(project_authorizations.access_level, member_union.access_level) access_level,
member_union.source_id, member_union.source_type, member_union.user_id,
member_union.notification_level, member_union.type, member_union.created_at,
member_union.updated_at, member_union.created_by_id, member_union.invite_email,
member_union.invite_token, member_union.invite_accepted_at, member_union.requested_at,
member_union.expires_at, member_union.ldap, member_union.override, member_union.state,
member_union.invite_email_success, member_union.member_namespace_id,
member_union.member_role_id, member_union.expiry_notified_at,
member_union.request_accepted_at
FROM (
(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"."type" = 'ProjectMember'
AND "members"."member_namespace_id" = 15846663
AND "members"."requested_at" IS NULL)
) AS member_union
LEFT JOIN project_authorizations
ON project_authorizations.user_id = member_union.user_id
AND project_authorizations.project_id = 278964
ORDER BY user_id,
invite_email,
CASE
WHEN type = 'ProjectMember' THEN 1
WHEN type = 'GroupMember' THEN 2
ELSE 3
END
) AS members
WHERE "members"."invite_token" IS NULLMR 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.





