2015-09-28 15:19:20 +00:00
|
|
|
class Projects::VariablesController < Projects::ApplicationController
|
2016-02-01 22:58:04 +00:00
|
|
|
before_action :authorize_admin_build!
|
2015-09-28 15:19:20 +00:00
|
|
|
|
2018-01-29 17:39:06 +00:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2018-01-30 01:14:39 +00:00
|
|
|
render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
|
2018-01-29 17:39:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-01-13 00:46:43 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2018-01-29 23:44:53 +00:00
|
|
|
if @project.update(variables_params)
|
2018-01-30 01:14:39 +00:00
|
|
|
return render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
|
2018-01-29 23:44:53 +00:00
|
|
|
end
|
2018-01-13 00:46:43 +00:00
|
|
|
|
2018-01-25 11:59:52 +00:00
|
|
|
render status: :bad_request, json: @project.errors.full_messages
|
2018-01-13 00:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
2018-01-12 21:39:42 +00:00
|
|
|
end
|
|
|
|
|
2015-09-28 15:19:20 +00:00
|
|
|
private
|
|
|
|
|
2018-01-13 00:46:43 +00:00
|
|
|
def variables_params
|
2018-01-23 00:17:40 +00:00
|
|
|
params.permit(variables_attributes: [*variable_params_attributes])
|
2018-01-13 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2017-07-07 06:46:23 +00:00
|
|
|
def variable_params_attributes
|
|
|
|
%i[id key value protected _destroy]
|
2017-07-06 07:45:38 +00:00
|
|
|
end
|
2015-09-28 15:19:20 +00:00
|
|
|
end
|