diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/services/groups/update_shared_runners_service.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/services/groups/update_shared_runners_service.rb')
-rw-r--r-- | app/services/groups/update_shared_runners_service.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/services/groups/update_shared_runners_service.rb b/app/services/groups/update_shared_runners_service.rb new file mode 100644 index 00000000000..63f57104510 --- /dev/null +++ b/app/services/groups/update_shared_runners_service.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Groups + class UpdateSharedRunnersService < Groups::BaseService + def execute + return error('Operation not allowed', 403) unless can?(current_user, :admin_group, group) + + validate_params + + enable_or_disable_shared_runners! + allow_or_disallow_descendants_override_disabled_shared_runners! + + success + + rescue Group::UpdateSharedRunnersError => error + error(error.message) + end + + private + + def validate_params + if Gitlab::Utils.to_boolean(params[:shared_runners_enabled]) && !params[:allow_descendants_override_disabled_shared_runners].nil? + raise Group::UpdateSharedRunnersError, 'Cannot set shared_runners_enabled to true and allow_descendants_override_disabled_shared_runners' + end + end + + def enable_or_disable_shared_runners! + return if params[:shared_runners_enabled].nil? + + if Gitlab::Utils.to_boolean(params[:shared_runners_enabled]) + group.enable_shared_runners! + else + group.disable_shared_runners! + end + end + + def allow_or_disallow_descendants_override_disabled_shared_runners! + return if params[:allow_descendants_override_disabled_shared_runners].nil? + + # Needs to reset group because if both params are present could result in error + group.reset + + if Gitlab::Utils.to_boolean(params[:allow_descendants_override_disabled_shared_runners]) + group.allow_descendants_override_disabled_shared_runners! + else + group.disallow_descendants_override_disabled_shared_runners! + end + end + end +end |