From 383138af617135dd72ca7016c1156c0cd2e6cb25 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Wed, 5 Jul 2017 14:59:19 +0200 Subject: add issues spec and user agent details to entities --- lib/api/entities.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 99eda3b0c4b..33620473175 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -875,5 +875,11 @@ module API expose :dependencies, using: Dependency end end + + class UserAgentDetail < Grape::Entity + expose :user_agent + expose :ip_address + expose :submitted + end end end -- cgit v1.2.1 From 6ee87aea89ef78e2e98df0e61225950446a822aa Mon Sep 17 00:00:00 2001 From: James Lopez Date: Wed, 5 Jul 2017 16:27:32 +0200 Subject: add user agent details API endpoints to issues and snippets --- lib/api/issues.rb | 17 +++++++++++++++++ lib/api/snippets.rb | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'lib/api') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 09dca0dff8b..88dd31739da 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -241,6 +241,23 @@ 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!('Issue') unless issue + return not_found!('UserAgentDetail') unless issue.user_agent_detail + + present issue.user_agent_detail, with: Entities::UserAgentDetail, current_user: current_user, project: user_project + end end end end diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb index c630c24c339..db4e0b0b013 100644 --- a/lib/api/snippets.rb +++ b/lib/api/snippets.rb @@ -140,6 +140,23 @@ 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!('Snippet') unless snippet + return not_found!('UserAgentDetail') unless snippet.user_agent_detail + + present snippet.user_agent_detail, with: Entities::UserAgentDetail + end end end end -- cgit v1.2.1 From 2aa95aa0185c94aefd6e51a35c62650d75d3c8b6 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 6 Jul 2017 15:19:14 +0200 Subject: refactor code based on feedback --- lib/api/entities.rb | 2 +- lib/api/issues.rb | 3 +-- lib/api/snippets.rb | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 33620473175..44b8c6e010d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -879,7 +879,7 @@ module API class UserAgentDetail < Grape::Entity expose :user_agent expose :ip_address - expose :submitted + expose :submitted, as: :akismet_submitted end end end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 88dd31739da..64be08094ed 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -253,10 +253,9 @@ module API issue = find_project_issue(params[:issue_iid]) - return not_found!('Issue') unless issue return not_found!('UserAgentDetail') unless issue.user_agent_detail - present issue.user_agent_detail, with: Entities::UserAgentDetail, current_user: current_user, project: user_project + present issue.user_agent_detail, with: Entities::UserAgentDetail end end end diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb index db4e0b0b013..fd634037a77 100644 --- a/lib/api/snippets.rb +++ b/lib/api/snippets.rb @@ -150,9 +150,8 @@ module API get ":id/user_agent_detail" do authenticated_as_admin! - snippet = Snippet.find_by(id: params[:id]) + snippet = Snippet.find_by!(id: params[:id]) - return not_found!('Snippet') unless snippet return not_found!('UserAgentDetail') unless snippet.user_agent_detail present snippet.user_agent_detail, with: Entities::UserAgentDetail -- cgit v1.2.1 From a9e8af3386f47cee657a95f0094095f5f4cc1b4e Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 7 Jul 2017 15:54:39 +0200 Subject: add spec and project snippet user agent details endpoint --- lib/api/project_snippets.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/api') 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 -- cgit v1.2.1