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

52 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Groups
class VariablesController < Groups::ApplicationController
before_action :authorize_admin_build!
2018-03-27 19:54:05 +05:30
skip_cross_project_access_check :show, :update
2017-09-10 17:25:29 +05:30
def show
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.json do
render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) }
end
end
2017-09-10 17:25:29 +05:30
end
def update
2018-03-17 18:26:18 +05:30
if @group.update(group_variables_params)
respond_to do |format|
2018-10-15 14:42:47 +05:30
format.json { render_group_variables }
2018-03-17 18:26:18 +05:30
end
2017-09-10 17:25:29 +05:30
else
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.json { render_error }
end
2017-09-10 17:25:29 +05:30
end
end
2018-03-17 18:26:18 +05:30
private
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
def render_group_variables
render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) }
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
def render_error
render status: :bad_request, json: @group.errors.full_messages
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
def group_variables_params
params.permit(variables_attributes: [*variable_params_attributes])
2017-09-10 17:25:29 +05:30
end
def variable_params_attributes
2019-07-31 22:56:46 +05:30
%i[id variable_type key secret_value protected masked _destroy]
2017-09-10 17:25:29 +05:30
end
def authorize_admin_build!
return render_404 unless can?(current_user, :admin_build, group)
end
end
end