diff options
-rw-r--r-- | app/models/ci/build.rb | 15 | ||||
-rw-r--r-- | app/policies/ci/build_policy.rb | 2 | ||||
-rw-r--r-- | app/services/ci/play_build_service.rb | 17 |
3 files changed, 21 insertions, 13 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 159b3b2e101..9edc4cd96b9 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -122,18 +122,9 @@ module Ci end def play(current_user) - unless can_play?(current_user) - raise Gitlab::Access::AccessDeniedError - end - - # Try to queue a current build - if self.enqueue - self.update(user: current_user) - self - else - # Otherwise we need to create a duplicate - Ci::Build.retry(self, current_user) - end + Ci::PlayBuildService + .new(project, current_user) + .execute(self) end def cancelable? diff --git a/app/policies/ci/build_policy.rb b/app/policies/ci/build_policy.rb index 0522cbdb331..2c39d31488f 100644 --- a/app/policies/ci/build_policy.rb +++ b/app/policies/ci/build_policy.rb @@ -17,7 +17,7 @@ module Ci alias_method :build, :subject def can_play_action? - return false unless build.playable? + return false unless build.action? ::Gitlab::UserAccess .new(user, project: build.project) diff --git a/app/services/ci/play_build_service.rb b/app/services/ci/play_build_service.rb new file mode 100644 index 00000000000..c9ed45408f2 --- /dev/null +++ b/app/services/ci/play_build_service.rb @@ -0,0 +1,17 @@ +module Ci + class PlayBuildService < ::BaseService + def execute(build) + unless can?(current_user, :play_build, build) + raise Gitlab::Access::AccessDeniedError + end + + # Try to enqueue thebuild, otherwise create a duplicate. + # + if build.enqueue + build.tap { |action| action.update(user: current_user) } + else + Ci::Build.retry(build, current_user) + end + end + end +end |