summaryrefslogtreecommitdiff
path: root/app/services/groups/destroy_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/groups/destroy_service.rb')
-rw-r--r--app/services/groups/destroy_service.rb23
1 files changed, 19 insertions, 4 deletions
diff --git a/app/services/groups/destroy_service.rb b/app/services/groups/destroy_service.rb
index 1bff70e6c2e..c7107e2fa56 100644
--- a/app/services/groups/destroy_service.rb
+++ b/app/services/groups/destroy_service.rb
@@ -29,17 +29,32 @@ module Groups
group.chat_team&.remove_mattermost_team(current_user)
- user_ids_for_project_authorizations_refresh = group.user_ids_for_project_authorizations
+ # If any other groups are shared with the group that is being destroyed,
+ # we should specifically trigger update of all project authorizations
+ # for users that are the members of this group.
+ # If not, the project authorization records of these users to projects within the shared groups
+ # will never be removed, causing inconsistencies with access permissions.
+ if any_other_groups_are_shared_with_this_group?
+ user_ids_for_project_authorizations_refresh = group.user_ids_for_project_authorizations
+ end
group.destroy
- UserProjectAccessChangedService
- .new(user_ids_for_project_authorizations_refresh)
- .execute(blocking: true)
+ if user_ids_for_project_authorizations_refresh.present?
+ UserProjectAccessChangedService
+ .new(user_ids_for_project_authorizations_refresh)
+ .execute(blocking: true)
+ end
group
end
# rubocop: enable CodeReuse/ActiveRecord
+
+ private
+
+ def any_other_groups_are_shared_with_this_group?
+ group.shared_group_links.any?
+ end
end
end