Commit f39582f7 authored by Douwe Maan's avatar Douwe Maan

Merge branch '46668-make-the-html-attribute-on-the-blob-json-call-optional' into 'master'

Resolve "Make the html attribute on the blob json call optional"

Closes #46668

See merge request gitlab-org/gitlab-ce!19479
parents 16723ff5 fbc749a9
...@@ -9,7 +9,7 @@ export default { ...@@ -9,7 +9,7 @@ export default {
return Vue.http.get(endpoint, { params: { format: 'json' } }); return Vue.http.get(endpoint, { params: { format: 'json' } });
}, },
getFileData(endpoint) { getFileData(endpoint) {
return Vue.http.get(endpoint, { params: { format: 'json' } }); return Vue.http.get(endpoint, { params: { format: 'json', viewer: 'none' } });
}, },
getRawFileData(file) { getRawFileData(file) {
if (file.tempFile) { if (file.tempFile) {
......
...@@ -197,14 +197,11 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -197,14 +197,11 @@ class Projects::BlobController < Projects::ApplicationController
end end
def show_json def show_json
json = blob_json(@blob)
return render_404 unless json
path_segments = @path.split('/') path_segments = @path.split('/')
path_segments.pop path_segments.pop
tree_path = path_segments.join('/') tree_path = path_segments.join('/')
render json: json.merge( json = {
id: @blob.id, id: @blob.id,
path: blob.path, path: blob.path,
name: blob.name, name: blob.name,
...@@ -221,6 +218,10 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -221,6 +218,10 @@ class Projects::BlobController < Projects::ApplicationController
commits_path: project_commits_path(project, @id), commits_path: project_commits_path(project, @id),
tree_path: project_tree_path(project, File.join(@ref, tree_path)), tree_path: project_tree_path(project, File.join(@ref, tree_path)),
permalink: project_blob_path(project, File.join(@commit.id, @path)) permalink: project_blob_path(project, File.join(@commit.id, @path))
) }
json.merge!(blob_json(@blob) || {}) unless params[:viewer] == 'none'
render json: json
end end
end end
...@@ -55,6 +55,25 @@ describe Projects::BlobController do ...@@ -55,6 +55,25 @@ describe Projects::BlobController do
expect(json_response).to have_key 'raw_path' expect(json_response).to have_key 'raw_path'
end end
end end
context "with viewer=none" do
let(:id) { 'master/README.md' }
before do
get(:show,
namespace_id: project.namespace,
project_id: project,
id: id,
format: :json,
viewer: 'none')
end
it do
expect(response).to be_ok
expect(json_response).not_to have_key 'html'
expect(json_response).to have_key 'raw_path'
end
end
end end
context 'with tree path' do context 'with tree path' do
......
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