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
f8af7854
Commit
f8af7854
authored
Aug 07, 2020
by
Arturo Herrero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate service belongs to project or group
parent
81fa9f67
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
app/models/service.rb
app/models/service.rb
+5
-0
spec/models/service_spec.rb
spec/models/service_spec.rb
+1
-0
No files found.
app/models/service.rb
View file @
f8af7854
...
...
@@ -57,6 +57,7 @@ class Service < ApplicationRecord
validates
:template
,
uniqueness:
{
scope: :type
},
if:
->
{
template?
}
validates
:instance
,
uniqueness:
{
scope: :type
},
if:
->
{
instance?
}
validate
:validate_is_instance_or_template
validate
:validate_belongs_to_project_or_group
scope
:external_issue_trackers
,
->
{
where
(
category:
'issue_tracker'
).
active
}
scope
:external_wikis
,
->
{
where
(
type:
'ExternalWikiService'
).
active
}
...
...
@@ -379,6 +380,10 @@ class Service < ApplicationRecord
errors
.
add
(
:template
,
'The service should be a service template or instance-level integration'
)
if
template?
&&
instance?
end
def
validate_belongs_to_project_or_group
errors
.
add
(
:project_id
,
'The service should belongs to a project or group'
)
if
project_id
&&
group_id
end
def
cache_project_has_external_issue_tracker
if
project
&&
!
project
.
destroyed?
project
.
cache_has_external_issue_tracker
...
...
spec/models/service_spec.rb
View file @
f8af7854
...
...
@@ -25,6 +25,7 @@ RSpec.describe Service do
nil
|
nil
|
false
|
true
|
true
nil
|
nil
|
false
|
false
|
false
nil
|
nil
|
true
|
true
|
false
1
|
1
|
false
|
false
|
false
1
|
nil
|
true
|
false
|
false
1
|
nil
|
false
|
true
|
false
nil
|
1
|
true
|
false
|
false
...
...
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