debian-mirror-gitlab/app/controllers/projects/variables_controller.rb

42 lines
956 B
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
class Projects::VariablesController < Projects::ApplicationController
2016-04-02 18:10:28 +05:30
before_action :authorize_admin_build!
2015-10-24 18:46:33 +05:30
def show
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.json do
render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
end
end
2015-10-24 18:46:33 +05:30
end
def update
2018-03-17 18:26:18 +05:30
if @project.update(variables_params)
respond_to do |format|
format.json { return render_variables }
end
2016-06-02 11:05:42 +05:30
else
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.json { render_error }
end
2016-06-02 11:05:42 +05:30
end
end
2018-03-17 18:26:18 +05:30
private
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
def render_variables
render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) }
2015-10-24 18:46:33 +05:30
end
2018-03-17 18:26:18 +05:30
def render_error
render status: :bad_request, json: @project.errors.full_messages
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
def variables_params
params.permit(variables_attributes: [*variable_params_attributes])
2017-09-10 17:25:29 +05:30
end
def variable_params_attributes
%i[id key value protected _destroy]
end
2015-10-24 18:46:33 +05:30
end