Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+3
-1
app/models/project.rb
app/models/project.rb
+0
-6
app/presenters/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
...
@@ -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
)
...
...
app/models/project.rb
View file @
45c77dac
...
@@ -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
...
...
app/presenters/project_presenter.rb
View file @
45c77dac
...
@@ -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
)
},
...
...
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