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
5c3c4ba6
Commit
5c3c4ba6
authored
Jan 17, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add app validation for any-approver rule uniqueness
This would save us from 500 error raised by database
parent
7467e0ae
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
8 deletions
+21
-8
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+1
-0
ee/app/models/approval_project_rule.rb
ee/app/models/approval_project_rule.rb
+1
-0
ee/changelogs/unreleased/id-validate-any-approval-rule-uniqueness.yml
...s/unreleased/id-validate-any-approval-rule-uniqueness.yml
+5
-0
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+4
-6
ee/spec/models/approval_project_rule_spec.rb
ee/spec/models/approval_project_rule_spec.rb
+4
-2
locale/gitlab.pot
locale/gitlab.pot
+6
-0
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
5c3c4ba6
...
@@ -24,6 +24,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
...
@@ -24,6 +24,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
end
end
validates
:name
,
uniqueness:
{
scope:
[
:merge_request
,
:code_owner
]
}
validates
:name
,
uniqueness:
{
scope:
[
:merge_request
,
:code_owner
]
}
validates
:rule_type
,
uniqueness:
{
scope: :merge_request_id
,
message:
proc
{
_
(
'any-approver for the merge request already exists'
)
}
},
if: :any_approver?
validates
:report_type
,
presence:
true
,
if: :report_approver?
validates
:report_type
,
presence:
true
,
if: :report_approver?
# Temporary validations until `code_owner` can be dropped in favor of `rule_type`
# Temporary validations until `code_owner` can be dropped in favor of `rule_type`
# To be removed with https://gitlab.com/gitlab-org/gitlab/issues/11834
# To be removed with https://gitlab.com/gitlab-org/gitlab/issues/11834
...
...
ee/app/models/approval_project_rule.rb
View file @
5c3c4ba6
...
@@ -17,6 +17,7 @@ class ApprovalProjectRule < ApplicationRecord
...
@@ -17,6 +17,7 @@ class ApprovalProjectRule < ApplicationRecord
validate
:validate_default_license_report_name
,
on: :update
,
if: :report_approver?
validate
:validate_default_license_report_name
,
on: :update
,
if: :report_approver?
validates
:name
,
uniqueness:
{
scope: :project_id
}
validates
:name
,
uniqueness:
{
scope: :project_id
}
validates
:rule_type
,
uniqueness:
{
scope: :project_id
,
message:
proc
{
_
(
'any-approver for the project already exists'
)
}
},
if: :any_approver?
def
self
.
applicable_to_branch
(
branch
)
def
self
.
applicable_to_branch
(
branch
)
includes
(
:protected_branches
).
select
{
|
rule
|
rule
.
applies_to_branch?
(
branch
)
}
includes
(
:protected_branches
).
select
{
|
rule
|
rule
.
applies_to_branch?
(
branch
)
}
...
...
ee/changelogs/unreleased/id-validate-any-approval-rule-uniqueness.yml
0 → 100644
View file @
5c3c4ba6
---
title
:
Add app validation for any-approver rule uniqueness
merge_request
:
23241
author
:
type
:
fixed
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
5c3c4ba6
...
@@ -92,14 +92,12 @@ describe ApprovalMergeRequestRule do
...
@@ -92,14 +92,12 @@ describe ApprovalMergeRequestRule do
context
'any_approver rules'
do
context
'any_approver rules'
do
let
(
:rule
)
{
build
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
rule_type: :any_approver
)
}
let
(
:rule
)
{
build
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
rule_type: :any_approver
)
}
it
'is valid'
do
it
'creating only one any_approver rule is allowed'
do
expect
(
rule
).
to
be_valid
end
it
'creating more than one any_approver rule raises an error'
do
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
rule_type: :any_approver
)
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
rule_type: :any_approver
)
expect
{
rule
.
save
}.
to
raise_error
(
ActiveRecord
::
RecordNotUnique
)
expect
(
rule
).
not_to
be_valid
expect
(
rule
.
errors
.
messages
).
to
eq
(
rule_type:
[
'any-approver for the merge request already exists'
])
expect
{
rule
.
save
(
validate:
false
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotUnique
)
end
end
end
end
end
end
...
...
ee/spec/models/approval_project_rule_spec.rb
View file @
5c3c4ba6
...
@@ -141,10 +141,12 @@ describe ApprovalProjectRule do
...
@@ -141,10 +141,12 @@ describe ApprovalProjectRule do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:rule
)
{
build
(
:approval_project_rule
,
project:
project
,
rule_type: :any_approver
)
}
let
(
:rule
)
{
build
(
:approval_project_rule
,
project:
project
,
rule_type: :any_approver
)
}
it
'creating
more than one any_approver rule raises an error
'
do
it
'creating
only one any_approver rule is allowed
'
do
create
(
:approval_project_rule
,
project:
project
,
rule_type: :any_approver
)
create
(
:approval_project_rule
,
project:
project
,
rule_type: :any_approver
)
expect
{
rule
.
save
}.
to
raise_error
(
ActiveRecord
::
RecordNotUnique
)
expect
(
rule
).
not_to
be_valid
expect
(
rule
.
errors
.
messages
).
to
eq
(
rule_type:
[
'any-approver for the project already exists'
])
expect
{
rule
.
save
(
validate:
false
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotUnique
)
end
end
end
end
...
...
locale/gitlab.pot
View file @
5c3c4ba6
...
@@ -21766,6 +21766,12 @@ msgstr ""
...
@@ -21766,6 +21766,12 @@ msgstr ""
msgid "and"
msgid "and"
msgstr ""
msgstr ""
msgid "any-approver for the merge request already exists"
msgstr ""
msgid "any-approver for the project already exists"
msgstr ""
msgid "archived"
msgid "archived"
msgstr ""
msgstr ""
...
...
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