Skip to content

Resolve "Defects with the share with group feature"

What does this MR do?

When a group is invited/shared to collaborate in a group or project, we are counting the members inversely.

As an example:

  • Group A invites Group B to collaborate.
  • When we display billable members for Group A, we should count the members from Group A and Group B.
  • When we display the members for Group B, we should count the members from Group B only.
  • We accidentally implemented the inverse.
  • When we display billable members for Group A, we are only counting the members from Group A .
  • When we display the billable members for Group B we are counting the members from Group B and Group A.

Also when the groups are invited to collaborate as Guest then the users should not be counted in Gold Plan

Example 1

  • Group I has 3 users.
    • Owner O
    • Maintainer M
    • Guest G
  • Group A invites Group I with Guest permissions
  • Group A is Silver plan
  • In Group A (Silver Plan) the billed users include Owner O, Maintainer M and Guest G from Group I

Example 2

  • Group I has 3 users.
    • Owner O
    • Maintainer M
    • Guest G
  • Group B invites Group I with Guest permissions
  • Group B is Gold plan.
  • In Group B (Gold Plan) none of the members of Group I are billable because they all have Guest permissions within Group B's paid namespace.

This MR will take care of the following defects

  • Count users from all the groups being invited to the billed group.
  • Check permissions of the invited group and do not include the groups with Guest permission for Gold Group.

Apart from the same 3 queries for fetching the data for members pasted here

The query for Get shared group members has changed and below is the sample query to fetch the billed user's id from shared group for Gitlab-org group. The explain statement for the below query :- https://explain.depesz.com/s/52yM

SELECT DISTINCT
   "members"."user_id" 
FROM
   "members" 
   LEFT OUTER JOIN
      "users" 
      ON "members"."user_id" = "users"."id" 
WHERE
   "members"."type" = 'GroupMember' 
   AND "members"."source_type" = 'Namespace' 
   AND "users"."state" = 'active' 
   AND "members"."requested_at" IS NULL 
   AND "members"."source_id" IN 
   (
      WITH RECURSIVE "base_and_ancestors" AS 
      (
(
         SELECT
            "namespaces".* 
         FROM
            "namespaces" 
            INNER JOIN
               "group_group_links" 
               ON "group_group_links"."shared_with_group_id" = "namespaces"."id" 
         WHERE
            "namespaces"."type" = 'Group' 
            AND "group_group_links"."shared_group_id" IN 
            (
               WITH RECURSIVE "base_and_descendants" AS 
               (
(
                  SELECT
                     "namespaces".* 
                  FROM
                     "namespaces" 
                  WHERE
                     "namespaces"."type" = 'Group' 
                     AND "namespaces"."id" = 9970) 
                  UNION
(
                  SELECT
                     "namespaces".* 
                  FROM
                     "namespaces", "base_and_descendants" 
                  WHERE
                     "namespaces"."type" = 'Group' 
                     AND "namespaces"."parent_id" = "base_and_descendants"."id")
               )
               SELECT
                  "namespaces"."id" 
               FROM
                  "base_and_descendants" AS "namespaces"
            )
) 
         UNION
(
         SELECT
            "namespaces".* 
         FROM
            "namespaces", "base_and_ancestors" 
         WHERE
            "namespaces"."type" = 'Group' 
            AND "namespaces"."id" = "base_and_ancestors"."parent_id")
      )
      SELECT
         "namespaces"."id" 
      FROM
         "base_and_ancestors" AS "namespaces"
   )

Conformity

Closes #213211

Edited by Shreyas Agarwal

Merge request reports