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
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2017-01-30 10:36:49 -05:00
|
|
|
def index
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project)
|
2017-01-30 10:36:49 -05:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:19:20 -04:00
|
|
|
def show
|
2016-04-27 04:01:43 -04:00
|
|
|
@variable = @project.variables.find(params[:id])
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-04-27 04:01:43 -04:00
|
|
|
@variable = @project.variables.find(params[:id])
|
|
|
|
|
2017-07-06 03:45:38 -04:00
|
|
|
if @variable.update_attributes(variable_params)
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_variables_path(project), notice: 'Variable was successfully updated.'
|
2016-04-27 04:01:43 -04:00
|
|
|
else
|
2017-02-03 17:51:34 -05:00
|
|
|
render action: "show"
|
2016-04-27 04:01:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-07-06 03:45:38 -04:00
|
|
|
@variable = @project.variables.new(variable_params)
|
2016-04-27 04:01:43 -04:00
|
|
|
|
2017-07-06 03:45:38 -04:00
|
|
|
if @variable.save
|
2017-02-01 16:29:55 -05:00
|
|
|
flash[:notice] = 'Variables were successfully updated.'
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(project)
|
2015-09-28 11:19:20 -04:00
|
|
|
else
|
2017-02-06 14:05:20 -05:00
|
|
|
render "show"
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-27 04:01:43 -04:00
|
|
|
def destroy
|
|
|
|
@key = @project.variables.find(params[:id])
|
|
|
|
@key.destroy
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(project),
|
2017-06-06 18:45:16 -04:00
|
|
|
status: 302,
|
|
|
|
notice: 'Variable was successfully removed.'
|
2016-04-27 04:01:43 -04:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:19:20 -04:00
|
|
|
private
|
|
|
|
|
2017-07-06 03:45:38 -04:00
|
|
|
def variable_params
|
|
|
|
params.require(:variable).permit(*variable_params_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def variable_params_attributes
|
|
|
|
%i[id key value protected _destroy]
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|
|
|
|
end
|