debian-mirror-gitlab/app/controllers/projects/variables_controller.rb

61 lines
1.4 KiB
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
class Projects::VariablesController < Projects::ApplicationController
2017-09-10 17:25:29 +05:30
before_action :variable, only: [:show, :update, :destroy]
2016-04-02 18:10:28 +05:30
before_action :authorize_admin_build!
2015-10-24 18:46:33 +05:30
layout 'project_settings'
2016-06-02 11:05:42 +05:30
def index
2017-09-10 17:25:29 +05:30
redirect_to project_settings_ci_cd_path(@project)
2016-06-02 11:05:42 +05:30
end
2015-10-24 18:46:33 +05:30
def show
end
def update
2017-09-10 17:25:29 +05:30
if variable.update(variable_params)
redirect_to project_variables_path(project),
notice: 'Variable was successfully updated.'
2016-06-02 11:05:42 +05:30
else
2017-09-10 17:25:29 +05:30
render "show"
2016-06-02 11:05:42 +05:30
end
end
def create
2017-09-10 17:25:29 +05:30
@variable = project.variables.create(variable_params)
.present(current_user: current_user)
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
if @variable.persisted?
redirect_to project_settings_ci_cd_path(project),
notice: 'Variable was successfully created.'
2015-10-24 18:46:33 +05:30
else
2017-08-17 22:00:37 +05:30
render "show"
2015-10-24 18:46:33 +05:30
end
end
2016-06-02 11:05:42 +05:30
def destroy
2017-09-10 17:25:29 +05:30
if variable.destroy
redirect_to project_settings_ci_cd_path(project),
status: 302,
notice: 'Variable was successfully removed.'
else
redirect_to project_settings_ci_cd_path(project),
status: 302,
notice: 'Failed to remove the variable.'
end
2016-06-02 11:05:42 +05:30
end
2015-10-24 18:46:33 +05:30
private
2017-09-10 17:25:29 +05:30
def variable_params
params.require(:variable).permit(*variable_params_attributes)
end
def variable_params_attributes
%i[id key value protected _destroy]
end
def variable
@variable ||= project.variables.find(params[:id]).present(current_user: current_user)
2015-10-24 18:46:33 +05:30
end
end