diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-20 12:42:41 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-20 12:42:41 +0000 |
commit | 33a25e0fc61a1436bfbe9b1e3079c5790a726492 (patch) | |
tree | 2bccf077054080ae7b5ba9c6995f48b993aa5dd3 /app/services | |
parent | f99cc765c7cc20372e2c1c915c40e4a71a1dca15 (diff) | |
parent | 36a8cc3eca62c28ff9001be9378f76b7d59a2f4d (diff) | |
download | gitlab-ce-33a25e0fc61a1436bfbe9b1e3079c5790a726492.tar.gz |
Merge branch 'uassign_on_member_removing' into 'master'
Unassign all Issues and Merge Requests when member leaves a team
Closes #30768 and #24117
See merge request !10755
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/members/authorized_destroy_service.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/app/services/members/authorized_destroy_service.rb b/app/services/members/authorized_destroy_service.rb index b7a244c2029..1711be7211c 100644 --- a/app/services/members/authorized_destroy_service.rb +++ b/app/services/members/authorized_destroy_service.rb @@ -9,7 +9,11 @@ module Members def execute return false if member.is_a?(GroupMember) && member.source.last_owner?(member.user) - member.destroy + Member.transaction do + unassign_issues_and_merge_requests(member) + + member.destroy + end if member.request? && member.user != user notification_service.decline_access_request(member) @@ -17,5 +21,23 @@ module Members member end + + private + + def unassign_issues_and_merge_requests(member) + if member.is_a?(GroupMember) + IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). + execute. + update_all(assignee_id: nil) + MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). + execute. + update_all(assignee_id: nil) + else + project = member.source + project.issues.opened.assigned_to(member.user).update_all(assignee_id: nil) + project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil) + member.user.update_cache_counts + end + end end end |