Commit 115ab79b authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '35158-snippets-api-visibility' into 'master'

Resolve "Provide ability to retrieve `visibility` level via Snippets API"

Closes #35158

See merge request gitlab-org/gitlab-ce!19620
parents a0a6e38b 4077d4f7
---
title: Expose visibility via Snippets API
merge_request: 19620
author: Jan Beckmann
type: added
...@@ -49,6 +49,7 @@ Example response: ...@@ -49,6 +49,7 @@ Example response:
"title": "test", "title": "test",
"file_name": "add.rb", "file_name": "add.rb",
"description": "Ruby test snippet", "description": "Ruby test snippet",
"visibility": "private",
"author": { "author": {
"id": 1, "id": 1,
"username": "john_smith", "username": "john_smith",
...@@ -99,6 +100,7 @@ Example response: ...@@ -99,6 +100,7 @@ Example response:
"title": "This is a snippet", "title": "This is a snippet",
"file_name": "test.txt", "file_name": "test.txt",
"description": "Hello World snippet", "description": "Hello World snippet",
"visibility": "internal",
"author": { "author": {
"id": 1, "id": 1,
"username": "john_smith", "username": "john_smith",
...@@ -150,6 +152,7 @@ Example response: ...@@ -150,6 +152,7 @@ Example response:
"title": "test", "title": "test",
"file_name": "add.rb", "file_name": "add.rb",
"description": "description of snippet", "description": "description of snippet",
"visibility": "internal",
"author": { "author": {
"id": 1, "id": 1,
"username": "john_smith", "username": "john_smith",
...@@ -238,7 +241,8 @@ Example response: ...@@ -238,7 +241,8 @@ Example response:
"raw_url": "http://localhost:3000/snippets/48/raw", "raw_url": "http://localhost:3000/snippets/48/raw",
"title": "Minus similique nesciunt vel fugiat qui ullam sunt.", "title": "Minus similique nesciunt vel fugiat qui ullam sunt.",
"updated_at": "2016-11-25T16:53:34.479Z", "updated_at": "2016-11-25T16:53:34.479Z",
"web_url": "http://localhost:3000/snippets/48" "web_url": "http://localhost:3000/snippets/48",
"visibility": "public"
} }
] ]
``` ```
......
...@@ -362,7 +362,7 @@ module API ...@@ -362,7 +362,7 @@ module API
end end
class Snippet < Grape::Entity class Snippet < Grape::Entity
expose :id, :title, :file_name, :description expose :id, :title, :file_name, :description, :visibility
expose :author, using: Entities::UserBasic expose :author, using: Entities::UserBasic
expose :updated_at, :created_at expose :updated_at, :created_at
expose :project_id expose :project_id
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"title": { "type": "string" }, "title": { "type": "string" },
"file_name": { "type": ["string", "null"] }, "file_name": { "type": ["string", "null"] },
"description": { "type": ["string", "null"] }, "description": { "type": ["string", "null"] },
"visibility": { "type": "string" },
"web_url": { "type": "string" }, "web_url": { "type": "string" },
"created_at": { "type": "date" }, "created_at": { "type": "date" },
"updated_at": { "type": "date" }, "updated_at": { "type": "date" },
......
...@@ -20,6 +20,7 @@ describe API::Snippets do ...@@ -20,6 +20,7 @@ describe API::Snippets do
private_snippet.id) private_snippet.id)
expect(json_response.last).to have_key('web_url') expect(json_response.last).to have_key('web_url')
expect(json_response.last).to have_key('raw_url') expect(json_response.last).to have_key('raw_url')
expect(json_response.last).to have_key('visibility')
end end
it 'hides private snippets from regular user' do it 'hides private snippets from regular user' do
...@@ -112,6 +113,7 @@ describe API::Snippets do ...@@ -112,6 +113,7 @@ describe API::Snippets do
expect(json_response['title']).to eq(snippet.title) expect(json_response['title']).to eq(snippet.title)
expect(json_response['description']).to eq(snippet.description) expect(json_response['description']).to eq(snippet.description)
expect(json_response['file_name']).to eq(snippet.file_name) expect(json_response['file_name']).to eq(snippet.file_name)
expect(json_response['visibility']).to eq(snippet.visibility)
end end
it 'returns 404 for invalid snippet id' do it 'returns 404 for invalid snippet id' do
...@@ -142,6 +144,7 @@ describe API::Snippets do ...@@ -142,6 +144,7 @@ describe API::Snippets do
expect(json_response['title']).to eq(params[:title]) expect(json_response['title']).to eq(params[:title])
expect(json_response['description']).to eq(params[:description]) expect(json_response['description']).to eq(params[:description])
expect(json_response['file_name']).to eq(params[:file_name]) expect(json_response['file_name']).to eq(params[:file_name])
expect(json_response['visibility']).to eq(params[:visibility])
end end
it 'returns 400 for missing parameters' do it 'returns 400 for missing parameters' 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