2015-09-28 15:19:20 +00:00
|
|
|
class Projects::VariablesController < Projects::ApplicationController
|
2017-05-03 18:51:55 +00:00
|
|
|
before_action :variable, only: [:show, :update, :destroy]
|
2016-02-01 22:58:04 +00:00
|
|
|
before_action :authorize_admin_build!
|
2015-09-28 15:19:20 +00:00
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2017-01-30 15:36:49 +00:00
|
|
|
def index
|
2017-07-06 11:18:11 +00:00
|
|
|
redirect_to project_settings_ci_cd_path(@project)
|
2017-01-30 15:36:49 +00:00
|
|
|
end
|
|
|
|
|
2015-09-28 15:19:20 +00:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-07-07 06:46:23 +00:00
|
|
|
if variable.update(variable_params)
|
2017-07-06 07:39:45 +00:00
|
|
|
redirect_to project_variables_path(project),
|
2017-07-03 16:28:55 +00:00
|
|
|
notice: 'Variable was successfully updated.'
|
2016-04-27 08:01:43 +00:00
|
|
|
else
|
2017-05-03 18:51:55 +00:00
|
|
|
render "show"
|
2016-04-27 08:01:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-07-07 06:46:23 +00:00
|
|
|
@variable = project.variables.create(variable_params)
|
2017-07-06 11:10:07 +00:00
|
|
|
.present(current_user: current_user)
|
2016-04-27 08:01:43 +00:00
|
|
|
|
2017-07-06 11:10:07 +00:00
|
|
|
if @variable.persisted?
|
2017-07-06 07:39:45 +00:00
|
|
|
redirect_to project_settings_ci_cd_path(project),
|
2017-07-06 11:10:07 +00:00
|
|
|
notice: 'Variable was successfully created.'
|
2015-09-28 15:19:20 +00:00
|
|
|
else
|
2017-02-06 19:05:20 +00:00
|
|
|
render "show"
|
2015-09-28 15:19:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-27 08:01:43 +00:00
|
|
|
def destroy
|
2017-07-04 13:27:42 +00:00
|
|
|
if variable.destroy
|
2017-07-06 11:18:11 +00:00
|
|
|
redirect_to project_settings_ci_cd_path(project),
|
2017-07-04 13:27:42 +00:00
|
|
|
status: 302,
|
|
|
|
notice: 'Variable was successfully removed.'
|
|
|
|
else
|
2017-07-06 11:18:11 +00:00
|
|
|
redirect_to project_settings_ci_cd_path(project),
|
2017-07-04 13:27:42 +00:00
|
|
|
status: 302,
|
2017-07-06 11:10:07 +00:00
|
|
|
notice: 'Failed to remove the variable.'
|
2017-07-04 13:27:42 +00:00
|
|
|
end
|
2016-04-27 08:01:43 +00:00
|
|
|
end
|
|
|
|
|
2015-09-28 15:19:20 +00:00
|
|
|
private
|
|
|
|
|
2017-07-07 06:46:23 +00:00
|
|
|
def variable_params
|
|
|
|
params.require(:variable).permit(*variable_params_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def variable_params_attributes
|
|
|
|
%i[id key value protected _destroy]
|
2017-07-06 07:45:38 +00:00
|
|
|
end
|
|
|
|
|
2017-05-03 18:51:55 +00:00
|
|
|
def variable
|
|
|
|
@variable ||= project.variables.find(params[:id]).present(current_user: current_user)
|
2015-09-28 15:19:20 +00:00
|
|
|
end
|
|
|
|
end
|