BigW Consortium Gitlab

branches_helper.rb 846 Bytes
Newer Older
Dmitriy Zaporozhets committed
1 2
module BranchesHelper
  def can_remove_branch?(project, branch_name)
3 4 5 6 7 8 9 10 11
    if project.protected_branch? branch_name
      false
    elsif branch_name == project.repository.root_ref
      false
    else
      can?(current_user, :push_code, project)
    end
  end

12 13 14 15 16 17 18 19 20 21 22
  def filter_branches_path(options = {})
    exist_opts = {
      search: params[:search],
      sort: params[:sort]
    }

    options = exist_opts.merge(options)

    namespace_project_branches_path(@project.namespace, @project, @id, options)
  end

23
  def can_push_branch?(project, branch_name)
24
    return false unless project.repository.branch_exists?(branch_name)
25

26
    ::Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(branch_name)
Dmitriy Zaporozhets committed
27
  end
28 29 30 31

  def project_branches
    options_for_select(@project.repository.branch_names, @project.default_branch)
  end
Dmitriy Zaporozhets committed
32
end