2019-11-05 09:21:54 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups
|
|
|
|
module GroupLinks
|
|
|
|
class DestroyService < BaseService
|
2020-06-09 18:08:28 +00:00
|
|
|
def execute(one_or_more_links, skip_authorization: false)
|
|
|
|
unless skip_authorization || group && can?(current_user, :admin_group_member, group)
|
|
|
|
return error('Not Found', 404)
|
|
|
|
end
|
|
|
|
|
2019-11-05 09:21:54 +00:00
|
|
|
links = Array(one_or_more_links)
|
|
|
|
|
2020-03-04 21:07:54 +00:00
|
|
|
if GroupGroupLink.delete(links)
|
|
|
|
Gitlab::AppLogger.info(
|
|
|
|
"GroupGroupLinks with ids: #{links.map(&:id)} have been deleted.")
|
2019-11-05 09:21:54 +00:00
|
|
|
|
|
|
|
groups_to_refresh = links.map(&:shared_with_group)
|
|
|
|
groups_to_refresh.uniq.each do |group|
|
2021-07-19 18:08:23 +00:00
|
|
|
group.refresh_members_authorized_projects(blocking: false, direct_members_only: true)
|
2019-11-05 09:21:54 +00:00
|
|
|
end
|
2020-03-04 21:07:54 +00:00
|
|
|
else
|
|
|
|
Gitlab::AppLogger.info(
|
|
|
|
"Failed to delete GroupGroupLinks with ids: #{links.map(&:id)}.")
|
2019-11-05 09:21:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|