summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-07-07 15:54:39 +0200
committerJames Lopez <james@jameslopez.es>2017-07-07 15:54:39 +0200
commita9e8af3386f47cee657a95f0094095f5f4cc1b4e (patch)
tree44bf6a97c7ec3743668c2e1fd4ccc52a032998a6
parent5173955fd49ab9748a9878203b691732198091aa (diff)
downloadgitlab-ce-a9e8af3386f47cee657a95f0094095f5f4cc1b4e.tar.gz
add spec and project snippet user agent details endpoint
-rw-r--r--doc/api/project_snippets.md1
-rw-r--r--doc/api/snippets.md1
-rw-r--r--lib/api/project_snippets.rb16
-rw-r--r--spec/requests/api/project_snippets_spec.rb21
4 files changed, 39 insertions, 0 deletions
diff --git a/doc/api/project_snippets.md b/doc/api/project_snippets.md
index cd64631ca4f..d74398c6e65 100644
--- a/doc/api/project_snippets.md
+++ b/doc/api/project_snippets.md
@@ -149,4 +149,5 @@ Example response:
"akismet_submitted": false
}
```
+
[ce-[ce-29508]: https://gitlab.com/gitlab-org/gitlab-ce/issues/29508]: https://gitlab.com/gitlab-org/gitlab-ce/issues/29508
diff --git a/doc/api/snippets.md b/doc/api/snippets.md
index 798b80a5b11..fdafbfb5b9e 100644
--- a/doc/api/snippets.md
+++ b/doc/api/snippets.md
@@ -264,4 +264,5 @@ Example response:
"akismet_submitted": false
}
```
+
[ce-[ce-29508]: https://gitlab.com/gitlab-org/gitlab-ce/issues/29508]: https://gitlab.com/gitlab-org/gitlab-ce/issues/29508
diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb
index 64efe82a937..3320eadff0d 100644
--- a/lib/api/project_snippets.rb
+++ b/lib/api/project_snippets.rb
@@ -131,6 +131,22 @@ module API
content_type 'text/plain'
present snippet.content
end
+
+ desc 'Get the user agent details for a project snippet' do
+ success Entities::UserAgentDetail
+ end
+ params do
+ requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
+ end
+ get ":id/snippets/:snippet_id/user_agent_detail" do
+ authenticated_as_admin!
+
+ snippet = Snippet.find_by!(id: params[:id])
+
+ return not_found!('UserAgentDetail') unless snippet.user_agent_detail
+
+ present snippet.user_agent_detail, with: Entities::UserAgentDetail
+ end
end
end
end
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb
index 518639f45a2..c7a2dfbea51 100644
--- a/spec/requests/api/project_snippets_spec.rb
+++ b/spec/requests/api/project_snippets_spec.rb
@@ -242,4 +242,25 @@ describe API::ProjectSnippets do
expect(json_response['message']).to eq('404 Snippet Not Found')
end
end
+
+ describe "GET /projects/:project_id/snippets/:id/user_agent_detail" do
+ let(:admin) { create(:admin) }
+ let(:snippet) { create(:project_snippet, author: admin) }
+ let!(:user_agent_detail) { create(:user_agent_detail, subject: snippet) }
+
+ it 'exposes known attributes' do
+ get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/user_agent_detail", admin)
+
+ expect(response).to have_http_status(200)
+ expect(json_response['user_agent']).to eq(user_agent_detail.user_agent)
+ expect(json_response['ip_address']).to eq(user_agent_detail.ip_address)
+ expect(json_response['akismet_submitted']).to eq(user_agent_detail.submitted)
+ end
+
+ it "returns unautorized for non-admin users" do
+ get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/user_agent_detail", user)
+
+ expect(response).to have_http_status(403)
+ end
+ end
end