Skip to content
Snippets Groups Projects
Commit 76bd0932 authored by Robert Schilling's avatar Robert Schilling
Browse files

Use declared_params helper in API

parent 36fa5d66
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -48,7 +48,7 @@ class AccessRequests < Grape::API
put ':id/access_requests/:user_id/approve' do
source = find_source(source_type, params[:id])
 
member = ::Members::ApproveAccessRequestService.new(source, current_user, declared(params)).execute
member = ::Members::ApproveAccessRequestService.new(source, current_user, declared_params).execute
 
status :created
present member.user, with: Entities::Member, member: member
Loading
Loading
Loading
Loading
@@ -36,8 +36,7 @@ def find_message
optional :font, type: String, desc: 'Foreground color'
end
post do
create_params = declared(params, include_missing: false).to_h
message = BroadcastMessage.create(create_params)
message = BroadcastMessage.create(declared_params(include_missing: false))
 
if message.persisted?
present message, with: Entities::BroadcastMessage
Loading
Loading
@@ -73,9 +72,8 @@ def find_message
end
put ':id' do
message = find_message
update_params = declared(params, include_missing: false).to_h
 
if message.update(update_params)
if message.update(declared_params(include_missing: false))
present message, with: Entities::BroadcastMessage
else
render_validation_error!(message)
Loading
Loading
Loading
Loading
@@ -53,7 +53,7 @@ class Commits < Grape::API
post ":id/repository/commits" do
authorize! :push_code, user_project
 
attrs = declared(params)
attrs = declared_params
attrs[:source_branch] = attrs[:branch_name]
attrs[:target_branch] = attrs[:branch_name]
attrs[:actions].map! do |action|
Loading
Loading
Loading
Loading
@@ -82,7 +82,7 @@ class DeployKeys < Grape::API
end
post ":id/#{path}/:key_id/enable" do
key = ::Projects::EnableDeployKeyService.new(user_project,
current_user, declared(params)).execute
current_user, declared_params).execute
 
if key
present key, with: Entities::SSHKey
Loading
Loading
Loading
Loading
@@ -32,8 +32,7 @@ class Environments < Grape::API
post ':id/environments' do
authorize! :create_environment, user_project
 
create_params = declared(params, include_parent_namespaces: false).to_h
environment = user_project.environments.create(create_params)
environment = user_project.environments.create(declared_params)
 
if environment.persisted?
present environment, with: Entities::Environment
Loading
Loading
@@ -55,8 +54,8 @@ class Environments < Grape::API
authorize! :update_environment, user_project
 
environment = user_project.environments.find(params[:environment_id])
update_params = declared(params, include_missing: false).extract!(:name, :external_url).to_h
update_params = declared_params(include_missing: false).extract!(:name, :external_url)
if environment.update(update_params)
present environment, with: Entities::Environment
else
Loading
Loading
Loading
Loading
@@ -30,10 +30,7 @@ class Labels < Grape::API
conflict!('Label already exists') if label
 
priority = params.delete(:priority)
label_params = declared(params,
include_parent_namespaces: false,
include_missing: false).to_h
label = user_project.labels.create(label_params)
label = user_project.labels.create(declared_params(include_missing: false))
 
if label.valid?
label.prioritize!(user_project, priority) if priority
Loading
Loading
@@ -77,11 +74,9 @@ class Labels < Grape::API
 
update_priority = params.key?(:priority)
priority = params.delete(:priority)
label_params = declared(params,
include_parent_namespaces: false,
include_missing: false).to_h
label_params = declared_params(include_missing: false)
# Rename new name to the actual label attribute name
label_params[:name] = label_params.delete('new_name') if label_params.key?('new_name')
label_params[:name] = label_params.delete(:new_name) if label_params.key?(:new_name)
 
render_validation_error!(label) unless label.update(label_params)
 
Loading
Loading
Loading
Loading
@@ -120,7 +120,7 @@ class Members < Grape::API
if member.nil?
{ message: "Access revoked", id: params[:user_id].to_i }
else
::Members::DestroyService.new(source, current_user, declared(params)).execute
::Members::DestroyService.new(source, current_user, declared_params).execute
 
present member.user, with: Entities::Member, member: member
end
Loading
Loading
Loading
Loading
@@ -33,10 +33,9 @@ class NotificationSettings < Grape::API
begin
notification_setting.transaction do
new_notification_email = params.delete(:notification_email)
declared_params = declared(params, include_missing: false).to_h
 
current_user.update(notification_email: new_notification_email) if new_notification_email
notification_setting.update(declared_params)
notification_setting.update(declared_params(include_missing: false))
end
rescue ArgumentError => e # catch level enum error
render_api_error! e.to_s, 400
Loading
Loading
@@ -81,9 +80,7 @@ class NotificationSettings < Grape::API
notification_setting = current_user.notification_settings_for(source)
 
begin
declared_params = declared(params, include_missing: false).to_h
notification_setting.update(declared_params)
notification_setting.update(declared_params(include_missing: false))
rescue ArgumentError => e # catch level enum error
render_api_error! e.to_s, 400
end
Loading
Loading
Loading
Loading
@@ -51,8 +51,7 @@ class ProjectHooks < Grape::API
use :project_hook_properties
end
post ":id/hooks" do
new_hook_params = declared(params, include_missing: false, include_parent_namespaces: false).to_h
hook = user_project.hooks.new(new_hook_params)
hook = user_project.hooks.new(declared_params(include_missing: false))
 
if hook.save
present hook, with: Entities::ProjectHook
Loading
Loading
@@ -71,12 +70,9 @@ class ProjectHooks < Grape::API
use :project_hook_properties
end
put ":id/hooks/:hook_id" do
hook = user_project.hooks.find(params[:hook_id])
new_params = declared(params, include_missing: false, include_parent_namespaces: false).to_h
new_params.delete('hook_id')
hook = user_project.hooks.find(params.delete(:hook_id))
 
if hook.update_attributes(new_params)
if hook.update_attributes(declared_params(include_missing: false))
present hook, with: Entities::ProjectHook
else
error!("Invalid url given", 422) if hook.errors[:url].present?
Loading
Loading
Loading
Loading
@@ -27,7 +27,7 @@ class SystemHooks < Grape::API
optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
end
post do
hook = SystemHook.new declared(params, include_missing: false).to_h
hook = SystemHook.new(declared_params(include_missing: false))
 
if hook.save
present hook, with: Entities::Hook
Loading
Loading
Loading
Loading
@@ -40,10 +40,9 @@ class Tags < Grape::API
end
post ':id/repository/tags' do
authorize_push_project
create_params = declared(params)
 
result = CreateTagService.new(user_project, current_user).
execute(create_params[:tag_name], create_params[:ref], create_params[:message], create_params[:release_description])
execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
 
if result[:status] == :success
present result[:tag],
Loading
Loading
Loading
Loading
@@ -335,7 +335,7 @@ class Users < Grape::API
requires :id, type: String, desc: 'The user ID'
end
get ':id/events' do
user = User.find_by(id: declared(params).id)
user = User.find_by(id: params[:id])
not_found!('User') unless user
 
events = user.events.
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment