提交 6c6bc400 编写于 作者: G Grzegorz Bizon

Move code for playing an action to separate service

上级 b09465f3
......@@ -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?
......
......@@ -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)
......
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册