diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2018-03-27 20:39:18 +0300 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2018-03-27 20:39:18 +0300 |
commit | de0c4730bb83b94195678e5ad4865ea648e6585f (patch) | |
tree | 3ea0fd48c5736b0f5b328f117c3db0508a371d22 /lib/api/project_snippets.rb | |
parent | dc5b5130d573a48fc34fa62862a1ad6da776b0d0 (diff) | |
parent | a1cde68d208437a470267e28ccff66fe8be88c2e (diff) |
Merge branch 'master' into add-canary-favicon
Diffstat (limited to 'lib/api/project_snippets.rb')
-rw-r--r-- | lib/api/project_snippets.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb index 64efe82a937..39c03c40bab 100644 --- a/lib/api/project_snippets.rb +++ b/lib/api/project_snippets.rb @@ -7,12 +7,13 @@ module API params do requires :id, type: String, desc: 'The ID of a project' end - resource :projects, requirements: { id: %r{[^/]+} } do + resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do helpers do def handle_project_member_errors(errors) if errors[:project_access].any? error!(errors[:project_access], 422) end + not_found! end @@ -116,7 +117,8 @@ module API not_found!('Snippet') unless snippet authorize! :admin_project_snippet, snippet - snippet.destroy + + destroy_conditionally!(snippet) end desc 'Get a raw project snippet' @@ -131,6 +133,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[:snippet_id], project_id: params[:id]) + + return not_found!('UserAgentDetail') unless snippet.user_agent_detail + + present snippet.user_agent_detail, with: Entities::UserAgentDetail + end end end end |