branches_controller.rb 949 Bytes
Newer Older
1 2 3 4 5
class Projects::BranchesController < Projects::ApplicationController
  # Authorize
  before_filter :authorize_read_project!
  before_filter :require_non_empty_project

6 7 8
  before_filter :authorize_code_access!
  before_filter :authorize_push!, only: [:create]
  before_filter :authorize_admin_project!, only: [:destroy]
9 10 11 12 13 14

  def index
    @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
  end

  def create
15 16 17
    @project.repository.add_branch(params[:branch_name], params[:ref])

    redirect_to project_branches_path(@project)
18 19 20
  end

  def destroy
21 22 23
    branch = @project.repository.branches.find { |branch| branch.name == params[:id] }

    if branch && @project.repository.rm_branch(branch.name)
24
      Event.create_rm_ref(@project, current_user, branch)
25
    end
26 27

    respond_to do |format|
28
      format.html { redirect_to project_branches_path(@project) }
29 30 31 32
      format.js { render nothing: true }
    end
  end
end