2017-05-03 14:51:55 -04:00
|
|
|
module Groups
|
|
|
|
class VariablesController < Groups::ApplicationController
|
|
|
|
before_action :authorize_admin_build!
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
skip_cross_project_access_check :show, :update
|
|
|
|
|
2018-01-29 12:54:16 -05:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2018-01-29 20:14:39 -05:00
|
|
|
render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) }
|
2018-01-29 12:54:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-02-06 11:56:54 -05:00
|
|
|
if @group.update(group_variables_params)
|
2018-02-01 15:38:41 -05:00
|
|
|
respond_to do |format|
|
2018-02-06 11:56:54 -05:00
|
|
|
format.json { return 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
|
|
|
|
render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_error
|
|
|
|
render status: :bad_request, json: @group.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_variables_params
|
2018-01-23 13:24:55 -05:00
|
|
|
params.permit(variables_attributes: [*variable_params_attributes])
|
|
|
|
end
|
|
|
|
|
2017-07-07 04:14:29 -04:00
|
|
|
def variable_params_attributes
|
2018-01-23 13:24:55 -05:00
|
|
|
%i[id key value protected _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
|