module Groups
class VariablesController < Groups::ApplicationController
before_action :variable, only: [:show, :update, :destroy]
before_action :authorize_admin_build!
def index
redirect_to group_settings_ci_cd_path(group)
end
def show
def update
if variable.update(variable_params)
redirect_to group_variables_path(group),
notice: 'Variable was successfully updated.'
else
render "show"
def create
@variable = group.variables.create(variable_params)
.present(current_user: current_user)
if @variable.persisted?
redirect_to group_settings_ci_cd_path(group),
notice: 'Variable was successfully created.'
def destroy
if variable.destroy
status: 302,
notice: 'Variable was successfully removed.'
notice: 'Failed to remove the variable.'
private
def variable_params
params.require(:variable).permit(*variable_params_attributes)
def variable_params_attributes
%i[key value protected]
def variable
@variable ||= group.variables.find(params[:id]).present(current_user: current_user)
def authorize_admin_build!
return render_404 unless can?(current_user, :admin_build, group)