Skip to content

Add "shared_visible_only" option to project's groups API

Vasilii Iakliushin requested to merge 28902_add_visible_only_option into master

What does this MR do?

Contributes to #28902 (closed)

Add a shared_visible_only option to project's groups API.

NOTE: On GitLab.com, you can add a group as an approver if you're a member of that group or the group is public.

Based on the documentation user can only add a shared group as an approver if the group is public or the user is a member of the group.

The combination of with_shared, shared_min_access_level and shared_visible_only options should return groups eligible for an approval.

Database

Query with with_shared, shared_min_access_level and shared_visible_only options applied.

Projects::GroupsFinder.new(project: Project.find(278964), current_user: User.find(421631), params: { with_shared: true, shared_visible_only: true, shared_min_access_level: 30 }).execute

postgres.ai: https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/3920/commands/13476

SELECT
    "namespaces".*
FROM ((
        SELECT
            "namespaces".*
        FROM (
            SELECT
                "namespaces".*
            FROM
                "namespaces"
                INNER JOIN (
                    SELECT
                        "id",
                        "depth"
                    FROM ( WITH RECURSIVE "base_and_ancestors" AS ((
                                SELECT
                                    "namespaces".*
                                FROM
                                    "namespaces"
                                WHERE
                                    "namespaces"."type" = 'Group'
                                    AND "namespaces"."id" = 9970)
                            UNION (
                                SELECT
                                    "namespaces".*
                                FROM
                                    "namespaces",
                                    "base_and_ancestors"
                                WHERE
                                    "namespaces"."type" = 'Group'
                                    AND "namespaces"."id" = "base_and_ancestors"."parent_id"))
                            SELECT DISTINCT
                                "namespaces".*,
                                ROW_NUMBER() OVER () AS depth
                            FROM
                                "base_and_ancestors" AS "namespaces") AS "namespaces"
                        WHERE
                            "namespaces"."type" = 'Group') namespaces_join_table ON namespaces_join_table.id = namespaces.id
                    WHERE
                        "namespaces"."type" = 'Group'
                    ORDER BY
                        "namespaces_join_table"."depth" ASC) AS "namespaces"
                WHERE
                    "namespaces"."type" = 'Group')
            UNION (
                SELECT
                    "namespaces".*
                FROM
                    "namespaces"
                    INNER JOIN "project_group_links" ON "namespaces"."id" = "project_group_links"."group_id"
                WHERE
                    "namespaces"."type" = 'Group'
                    AND "project_group_links"."project_id" = 278964
                    AND (project_group_links.group_access >= 30)
                    AND "namespaces"."visibility_level" IN (10, 20))
            UNION (
                SELECT
                    "namespaces".*
                FROM
                    "namespaces"
                    INNER JOIN "project_group_links" ON "namespaces"."id" = "project_group_links"."group_id"
                    INNER JOIN "members" ON "members"."source_type" = 'Namespace'
                        AND "members"."source_type" = 'Namespace'
                        AND "members"."requested_at" IS NULL
                        AND "members"."access_level" != 5
                        AND "members"."source_id" = "namespaces"."id"
                        AND "members"."type" = 'GroupMember'
                WHERE
                    "namespaces"."type" = 'Group'
                    AND "project_group_links"."project_id" = 278964
                    AND (project_group_links.group_access >= 30)
                    AND "members"."user_id" = 421631
                    AND (access_level >= 10))) namespaces
    WHERE
        "namespaces"."type" = 'Group'
    ORDER BY
        "namespaces"."id" DESC

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Vasilii Iakliushin

Merge request reports