Commit df1aee14 authored by Jonathan Schafer's avatar Jonathan Schafer

DRY up Vulnerability API code

parent bdefe8a7
...@@ -29,45 +29,46 @@ module API ...@@ -29,45 +29,46 @@ module API
requires :id, type: String, desc: 'The ID of a vulnerability' requires :id, type: String, desc: 'The ID of a vulnerability'
end end
resource :vulnerabilities do resource :vulnerabilities do
before do
@vulnerability = find_and_authorize_vulnerability!(:read_vulnerability)
end
after do
render_vulnerability(@vulnerability)
end
desc 'Get a vulnerability' do desc 'Get a vulnerability' do
success EE::API::Entities::Vulnerability success EE::API::Entities::Vulnerability
end end
get ':id' do get ':id' do
vulnerability = find_and_authorize_vulnerability!(:read_vulnerability) # do nothing
render_vulnerability(vulnerability)
end end
desc 'Resolve a vulnerability' do desc 'Resolve a vulnerability' do
success EE::API::Entities::Vulnerability success EE::API::Entities::Vulnerability
end end
post ':id/resolve' do post ':id/resolve' do
vulnerability = find_and_authorize_vulnerability!(:admin_vulnerability) not_modified! if @vulnerability.resolved?
not_modified! if vulnerability.resolved?
vulnerability = ::Vulnerabilities::ResolveService.new(current_user, vulnerability).execute @vulnerability = ::Vulnerabilities::ResolveService.new(current_user, @vulnerability).execute
render_vulnerability(vulnerability)
end end
desc 'Dismiss a vulnerability' do desc 'Dismiss a vulnerability' do
success EE::API::Entities::Vulnerability success EE::API::Entities::Vulnerability
end end
post ':id/dismiss' do post ':id/dismiss' do
vulnerability = find_and_authorize_vulnerability!(:admin_vulnerability) not_modified! if @vulnerability.dismissed?
not_modified! if vulnerability.dismissed?
vulnerability = ::Vulnerabilities::DismissService.new(current_user, vulnerability).execute @vulnerability = ::Vulnerabilities::DismissService.new(current_user, @vulnerability).execute
render_vulnerability(vulnerability)
end end
desc 'Confirm a vulnerability' do desc 'Confirm a vulnerability' do
success EE::API::Entities::Vulnerability success EE::API::Entities::Vulnerability
end end
post ':id/confirm' do post ':id/confirm' do
vulnerability = find_and_authorize_vulnerability!(:admin_vulnerability) not_modified! if @vulnerability.confirmed?
not_modified! if vulnerability.confirmed?
vulnerability = ::Vulnerabilities::ConfirmService.new(current_user, vulnerability).execute @vulnerability = ::Vulnerabilities::ConfirmService.new(current_user, @vulnerability).execute
render_vulnerability(vulnerability)
end end
end end
......
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