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
7388a911
Commit
7388a911
authored
Dec 28, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consider all matching MRs to determine if user can push
parent
8c2172f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
14 deletions
+24
-14
app/models/project.rb
app/models/project.rb
+13
-13
spec/models/project_spec.rb
spec/models/project_spec.rb
+10
-0
spec/services/ci/retry_pipeline_service_spec.rb
spec/services/ci/retry_pipeline_service_spec.rb
+1
-1
No files found.
app/models/project.rb
View file @
7388a911
...
...
@@ -1933,14 +1933,8 @@ class Project < ActiveRecord::Base
def
any_branch_allows_collaboration?
(
user
)
return
false
unless
user
return
false
if
empty_repo?
# Issue for N+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/49322
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
merge_requests_allowing_collaboration
.
any?
do
|
merge_request
|
merge_request
.
can_be_merged_by?
(
user
)
end
end
fetch_branch_allows_collaboration
(
user
)
end
def
branch_allows_collaboration?
(
user
,
branch_name
)
...
...
@@ -1950,7 +1944,7 @@ class Project < ActiveRecord::Base
memoized_results
=
strong_memoize
(
:branch_allows_collaboration
)
do
Hash
.
new
do
|
result
,
cache_key
|
result
[
cache_key
]
=
fetch_branch_allows_collaboration
?
(
user
,
branch_name
)
result
[
cache_key
]
=
fetch_branch_allows_collaboration
(
user
,
branch_name
)
end
end
...
...
@@ -2028,8 +2022,10 @@ class Project < ActiveRecord::Base
private
def
merge_requests_allowing_collaboration
source_of_merge_requests
.
opened
.
where
(
allow_collaboration:
true
)
def
merge_requests_allowing_collaboration
(
source_branch
=
nil
)
relation
=
source_of_merge_requests
.
opened
.
where
(
allow_collaboration:
true
)
relation
=
relation
.
where
(
source_branch:
source_branch
)
if
source_branch
relation
end
def
create_new_pool_repository
...
...
@@ -2156,12 +2152,16 @@ class Project < ActiveRecord::Base
raise
ex
end
def
fetch_branch_allows_collaboration
?
(
user
,
branch_name
)
def
fetch_branch_allows_collaboration
(
user
,
branch_name
=
nil
)
Gitlab
::
SafeRequestStore
.
fetch
(
"project-
#{
id
}
:branch-
#{
branch_name
}
:user-
#{
user
.
id
}
:branch_allows_collaboration"
)
do
next
false
if
empty_repo?
merge_request
=
merge_requests_allowing_collaboration
.
find_by
(
source_branch:
branch_name
)
merge_request
&
.
can_be_merged_by?
(
user
)
# Issue for N+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/49322
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
merge_requests_allowing_collaboration
(
branch_name
).
any?
do
|
merge_request
|
merge_request
.
can_be_merged_by?
(
user
)
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
7388a911
...
...
@@ -3831,6 +3831,16 @@ describe Project do
let
(
:user
)
{
create
(
:user
)
}
let
(
:target_project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
fork_project
(
target_project
,
nil
,
repository:
true
)
}
let!
(
:local_merge_request
)
do
create
(
:merge_request
,
target_project:
project
,
target_branch:
'target-branch'
,
source_project:
project
,
source_branch:
'awesome-feature-1'
,
allow_collaboration:
true
)
end
let!
(
:merge_request
)
do
create
(
:merge_request
,
...
...
spec/services/ci/retry_pipeline_service_spec.rb
View file @
7388a911
...
...
@@ -285,7 +285,7 @@ describe Ci::RetryPipelineService, '#execute' do
end
it
'allows to retry failed pipeline'
do
allow_any_instance_of
(
Project
).
to
receive
(
:
fetch_
branch_allows_collaboration?
).
and_return
(
true
)
allow_any_instance_of
(
Project
).
to
receive
(
:branch_allows_collaboration?
).
and_return
(
true
)
allow_any_instance_of
(
Project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
service
.
execute
(
pipeline
)
...
...
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