BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
45c77dac
Commit
45c77dac
authored
Feb 22, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move can_current_user_push_to_branch to Presenter
parent
31d1b2ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
tree_helper.rb
app/helpers/tree_helper.rb
+3
-1
project.rb
app/models/project.rb
+0
-6
project_presenter.rb
app/presenters/project_presenter.rb
+7
-1
No files found.
app/helpers/tree_helper.rb
View file @
45c77dac
...
...
@@ -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
)
...
...
app/models/project.rb
View file @
45c77dac
...
...
@@ -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
...
...
app/presenters/project_presenter.rb
View file @
45c77dac
...
...
@@ -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
)
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment