Commit 3dbef510 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Expose manual action abilities from a build entity

parent 5525db8b
...@@ -12,7 +12,7 @@ class BuildEntity < Grape::Entity ...@@ -12,7 +12,7 @@ class BuildEntity < Grape::Entity
path_to(:retry_namespace_project_build, build) path_to(:retry_namespace_project_build, build)
end end
expose :play_path, if: ->(build, _) { build.playable? } do |build| expose :play_path, if: proc { playable? } do |build|
path_to(:play_namespace_project_build, build) path_to(:play_namespace_project_build, build)
end end
...@@ -25,11 +25,15 @@ class BuildEntity < Grape::Entity ...@@ -25,11 +25,15 @@ class BuildEntity < Grape::Entity
alias_method :build, :object alias_method :build, :object
def path_to(route, build) def playable?
send("#{route}_path", build.project.namespace, build.project, build) build.playable? && build.can_play?(request.user)
end end
def detailed_status def detailed_status
build.detailed_status(request.user) build.detailed_status(request.user)
end end
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
end end
...@@ -41,13 +41,37 @@ describe BuildEntity do ...@@ -41,13 +41,37 @@ describe BuildEntity do
it 'does not contain path to play action' do it 'does not contain path to play action' do
expect(subject).not_to include(:play_path) expect(subject).not_to include(:play_path)
end end
it 'is not a playable job' do
expect(subject[:playable]).to be false
end
end end
context 'when build is a manual action' do context 'when build is a manual action' do
let(:build) { create(:ci_build, :manual) } let(:build) { create(:ci_build, :manual) }
it 'contains path to play action' do context 'when user is allowed to trigger action' do
expect(subject).to include(:play_path) before do
build.project.add_master(user)
end
it 'contains path to play action' do
expect(subject).to include(:play_path)
end
it 'is a playable action' do
expect(subject[:playable]).to be true
end
end
context 'when user is not allowed to trigger action' do
it 'does not contain path to play action' do
expect(subject).not_to include(:play_path)
end
it 'is not a playable action' do
expect(subject[:playable]).to be false
end
end end
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