Commit 6c6bc400 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move code for playing an action to separate service

parent b09465f3
...@@ -122,18 +122,9 @@ module Ci ...@@ -122,18 +122,9 @@ module Ci
end end
def play(current_user) def play(current_user)
unless can_play?(current_user) Ci::PlayBuildService
raise Gitlab::Access::AccessDeniedError .new(project, current_user)
end .execute(self)
# 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
end end
def cancelable? def cancelable?
......
...@@ -17,7 +17,7 @@ module Ci ...@@ -17,7 +17,7 @@ module Ci
alias_method :build, :subject alias_method :build, :subject
def can_play_action? def can_play_action?
return false unless build.playable? return false unless build.action?
::Gitlab::UserAccess ::Gitlab::UserAccess
.new(user, project: build.project) .new(user, project: build.project)
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment