summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-02-22 13:56:38 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-02-22 13:59:15 -0300
commit45c77dacbc7d9d71e6a32feb0640400bd266c357 (patch)
tree128ca00f0bf1f0eed9ad3b57a41e1bf95b27aaf0
parent31d1b2ca8c338281f3fac6dd862c988b721fa39d (diff)
downloadgitlab-ce-45c77dacbc7d9d71e6a32feb0640400bd266c357.tar.gz
Move can_current_user_push_to_branch to Presenter
-rw-r--r--app/helpers/tree_helper.rb4
-rw-r--r--app/models/project.rb6
-rw-r--r--app/presenters/project_presenter.rb8
3 files changed, 10 insertions, 8 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index 0a4da0ef3fc..f5733b4b57c 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -55,7 +55,9 @@ module TreeHelper
def tree_edit_branch(project = @project, ref = @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
else
project = tree_edit_project(project)
diff --git a/app/models/project.rb b/app/models/project.rb
index 8cd5cd8ab67..4ad6f025e5c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1040,12 +1040,6 @@ class Project < ActiveRecord::Base
!ProtectedBranch.default_branch_protected? || team.max_member_access(user.id) > Gitlab::Access::DEVELOPER
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?
return true if fork_network && fork_network.root_project != self
diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb
index f850f6273a3..9db4ef63fd7 100644
--- a/app/presenters/project_presenter.rb
+++ b/app/presenters/project_presenter.rb
@@ -164,11 +164,17 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if empty_repo?
can?(current_user, :push_code, project)
else
- user_can_push_to_branch?(current_user, default_branch)
+ can_current_user_push_to_branch?(default_branch)
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
OpenStruct.new(enabled: true,
label: _('Files (%{human_size})') % { human_size: storage_counter(statistics.total_repository_size) },