Skip to content

Add `membersCount` to `memberRole`

mo khan requested to merge mokhax/432477/member-count into master

What does this MR do and why?

A MemberRole cannot be deleted if it has 1 or more members. In order to allow the frontend code to determine if a Delete icon can be rendered next to a MemberRole record it needs to know how many members have a specific role. This MR adds a membersCount field to the memberRole GraphQL type to provide this information to the frontend.

#432477 (closed)

SELECT 
  member_roles.*,
  COUNT(members.id) AS members_count
FROM "member_roles"
LEFT OUTER JOIN "members" ON "members"."member_role_id" = "member_roles"."id"
WHERE "member_roles"."namespace_id" = 9970
GROUP BY "member_roles"."id"
ORDER BY "member_roles"."name" ASC
LIMIT 100
OFFSET 0;

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/24446/commands/78064

Screenshots or screen recordings

image

How to set up and validate locally

  1. Open GraphQL Explorer: http://gdk.test:3000/-/graphql-explorer

  2. Execute the following query

    query findMemberRole($id: MemberRoleID!){
      memberRole(id:$id) {
        id
        name
        membersCount
      }
    }
    {
      "id": "gid://gitlab/MemberRole/1"
    }
  3. Verify the correct membersCount is returned in the results

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by mo khan

Merge request reports

Loading