Commit db484bcf authored by Robert Speicher's avatar Robert Speicher

Merge branch '214085-refactor-re-used-code-in-ee-lib-api-vulnerabilities-rb' into 'master'

Resolve "Refactor re-used code in ee/lib/api/vulnerabilities.rb"

See merge request gitlab-org/gitlab!36227
parents 6a71a82a 07c8855f
...@@ -29,45 +29,45 @@ module API ...@@ -29,45 +29,45 @@ 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
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) render_vulnerability(@vulnerability)
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) 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) 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) 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