diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-07-07 17:13:31 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-07-07 17:13:31 +0000 |
commit | 820aeb4e8d8df9ed5a197a4f9529e107a170e9de (patch) | |
tree | 8783945cd1a61351beb3a772c2cf51c082eb6b04 /lib/api | |
parent | c5e11d0405ce6f1b28af50e918af24cd330cfd65 (diff) | |
parent | 4c735e1bd4bd0d67dc6f5496e13346a8b5926cd0 (diff) | |
download | gitlab-ce-820aeb4e8d8df9ed5a197a4f9529e107a170e9de.tar.gz |
Merge branch 'feature/user-agent-details-api' into 'master'
Allow admins to retrieve user agent details for an issue or snippet
Closes #29508
See merge request !12655
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 6 | ||||
-rw-r--r-- | lib/api/issues.rb | 16 | ||||
-rw-r--r-- | lib/api/project_snippets.rb | 16 | ||||
-rw-r--r-- | lib/api/snippets.rb | 16 |
4 files changed, 54 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index fdc0c562248..f4796f311a5 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -888,5 +888,11 @@ module API expose :dependencies, using: Dependency end end + + class UserAgentDetail < Grape::Entity + expose :user_agent + expose :ip_address + expose :submitted, as: :akismet_submitted + end end end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 09dca0dff8b..64be08094ed 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -241,6 +241,22 @@ module API present paginate(merge_requests), with: Entities::MergeRequestBasic, current_user: current_user, project: user_project end + + desc 'Get the user agent details for an issue' do + success Entities::UserAgentDetail + end + params do + requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + end + get ":id/issues/:issue_iid/user_agent_detail" do + authenticated_as_admin! + + issue = find_project_issue(params[:issue_iid]) + + return not_found!('UserAgentDetail') unless issue.user_agent_detail + + present issue.user_agent_detail, with: Entities::UserAgentDetail + end end end end 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/lib/api/snippets.rb b/lib/api/snippets.rb index c630c24c339..fd634037a77 100644 --- a/lib/api/snippets.rb +++ b/lib/api/snippets.rb @@ -140,6 +140,22 @@ module API content_type 'text/plain' present snippet.content end + + desc 'Get the user agent details for a snippet' do + success Entities::UserAgentDetail + end + params do + requires :id, type: Integer, desc: 'The ID of a snippet' + end + get ":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 |