diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-14 13:15:58 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-14 13:15:58 +0000 |
commit | 36fa5d660df96c49484cd27695da1df6e361eb8f (patch) | |
tree | 8709c9e4945fb00cd0d57884f8126fb4dc077a99 /lib/api | |
parent | 7e34f7fcfc802dccae71f38d75707ea49e5fb4e9 (diff) | |
parent | 510092c83ad6b35dc4cc0ac1f15c643952f519b5 (diff) | |
download | gitlab-ce-36fa5d660df96c49484cd27695da1df6e361eb8f.tar.gz |
Merge branch 'grapify-to-h' into 'master'
Use to_h to convert params to a hash
See merge request !7406
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/helpers.rb | 5 | ||||
-rw-r--r-- | lib/api/milestones.rb | 7 | ||||
-rw-r--r-- | lib/api/runners.rb | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 3c9d7b1aaef..6998b6dc039 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -23,6 +23,11 @@ module API warden.try(:authenticate) if %w[GET HEAD].include?(env['REQUEST_METHOD']) 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 token = private_token return nil unless token.present? diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 8984cf8cdcd..ba4a84275bc 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -62,9 +62,8 @@ module API end post ":id/milestones" do 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? present milestone, with: Entities::Milestone @@ -86,9 +85,9 @@ module API end put ":id/milestones/:milestone_id" do 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) if milestone.valid? diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 84c19c432b0..b145cce7e3e 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -57,9 +57,7 @@ module API runner = get_runner(params.delete(:id)) authenticate_update_runner!(runner) - runner_params = declared(params, include_missing: false) - - if runner.update(runner_params) + if runner.update(declared_params(include_missing: false)) present runner, with: Entities::RunnerDetails, current_user: current_user else render_validation_error!(runner) |