Move code for playing an action to separate service
This commit is contained in:
parent
b09465f38d
commit
6c6bc400d1
3 changed files with 21 additions and 13 deletions
|
@ -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)
|
||||
|
|
17
app/services/ci/play_build_service.rb
Normal file
17
app/services/ci/play_build_service.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue