Add method to API::Variables for filtering params

This allows EE to customize the parameters used in two places, without
having to modify the source code directly.
This commit is contained in:
Yorick Peterse 2019-03-04 14:50:15 +01:00
parent 3f629b8d14
commit a7004e2825
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
1 changed files with 10 additions and 0 deletions

View File

@ -7,6 +7,14 @@ module API
before { authenticate! }
before { authorize! :admin_build, user_project }
helpers do
def filter_variable_parameters(params)
# This method exists so that EE can more easily filter out certain
# parameters, without having to modify the source code directly.
params
end
end
params do
requires :id, type: String, desc: 'The ID of a project'
end
@ -50,6 +58,7 @@ module API
end
post ':id/variables' do
variable_params = declared_params(include_missing: false)
variable_params = filter_variable_parameters(variable_params)
variable = user_project.variables.create(variable_params)
@ -75,6 +84,7 @@ module API
break not_found!('Variable') unless variable
variable_params = declared_params(include_missing: false).except(:key)
variable_params = filter_variable_parameters(variable_params)
if variable.update(variable_params)
present variable, with: Entities::Variable