diff options
Diffstat (limited to 'app/services/groups/update_shared_runners_service.rb')
-rw-r--r-- | app/services/groups/update_shared_runners_service.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/app/services/groups/update_shared_runners_service.rb b/app/services/groups/update_shared_runners_service.rb index c09dce0761f..08b43037c4c 100644 --- a/app/services/groups/update_shared_runners_service.rb +++ b/app/services/groups/update_shared_runners_service.rb @@ -25,7 +25,14 @@ module Groups end def update_shared_runners - group.update_shared_runners_setting!(params[:shared_runners_setting]) + case params[:shared_runners_setting] + when Namespace::SR_DISABLED_AND_UNOVERRIDABLE + set_shared_runners_enabled!(false) + when Namespace::SR_DISABLED_WITH_OVERRIDE, Namespace::SR_DISABLED_AND_OVERRIDABLE + disable_shared_runners_and_allow_override! + when Namespace::SR_ENABLED + set_shared_runners_enabled!(true) + end end def update_pending_builds? @@ -41,5 +48,38 @@ module Groups ::Ci::UpdatePendingBuildService.new(group, pending_builds_params).execute end end + + def set_shared_runners_enabled!(enabled) + group.update!( + shared_runners_enabled: enabled, + allow_descendants_override_disabled_shared_runners: false) + + group_ids = group.descendants + unless group_ids.empty? + Group.by_id(group_ids).update_all( + shared_runners_enabled: enabled, + allow_descendants_override_disabled_shared_runners: false) + end + + group.all_projects.update_all(shared_runners_enabled: enabled) + end + + def disable_shared_runners_and_allow_override! + # enabled -> disabled_and_overridable + if group.shared_runners_enabled? + group.update!( + shared_runners_enabled: false, + allow_descendants_override_disabled_shared_runners: true) + + group_ids = group.descendants + Group.by_id(group_ids).update_all(shared_runners_enabled: false) unless group_ids.empty? + + group.all_projects.update_all(shared_runners_enabled: false) + + # disabled_and_unoverridable -> disabled_and_overridable + else + group.update!(allow_descendants_override_disabled_shared_runners: true) + end + end end end |