2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
2021-06-18 05:10:09 -04:00
|
|
|
feature_category :pipeline_authoring
|
2020-10-08 14:08:32 -04:00
|
|
|
|
2018-01-29 12:39:06 -05:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2020-07-13 17:09:24 -04:00
|
|
|
render status: :ok, json: { variables: ::Ci::VariableSerializer.new.represent(@project.variables) }
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-08-18 11:10:33 -04:00
|
|
|
update_result = Ci::ChangeVariablesService.new(
|
|
|
|
container: @project, current_user: current_user,
|
|
|
|
params: variables_params
|
|
|
|
).execute
|
|
|
|
|
|
|
|
if update_result
|
2018-02-01 15:38:41 -05:00
|
|
|
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
|
2020-07-13 17:09:24 -04:00
|
|
|
render status: :ok, json: { variables: ::Ci::VariableSerializer.new.represent(@project.variables) }
|
2018-02-06 11:56:54 -05:00
|
|
|
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
|
2019-08-08 14:51:52 -04:00
|
|
|
%i[id variable_type key secret_value protected masked environment_scope _destroy]
|
2017-07-06 03:45:38 -04:00
|
|
|
end
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|