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
579e57dd
Commit
579e57dd
authored
Feb 25, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scope name uniqueness of approval rules to type
This will allow to create All Members regular rule
parent
ab614380
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
3 deletions
+14
-3
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+1
-1
ee/app/models/approval_project_rule.rb
ee/app/models/approval_project_rule.rb
+1
-1
ee/changelogs/unreleased/id-scope-name-validation-for-approval-rules.yml
...nreleased/id-scope-name-validation-for-approval-rules.yml
+5
-0
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+4
-0
ee/spec/models/approval_project_rule_spec.rb
ee/spec/models/approval_project_rule_spec.rb
+3
-1
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
579e57dd
...
@@ -23,7 +23,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
...
@@ -23,7 +23,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
end
end
end
end
validates
:name
,
uniqueness:
{
scope:
[
:merge_request
,
:code_owner
]
}
validates
:name
,
uniqueness:
{
scope:
[
:merge_request
_id
,
:rule_type
]
}
validates
:rule_type
,
uniqueness:
{
scope: :merge_request_id
,
message:
proc
{
_
(
'any-approver for the merge request already exists'
)
}
},
if: :any_approver?
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`
...
...
ee/app/models/approval_project_rule.rb
View file @
579e57dd
...
@@ -16,7 +16,7 @@ class ApprovalProjectRule < ApplicationRecord
...
@@ -16,7 +16,7 @@ class ApprovalProjectRule < ApplicationRecord
alias_method
:code_owner
,
:code_owner?
alias_method
:code_owner
,
:code_owner?
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
,
:rule_type
]
}
validates
:rule_type
,
uniqueness:
{
scope: :project_id
,
message:
proc
{
_
(
'any-approver for the project already exists'
)
}
},
if: :any_approver?
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
)
...
...
ee/changelogs/unreleased/id-scope-name-validation-for-approval-rules.yml
0 → 100644
View file @
579e57dd
---
title
:
Scope name uniqueness of approval rules to type
merge_request
:
25875
author
:
type
:
fixed
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
579e57dd
...
@@ -16,6 +16,10 @@ describe ApprovalMergeRequestRule do
...
@@ -16,6 +16,10 @@ describe ApprovalMergeRequestRule do
expect
(
build
(
:approval_merge_request_rule
,
name:
nil
)).
not_to
be_valid
expect
(
build
(
:approval_merge_request_rule
,
name:
nil
)).
not_to
be_valid
end
end
it
'is invalid when name not unique within rule type and merge request'
do
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
([
:merge_request_id
,
:rule_type
])
end
context
'approval_project_rule is set'
do
context
'approval_project_rule is set'
do
let
(
:approval_project_rule
)
{
build
(
:approval_project_rule
)
}
let
(
:approval_project_rule
)
{
build
(
:approval_project_rule
)
}
let
(
:merge_request_rule
)
{
build
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
approval_project_rule:
approval_project_rule
)
}
let
(
:merge_request_rule
)
{
build
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
approval_project_rule:
approval_project_rule
)
}
...
...
ee/spec/models/approval_project_rule_spec.rb
View file @
579e57dd
...
@@ -6,7 +6,9 @@ describe ApprovalProjectRule do
...
@@ -6,7 +6,9 @@ describe ApprovalProjectRule do
subject
{
create
(
:approval_project_rule
)
}
subject
{
create
(
:approval_project_rule
)
}
describe
'validations'
do
describe
'validations'
do
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
'is invalid when name not unique within rule type and project'
do
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
([
:project_id
,
:rule_type
])
end
end
end
describe
'.regular'
do
describe
'.regular'
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