2015-09-28 11:19:20 -04:00
|
|
|
class Projects::VariablesController < Projects::ApplicationController
|
2017-05-03 14:51:55 -04:00
|
|
|
before_action :variable, only: [:show, :update, :destroy]
|
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-05-03 14:51:55 -04:00
|
|
|
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
|
2017-01-30 10:36:49 -05:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:19:20 -04:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-05-03 14:51:55 -04:00
|
|
|
if @variable.update(project_params)
|
2017-07-03 12:28:55 -04:00
|
|
|
redirect_to namespace_project_variables_path(project.namespace, project),
|
|
|
|
notice: 'Variable was successfully updated.'
|
2016-04-27 04:01:43 -04:00
|
|
|
else
|
2017-05-03 14:51:55 -04:00
|
|
|
render "show"
|
2016-04-27 04:01:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-07-04 09:27:42 -04:00
|
|
|
new_variable = project.variables.create(project_params)
|
2016-04-27 04:01:43 -04:00
|
|
|
|
2017-07-04 09:27:42 -04:00
|
|
|
if new_variable.persisted?
|
2017-07-03 12:28:55 -04:00
|
|
|
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project),
|
|
|
|
notice: 'Variables were successfully updated.'
|
2015-09-28 11:19:20 -04:00
|
|
|
else
|
2017-07-03 12:28:55 -04:00
|
|
|
@variable = new_variable.present(current_user: current_user)
|
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
|
2017-07-04 09:27:42 -04:00
|
|
|
if variable.destroy
|
|
|
|
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project),
|
|
|
|
status: 302,
|
|
|
|
notice: 'Variable was successfully removed.'
|
|
|
|
else
|
|
|
|
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project),
|
|
|
|
status: 302,
|
|
|
|
notice: 'Failed to remove the variable'
|
|
|
|
end
|
2016-04-27 04:01:43 -04:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:19:20 -04:00
|
|
|
private
|
|
|
|
|
2017-05-03 14:51:55 -04:00
|
|
|
def project_params
|
2017-07-03 12:28:55 -04:00
|
|
|
params.require(:variable).permit([:id, :key, :value, :protected, :_destroy])
|
2017-07-06 03:45:38 -04:00
|
|
|
end
|
|
|
|
|
2017-05-03 14:51:55 -04:00
|
|
|
def variable
|
|
|
|
@variable ||= project.variables.find(params[:id]).present(current_user: current_user)
|
2015-09-28 11:19:20 -04:00
|
|
|
end
|
|
|
|
end
|