Inherited group members are missing in `shared_with_groups` when using Projects API

Summary

The Get single project Projects API endpoint supposedly returns the shared_with_groups which should list down the groups where the group was shared (i.e. which groups have access to the group). At the moment it looks like the API will only show direct members which is different from what the UI is showing.

Steps to reproduce

  1. Create a top level group TopLevel.
  2. Create another top level group DirectGroup.
  3. Create another top level group InheritedGroup.
  4. Invite InheritedGroup to TopLevel
  5. Create a project under group TopLevel named test-project.
  6. Invite DirectGroup to test-project.
  7. Go to Project Information > Members > Groups and see that InheritedGroup and DirectGroup are listed.
  8. Query the project using the Projects API and see the InheritedGroup is not listed.

Example Project

What is the current bug behavior?

  • Inherited Group members are not included in the API response.

What is the expected correct behavior?

  • Inherited Group members should be included in the API response.

Relevant logs and/or screenshots

Screenshot_from_2023-07-07_11-40-35

$ curl --header "PRIVATE-TOKEN: <REDACTED>" "https://gitlab.example.com/api/v4/projects/115" | jq '.shared_with_groups'
...
[
  {
    "group_id": 110,
    "group_name": "test-public-group",
    "group_full_path": "test-public-group",
    "group_access_level": 10,
    "expires_at": null
  }
]

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Christina Lohr