Deleting a group member also deletes the user's direct memberships in subgroups
Summary
When a member is removed from a group, the user's direct membership in the group is deleted. In addition, all inherited memberships in subgroups disappear. This is all as it should be. But it also removes all direct memberships of the affected user in subgroups - i.e. those memberships that were not inherited but explicitly added.
Steps to reproduce
Preparation:
- Create group
group-1
and its subgroupgroup-1/subgroup-2
. - Add a user as direct member to group
group-1
. - Add same user as direct member to group
group-1/subgroup-2
.
Bug:
- Remove the user again from group
group-1
.
What is the current bug behavior?
The direct membership of the affected user in subgroup group-1/subgroup-2
is removed as well.
What is the expected correct behavior?
The direct membership of the affected user in subgroup group-1/subgroup-2
remains in place and is not removed. This membership was added explicitly and should not be removed automatically.
Output of checks
This bug happens on GitLab.com.
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Proxy: no Current User: jonas Using RVM: no Ruby Version: 2.7.2p137 Gem Version: 3.1.4 Bundler Version:2.1.4 Rake Version: 13.0.3 Redis Version: 6.0.10 Git Version: 2.30.1 Sidekiq Version:5.2.9 Go Version: go1.15.5 darwin/amd64 GitLab information Version: 13.9.0-pre Revision: d2ca937332b Directory: /Users/jonas/repos/gdk/gitlab DB Adapter: PostgreSQL DB Version: 11.9 URL: http://gdk.test:3000 HTTP Clone URL: http://gdk.test:3000/some-group/some-project.git SSH Clone URL: ssh://jonas@gdk.test:2222/some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: google_oauth2 GitLab Shell Version: 13.16.1 Repository storage paths: - default: /Users/jonas/repos/gdk/repositories GitLab Shell path: /Users/jonas/repos/gdk/gitlab-shell Git: /usr/local/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 13.16.1 ? ... OK (13.16.1) Running /Users/jonas/repos/gdk/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... yes Init script up-to-date? ... yes Projects have namespace: ... 22/1 ... yes 22/2 ... yes 23/3 ... yes 24/4 ... yes 25/5 ... yes 26/6 ... yes 27/7 ... yes 28/8 ... yes 11/9 ... yes 5/10 ... yes 14/11 ... yes 19/12 ... yes 3/13 ... yes 8/14 ... yes 15/15 ... yes 17/16 ... yes 9/17 ... yes 18/18 ... yes 52/19 ... yes 109/41 ... yes 110/56 ... yes 107/57 ... yes Redis version >= 4.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.2) Git version >= 2.29.0 ? ... yes (2.30.1) Git user has default SSH configuration? ... yes Active users: ... 98 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x (6.4 - 6.x deprecated to be removed in 13.8)? ... skipped (elasticsearch is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
The removal of memberships is done in the Members::DestroyService and it calls the function delete_subgroup_members
to remove memberships of subgroups. I suggest to simply remove this function.