Commit 1c08df19 authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Unschedule group deletion on deleting user group membership removal

When a group member is removed from a group,
delete associated deletion schedule, if present.
parent 66d88eb6
......@@ -530,7 +530,10 @@ To remove a group and its contents:
This action either:
- Removes the group, and also queues a background job to delete all projects in that group.
- Since [GitLab 12.8](https://gitlab.com/gitlab-org/gitlab/-/issues/33257), on [Premium or Silver](https://about.gitlab.com/pricing/premium/) or higher tiers, marks a group for deletion. The deletion will happen 7 days later by default, but this can be changed in the [instance settings](../admin_area/settings/visibility_and_access_controls.md#default-deletion-delay).
- Since [GitLab 12.8](https://gitlab.com/gitlab-org/gitlab/-/issues/33257), on [Premium or Silver](https://about.gitlab.com/pricing/premium/) or higher tiers, this action adds a background job to mark a group for deletion. By default, the job schedules the deletion 7 days in the future. You can modify this waiting period through the [instance settings](../admin_area/settings/visibility_and_access_controls.md#default-deletion-delay).
Since [GitLab 13.6](https://gitlab.com/gitlab-org/gitlab/-/issues/39504), if the user who sets up the deletion leaves or is otherwise removed from the group before the
actual deletion happens, the job is cancelled, and the group is no longer scheduled for deletion.
### Restore a group **(PREMIUM)**
......
......@@ -13,6 +13,7 @@ module EE
end
cleanup_group_identity(member)
cleanup_group_deletion_schedule(member) if member.source&.is_a?(Group)
end
private
......@@ -40,6 +41,14 @@ module EE
saml_provider.identities.for_user(member.user).delete_all
end
def cleanup_group_deletion_schedule(member)
deletion_schedule = member.source&.deletion_schedule
return unless deletion_schedule
deletion_schedule.destroy if deletion_schedule.deleting_user == member.user
end
end
end
end
---
title: Unschedule group deletion on deleting member removal
merge_request: 45715
author:
type: changed
......@@ -57,6 +57,30 @@ RSpec.describe Members::DestroyService do
expect(details[:reason]).to be_nil
end
end
context 'group deletion schedule' do
context 'when member user has a scheduled deletion for the group' do
let!(:group_deletion_schedule) { create(:group_deletion_schedule, group: group, user_id: member_user.id, marked_for_deletion_on: 2.days.ago) }
it 'deletes the group deletion schedule' do
expect(group.reload.deletion_schedule).to eq(group_deletion_schedule)
subject.execute(member)
expect(group.reload.deletion_schedule).to be nil
end
end
context 'when scheduled deletion for the group belongs to different user' do
let!(:group_deletion_schedule) { create(:group_deletion_schedule, group: group, user_id: current_user.id, marked_for_deletion_on: 2.days.ago) }
it 'does not delete the group deletion schedule' do
subject.execute(member)
expect(group.reload.deletion_schedule).to eq(group_deletion_schedule)
end
end
end
end
context 'when current user is not present' do # ie, when the system initiates the destroy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment