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-05-03 18:51:55 +00:00
|
|
|
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
|
2017-01-30 15:36:49 +00:00
|
|
|
end
|
|
|
|
|
2015-09-28 15:19:20 +00:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-05-03 18:51:55 +00:00
|
|
|
if @variable.update(project_params)
|
2017-07-03 16:28:55 +00:00
|
|
|
redirect_to namespace_project_variables_path(project.namespace, project),
|
|
|
|
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-03 16:28:55 +00:00
|
|
|
new_variable = Ci::Variable.new(project_params)
|
2016-04-27 08:01:43 +00:00
|
|
|
|
2017-07-03 16:28:55 +00:00
|
|
|
if new_variable.valid? && @project.variables << new_variable
|
|
|
|
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project),
|
|
|
|
notice: 'Variables were successfully updated.'
|
2015-09-28 15:19:20 +00:00
|
|
|
else
|
2017-07-03 16:28:55 +00:00
|
|
|
@variable = new_variable.present(current_user: current_user)
|
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-05-03 18:51:55 +00:00
|
|
|
variable.destroy
|
2016-04-27 08:01:43 +00:00
|
|
|
|
2017-05-03 18:51:55 +00:00
|
|
|
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project),
|
2017-06-06 22:45:16 +00:00
|
|
|
status: 302,
|
|
|
|
notice: 'Variable was successfully removed.'
|
2016-04-27 08:01:43 +00:00
|
|
|
end
|
|
|
|
|
2015-09-28 15:19:20 +00:00
|
|
|
private
|
|
|
|
|
2017-05-03 18:51:55 +00:00
|
|
|
def project_params
|
2017-07-03 16:28:55 +00:00
|
|
|
params.require(:variable).permit([: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
|