BigW Consortium Gitlab

variables_controller.rb 1.15 KB
Newer Older
1
class Projects::VariablesController < Projects::ApplicationController
2
  before_action :authorize_admin_build!
3 4 5

  layout 'project_settings'

Phil Hughes committed
6 7 8 9
  def index
    @variable = Ci::Variable.new
  end

10
  def show
Phil Hughes committed
11
    @variable = @project.variables.find(params[:id])
12 13 14
  end

  def update
Phil Hughes committed
15 16 17 18 19 20 21 22 23 24 25 26 27
    @variable = @project.variables.find(params[:id])

    if @variable.update_attributes(project_params)
      redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variable was successfully updated.'
    else
      render action: "show"
    end
  end

  def create
    @variable = Ci::Variable.new(project_params)

    if @variable.valid? && @project.variables << @variable
28 29
      redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variables were successfully updated.'
    else
Phil Hughes committed
30
      render action: "index"
31 32 33
    end
  end

Phil Hughes committed
34 35 36 37 38 39 40
  def destroy
    @key = @project.variables.find(params[:id])
    @key.destroy

    redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variable was successfully removed.'
  end

41 42 43
  private

  def project_params
Phil Hughes committed
44
    params.require(:variable).permit([:id, :key, :value, :_destroy])
45 46
  end
end