Commit 36fa5d66 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'grapify-to-h' into 'master'

Use to_h to convert params to a hash

See merge request !7406
parents 7e34f7fc 510092c8
...@@ -23,6 +23,11 @@ module API ...@@ -23,6 +23,11 @@ module API
warden.try(:authenticate) if %w[GET HEAD].include?(env['REQUEST_METHOD']) warden.try(:authenticate) if %w[GET HEAD].include?(env['REQUEST_METHOD'])
end end
def declared_params(options = {})
options = { include_parent_namespaces: false }.merge(options)
declared(params, options).to_h.symbolize_keys
end
def find_user_by_private_token def find_user_by_private_token
token = private_token token = private_token
return nil unless token.present? return nil unless token.present?
......
...@@ -62,9 +62,8 @@ module API ...@@ -62,9 +62,8 @@ module API
end end
post ":id/milestones" do post ":id/milestones" do
authorize! :admin_milestone, user_project authorize! :admin_milestone, user_project
milestone_params = declared(params, include_parent_namespaces: false)
milestone = ::Milestones::CreateService.new(user_project, current_user, milestone_params).execute milestone = ::Milestones::CreateService.new(user_project, current_user, declared_params).execute
if milestone.valid? if milestone.valid?
present milestone, with: Entities::Milestone present milestone, with: Entities::Milestone
...@@ -86,9 +85,9 @@ module API ...@@ -86,9 +85,9 @@ module API
end end
put ":id/milestones/:milestone_id" do put ":id/milestones/:milestone_id" do
authorize! :admin_milestone, user_project authorize! :admin_milestone, user_project
milestone_params = declared(params, include_parent_namespaces: false, include_missing: false) milestone = user_project.milestones.find(params.delete(:milestone_id))
milestone = user_project.milestones.find(milestone_params.delete(:milestone_id)) milestone_params = declared_params(include_missing: false)
milestone = ::Milestones::UpdateService.new(user_project, current_user, milestone_params).execute(milestone) milestone = ::Milestones::UpdateService.new(user_project, current_user, milestone_params).execute(milestone)
if milestone.valid? if milestone.valid?
......
...@@ -57,9 +57,7 @@ module API ...@@ -57,9 +57,7 @@ module API
runner = get_runner(params.delete(:id)) runner = get_runner(params.delete(:id))
authenticate_update_runner!(runner) authenticate_update_runner!(runner)
runner_params = declared(params, include_missing: false) if runner.update(declared_params(include_missing: false))
if runner.update(runner_params)
present runner, with: Entities::RunnerDetails, current_user: current_user present runner, with: Entities::RunnerDetails, current_user: current_user
else else
render_validation_error!(runner) render_validation_error!(runner)
......
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