2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-03 14:51:55 -04:00
|
|
|
module Groups
|
|
|
|
class VariablesController < Groups::ApplicationController
|
2021-03-04 19:09:24 -05:00
|
|
|
before_action :authorize_admin_group!
|
2017-05-03 14:51:55 -04:00
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
skip_cross_project_access_check :show, :update
|
|
|
|
|
2020-10-06 08:08:38 -04:00
|
|
|
feature_category :continuous_integration
|
|
|
|
|
2018-01-29 12:54:16 -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::GroupVariableSerializer.new.represent(@group.variables) }
|
2018-01-29 12:54:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-07-30 11:09:40 -04:00
|
|
|
update_result = Ci::ChangeVariablesService.new(
|
|
|
|
container: @group, current_user: current_user,
|
|
|
|
params: group_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_group_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-23 13:24:55 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-03 14:51:55 -04:00
|
|
|
private
|
|
|
|
|
2018-02-06 11:56:54 -05:00
|
|
|
def render_group_variables
|
2020-07-13 17:09:24 -04:00
|
|
|
render status: :ok, json: { variables: ::Ci::GroupVariableSerializer.new.represent(@group.variables) }
|
2018-02-06 11:56:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_error
|
|
|
|
render status: :bad_request, json: @group.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_variables_params
|
2018-03-17 07:17:40 -04:00
|
|
|
params.permit(variables_attributes: [*variable_params_attributes])
|
2018-01-23 13:24:55 -05:00
|
|
|
end
|
|
|
|
|
2017-07-07 04:14:29 -04:00
|
|
|
def variable_params_attributes
|
2019-05-06 09:11:42 -04:00
|
|
|
%i[id variable_type key secret_value protected masked _destroy]
|
2017-05-03 14:51:55 -04:00
|
|
|
end
|
|
|
|
|
2017-07-07 04:14:29 -04:00
|
|
|
def authorize_admin_build!
|
|
|
|
return render_404 unless can?(current_user, :admin_build, group)
|
|
|
|
end
|
2017-05-03 14:51:55 -04:00
|
|
|
end
|
|
|
|
end
|