2015-09-28 11:19:20 -04:00
|
|
|
class Projects::VariablesController < Projects::ApplicationController
|
2016-02-01 17:58:04 -05:00
|
|
|
before_action :authorize_admin_build!
|
2015-09-28 11:19:20 -04:00
|
|
|
|
2018-01-29 12:39:06 -05:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2018-01-29 20:14:39 -05:00
|
|
|
render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-02-01 15:38:41 -05:00
|
|
|
if @project.update(variables_params)
|
|
|
|
respond_to do |format|
|
2018-04-18 05:19:40 -04:00
|
|
|
format.json { render_variables }
|
2018-02-01 15:38:41 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
2018-02-06 11:56:54 -05:00
|
|
|
format.json { render_error }
|
2018-01-12 19:46:43 -05:00
|
|
|
end
|
|
|
|
end
|
2018-01-12 16:39:42 -05:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:19:20 -04:00
|
|
|
private
|
|
|
|
|
2018-02-06 11:56:54 -05:00
|
|
|
def render_variables
|
|
|
|
render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_error
|
|
|
|
render status: :bad_request, json: @project.errors.full_messages
|
|
|
|
end
|
|
|
|
|
2018-01-12 19:46:43 -05:00
|
|
|
def variables_params
|
2018-03-17 07:17:40 -04:00
|
|
|
params.permit(variables_attributes: [*variable_params_attributes])
|
2018-01-12 19:46:43 -05:00
|
|
|
end
|
|
|
|
|
2017-07-07 02:46:23 -04:00
|
|
|
def variable_params_attributes
|
2018-03-22 07:08:16 -04:00
|
|
|
%i[id key secret_value protected _destroy]
|
2017-07-06 03:45:38 -04:00
|
|
|
end
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|