GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

protected_branches_controller.rb 1.64 KB
Newer Older
1
class Projects::ProtectedBranchesController < Projects::ApplicationController
2
  # Authorize
3 4
  before_action :require_non_empty_project
  before_action :authorize_admin_project!
5
  before_action :load_protected_branch, only: [:show, :update, :destroy]
6

7
  layout "project_settings"
8

9
  def index
10
    @protected_branches = @project.protected_branches.order(:name).page(params[:page])
11
    @protected_branch = @project.protected_branches.new
12
    gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } })
13 14 15
  end

  def create
16
    @project.protected_branches.create(protected_branch_params)
Vinnie Okada's avatar
Vinnie Okada committed
17 18
    redirect_to namespace_project_protected_branches_path(@project.namespace,
                                                          @project)
19 20
  end

21 22 23
  def show
    @matching_branches = @protected_branch.matching(@project.repository.branches)
  end
24

25 26
  def update
    if @protected_branch && @protected_branch.update_attributes(protected_branch_params)
27
      respond_to do |format|
28
        format.json { render json: @protected_branch, status: :ok }
29 30 31
      end
    else
      respond_to do |format|
32
        format.json { render json: @protected_branch.errors, status: :unprocessable_entity }
33
      end
34 35 36
    end
  end

37
  def destroy
38
    @protected_branch.destroy
39 40

    respond_to do |format|
Vinnie Okada's avatar
Vinnie Okada committed
41
      format.html { redirect_to namespace_project_protected_branches_path }
42
      format.js { head :ok }
43
    end
44
  end
45 46 47

  private

48 49 50 51
  def load_protected_branch
    @protected_branch = @project.protected_branches.find(params[:id])
  end

52
  def protected_branch_params
53
    params.require(:protected_branch).permit(:name, :developers_can_push)
54
  end
55
end