Commit 3f6121f2 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira Committed by Fatih Acet

Returns new_blob_path only when user can push_code to project

parent ca3d868c
...@@ -98,9 +98,11 @@ class MergeRequestEntity < IssuableEntity ...@@ -98,9 +98,11 @@ class MergeRequestEntity < IssuableEntity
end end
expose :new_blob_path do |merge_request| expose :new_blob_path do |merge_request|
namespace_project_new_blob_path(merge_request.project.namespace, if can?(current_user, :push_code, merge_request.project)
merge_request.project, namespace_project_new_blob_path(merge_request.project.namespace,
merge_request.source_branch) merge_request.project,
merge_request.source_branch)
end
end end
expose :conflict_resolution_path do |merge_request| expose :conflict_resolution_path do |merge_request|
......
...@@ -65,6 +65,23 @@ describe MergeRequestEntity do ...@@ -65,6 +65,23 @@ describe MergeRequestEntity do
.to eq(resource.merge_commit_message(include_description: true)) .to eq(resource.merge_commit_message(include_description: true))
end end
describe 'new_blob_path' do
context 'when user can push to project' do
it 'returns path' do
project.add_developer(user)
expect(subject[:new_blob_path])
.to eq("/#{resource.project.full_path}/new/#{resource.source_branch}")
end
end
context 'when user cannot push to project' do
it 'returns nil' do
expect(subject[:new_blob_path]).to be_nil
end
end
end
describe 'diff_head_sha' do describe 'diff_head_sha' do
before do before do
allow(resource).to receive(:diff_head_sha) { 'sha' } allow(resource).to receive(:diff_head_sha) { 'sha' }
......
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