Commit df1aee14 authored by Jonathan Schafer's avatar Jonathan Schafer

DRY up Vulnerability API code

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