Commit d70c5dc7 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Fetch payload body from params[:notification]

Fetch payload body from `params[:notification]` instead of slicing out
service params such as controller, and action names.

If the "Content-Type" header of your request is set
to "application/json", Rails will automatically load your parameters
into the params hash, which you can access as you would normally.

https://guides.rubyonrails.org/v5.2/
action_controller_overview.html#json-parameters
parent d9117a45
...@@ -19,8 +19,6 @@ module Projects ...@@ -19,8 +19,6 @@ module Projects
private private
PARAMS_TO_EXCLUDE = %w(controller action namespace_id project_id).freeze
def project_without_auth def project_without_auth
@project ||= Project @project ||= Project
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}") .find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
...@@ -36,7 +34,7 @@ module Projects ...@@ -36,7 +34,7 @@ module Projects
def notify_service def notify_service
Projects::Alerting::NotifyService Projects::Alerting::NotifyService
.new(project, current_user, permitted_params) .new(project, current_user, notification_payload)
end end
def response_status(result) def response_status(result)
...@@ -45,8 +43,8 @@ module Projects ...@@ -45,8 +43,8 @@ module Projects
result.http_status result.http_status
end end
def permitted_params def notification_payload
params.except(*PARAMS_TO_EXCLUDE).permit! params.permit![:notification]
end end
end end
end end
......
...@@ -14,8 +14,8 @@ describe Projects::Alerting::NotificationsController do ...@@ -14,8 +14,8 @@ describe Projects::Alerting::NotificationsController do
allow(Projects::Alerting::NotifyService).to receive(:new).and_return(notify_service) allow(Projects::Alerting::NotifyService).to receive(:new).and_return(notify_service)
end end
def make_request(opts = {}) def make_request(body = {})
post :create, params: project_params(opts), session: { as: :json } post :create, params: project_params, body: body.to_json, as: :json
end end
context 'when feature flag is on' do context 'when feature flag is on' do
......
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