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
afa6d080
Commit
afa6d080
authored
Dec 16, 2020
by
David Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return project approval rules if merge request approval rules is empty
parent
a825bc8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
18 deletions
+39
-18
ee/app/models/concerns/approvable.rb
ee/app/models/concerns/approvable.rb
+1
-0
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+1
-1
ee/spec/serializers/ee/user_serializer_spec.rb
ee/spec/serializers/ee/user_serializer_spec.rb
+37
-17
No files found.
ee/app/models/concerns/approvable.rb
View file @
afa6d080
...
...
@@ -17,6 +17,7 @@ module Approvable
committers_can_approve?
approvers_overwritten?
total_approvals_count
wrapped_approval_rules
}
.
freeze
delegate
(
*
FORWARDABLE_METHODS
,
to: :approval_state
)
...
...
ee/app/models/ee/merge_request.rb
View file @
afa6d080
...
...
@@ -275,7 +275,7 @@ module EE
end
def
applicable_approval_rules_for_user
(
user_id
)
approval_rules
.
applicable_to_branch
(
target_branch
)
.
select
do
|
rule
|
wrapped_approval_rules
.
select
do
|
rule
|
rule
.
approvers
.
pluck
(
:id
).
include?
(
user_id
)
end
end
...
...
ee/spec/serializers/ee/user_serializer_spec.rb
View file @
afa6d080
...
...
@@ -7,6 +7,10 @@ RSpec.describe UserSerializer do
let_it_be
(
:user2
)
{
create
(
:user
)
}
let_it_be
(
:merge_request
)
{
create
(
:merge_request
)
}
let_it_be
(
:project
)
{
merge_request
.
project
}
let_it_be
(
:protected_branch
)
{
create
(
:protected_branch
,
project:
project
,
name:
merge_request
.
target_branch
)
}
let_it_be
(
:approval_project_rule
)
do
create
(
:approval_project_rule
,
name:
'Project Rule'
,
project:
project
,
users:
[
user1
],
protected_branches:
[
protected_branch
])
end
let
(
:serializer
)
{
described_class
.
new
(
options
)
}
...
...
@@ -33,20 +37,41 @@ RSpec.describe UserSerializer do
context
'with approval_rules'
do
let
(
:options
)
{
super
().
merge
(
approval_rules:
'true'
)
}
let!
(
:approval_merge_request_rule
)
do
create
(
:approval_merge_request_rule
,
name:
'Merge Request Rule'
,
merge_request:
merge_request
,
users:
[
user1
])
context
'with merge request approval rules'
do
let!
(
:approval_merge_request_rule
)
do
create
(
:approval_merge_request_rule
,
name:
'Merge Request Rule'
,
merge_request:
merge_request
,
users:
[
user1
])
end
let!
(
:approval_code_owner_rule
)
do
create
(
:code_owner_rule
,
name:
'Code Owner Rule'
,
merge_request:
merge_request
,
users:
[
user1
])
end
it
'returns users with merge request approval rules'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
expect
(
serialized_user1
).
to
include
(
'id'
=>
user1
.
id
,
'applicable_approval_rules'
=>
[
{
'id'
=>
approval_merge_request_rule
.
id
,
'name'
=>
'Merge Request Rule'
,
'rule_type'
=>
'regular'
},
{
'id'
=>
approval_code_owner_rule
.
id
,
'name'
=>
'Code Owner Rule'
,
'rule_type'
=>
'code_owner'
}
]
)
expect
(
serialized_user2
).
to
include
(
'id'
=>
user2
.
id
,
'applicable_approval_rules'
=>
[])
end
end
it
'returns users with applicable_approval_rules'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
context
'without merge request approval rules'
do
it
'returns users with project approval rules'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
expect
(
serialized_user1
).
to
include
(
'id'
=>
user1
.
id
,
'applicable_approval_rules'
=>
[
{
'id'
=>
approval_merge_request_rule
.
id
,
'name'
=>
'Merge Request Rule'
,
'rule_type'
=>
'regular'
}
]
)
expect
(
serialized_user2
).
to
include
(
'id'
=>
user2
.
id
,
'applicable_approval_rules'
=>
[])
expect
(
serialized_user1
).
to
include
(
'id'
=>
user1
.
id
,
'applicable_approval_rules'
=>
[
{
'id'
=>
approval_project_rule
.
id
,
'name'
=>
'Project Rule'
,
'rule_type'
=>
'regular'
}
]
)
expect
(
serialized_user2
).
to
include
(
'id'
=>
user2
.
id
,
'applicable_approval_rules'
=>
[])
end
end
end
end
...
...
@@ -61,11 +86,6 @@ RSpec.describe UserSerializer do
context
'with approval_rules'
do
let
(
:options
)
{
super
().
merge
(
approval_rules:
'true'
)
}
let!
(
:protected_branch
)
{
create
(
:protected_branch
,
project:
project
,
name:
'my_branch'
)
}
let!
(
:approval_project_rule
)
do
create
(
:approval_project_rule
,
name:
'Project Rule'
,
project:
project
,
users:
[
user1
],
protected_branches:
[
protected_branch
])
end
it
'returns users with applicable_approval_rules'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
...
...
@@ -79,7 +99,7 @@ RSpec.describe UserSerializer do
end
context
'with target_branch'
do
let
(
:options
)
{
super
().
merge
(
target_branch:
'my_branch'
)
}
let
(
:options
)
{
super
().
merge
(
target_branch:
protected_branch
.
name
)
}
it
'returns users with applicable_approval_rules'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
...
...
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