Commit 45c77dac authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Move can_current_user_push_to_branch to Presenter

parent 31d1b2ca
...@@ -55,7 +55,9 @@ module TreeHelper ...@@ -55,7 +55,9 @@ module TreeHelper
def tree_edit_branch(project = @project, ref = @ref) def tree_edit_branch(project = @project, ref = @ref)
return unless can_edit_tree?(project, ref) return unless can_edit_tree?(project, ref)
if project.user_can_push_to_branch?(current_user, ref) project = project.present(current_user: current_user)
if project.can_current_user_push_to_branch?(ref)
ref ref
else else
project = tree_edit_project(project) project = tree_edit_project(project)
......
...@@ -1040,12 +1040,6 @@ class Project < ActiveRecord::Base ...@@ -1040,12 +1040,6 @@ class Project < ActiveRecord::Base
!ProtectedBranch.default_branch_protected? || team.max_member_access(user.id) > Gitlab::Access::DEVELOPER !ProtectedBranch.default_branch_protected? || team.max_member_access(user.id) > Gitlab::Access::DEVELOPER
end end
def user_can_push_to_branch?(user, branch_name)
return false unless repository.branch_exists?(branch_name)
::Gitlab::UserAccess.new(user, project: self).can_push_to_branch?(branch_name)
end
def forked? def forked?
return true if fork_network && fork_network.root_project != self return true if fork_network && fork_network.root_project != self
......
...@@ -164,11 +164,17 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -164,11 +164,17 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if empty_repo? if empty_repo?
can?(current_user, :push_code, project) can?(current_user, :push_code, project)
else else
user_can_push_to_branch?(current_user, default_branch) can_current_user_push_to_branch?(default_branch)
end end
end end
end end
def can_current_user_push_to_branch?(branch)
return false unless repository.branch_exists?(branch)
::Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(branch)
end
def files_anchor_data def files_anchor_data
OpenStruct.new(enabled: true, OpenStruct.new(enabled: true,
label: _('Files (%{human_size})') % { human_size: storage_counter(statistics.total_repository_size) }, label: _('Files (%{human_size})') % { human_size: storage_counter(statistics.total_repository_size) },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment