Add "shared_visible_only" option to project's groups API
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
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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