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
32eeaa6e
Commit
32eeaa6e
authored
Jan 15, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove any-approval rule for MR when a regular is created
parent
bf470fc9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
34 deletions
+42
-34
ee/app/services/approval_rules/create_service.rb
ee/app/services/approval_rules/create_service.rb
+3
-3
ee/spec/services/approval_rules/create_service_spec.rb
ee/spec/services/approval_rules/create_service_spec.rb
+39
-31
No files found.
ee/app/services/approval_rules/create_service.rb
View file @
32eeaa6e
...
...
@@ -14,7 +14,7 @@ module ApprovalRules
params
.
reverse_merge!
(
rule_type: :report_approver
)
end
handle_any_approver_rule_creation
(
target
,
params
)
if
target
.
is_a?
(
Project
)
handle_any_approver_rule_creation
(
target
,
@rule
.
project
,
params
)
copy_approval_project_rule_properties
(
params
)
if
target
.
is_a?
(
MergeRequest
)
super
(
@rule
.
project
,
user
,
params
)
...
...
@@ -38,14 +38,14 @@ module ApprovalRules
params
[
:groups
]
=
approval_project_rule
.
groups
end
def
handle_any_approver_rule_creation
(
target
,
params
)
def
handle_any_approver_rule_creation
(
target
,
p
roject
,
p
arams
)
if
params
[
:user_ids
].
blank?
&&
params
[
:group_ids
].
blank?
params
.
reverse_merge!
(
rule_type: :any_approver
,
name:
ApprovalRuleLike
::
ALL_MEMBERS
)
return
end
return
if
targe
t
.
multiple_approval_rules_available?
return
if
projec
t
.
multiple_approval_rules_available?
target
.
approval_rules
.
any_approver
.
delete_all
end
...
...
ee/spec/services/approval_rules/create_service_spec.rb
View file @
32eeaa6e
...
...
@@ -76,6 +76,45 @@ describe ApprovalRules::CreateService do
expect
(
result
[
:message
]).
to
include
(
'Prohibited'
)
end
end
context
'when approval rule with empty users and groups is being created'
do
subject
{
described_class
.
new
(
target
,
user
,
{
user_ids:
[],
group_ids:
[]
})
}
it
'sets default attributes for any-approver rule'
do
rule
=
subject
.
execute
[
:rule
]
expect
(
rule
[
:rule_type
]).
to
eq
(
'any_approver'
)
expect
(
rule
[
:name
]).
to
eq
(
'All Members'
)
end
end
context
'when any-approver rule exists'
do
before
do
target
.
approval_rules
.
create!
(
rule_type: :any_approver
,
name:
'All members'
)
end
context
'multiple approval rules are not enabled'
do
subject
{
described_class
.
new
(
target
,
user
,
{
user_ids:
[
1
],
group_ids:
[]
})
}
it
'removes the rule if a regular one is created'
do
expect
{
subject
.
execute
}.
to
change
(
target
.
approval_rules
.
any_approver
,
:count
).
from
(
1
).
to
(
0
)
end
end
context
'multiple approval rules are enabled'
do
subject
{
described_class
.
new
(
target
,
user
,
{
user_ids:
[
1
],
group_ids:
[]
})
}
before
do
stub_licensed_features
(
multiple_approval_rules:
true
)
end
it
'does not remove any approval rule'
do
expect
{
subject
.
execute
}.
not_to
change
(
target
.
approval_rules
.
any_approver
,
:count
)
end
end
end
end
context
'when target is project'
do
...
...
@@ -148,37 +187,6 @@ describe ApprovalRules::CreateService do
specify
{
expect
(
result
[
:rule
].
rule_type
).
to
eq
(
'report_approver'
)
}
end
end
context
'when approval rule is being created'
do
subject
{
described_class
.
new
(
target
,
user
,
{
user_ids:
[],
group_ids:
[]
})
}
it
'sets default attributes for any-approver rule'
do
rule
=
subject
.
execute
[
:rule
]
expect
(
rule
[
:rule_type
]).
to
eq
(
'any_approver'
)
expect
(
rule
[
:name
]).
to
eq
(
'All Members'
)
end
end
context
'when any-approver rule exists'
do
let!
(
:any_approver_rule
)
do
create
(
:approval_project_rule
,
project:
target
,
rule_type: :any_approver
)
end
context
'multiple approval rules are not enabled'
do
subject
{
described_class
.
new
(
target
,
user
,
{
user_ids:
[
1
],
group_ids:
[]
})
}
before
do
stub_licensed_features
(
multiple_approval_rules:
false
)
end
it
'removes the rule if a regular one is created'
do
expect
{
subject
.
execute
}.
to
change
(
target
.
approval_rules
.
any_approver
,
:count
).
from
(
1
).
to
(
0
)
end
end
end
end
context
'when target is merge request'
do
...
...
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