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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
6bc3edee
Commit
6bc3edee
authored
Oct 08, 2016
by
Luis Del Giudice
Committed by
Adam Niedzielski
Mar 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent more than one issue tracker to be active for the same project
parent
81ad6111
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
1 deletion
+49
-1
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+2
-1
app/models/project_services/issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+11
-0
changelogs/unreleased/adam-prevent-two-issue-trackers.yml
changelogs/unreleased/adam-prevent-two-issue-trackers.yml
+4
-0
spec/models/project_services/issue_tracker_service_spec.rb
spec/models/project_services/issue_tracker_service_spec.rb
+32
-0
No files found.
app/controllers/projects/services_controller.rb
View file @
6bc3edee
...
...
@@ -13,7 +13,8 @@ class Projects::ServicesController < Projects::ApplicationController
end
def
update
if
@service
.
update_attributes
(
service_params
[
:service
])
@service
.
assign_attributes
(
service_params
[
:service
])
if
@service
.
save
(
context: :manual_change
)
redirect_to
(
edit_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
notice:
'Successfully updated.'
...
...
app/models/project_services/issue_tracker_service.rb
View file @
6bc3edee
class
IssueTrackerService
<
Service
validate
:one_issue_tracker
,
if: :activated?
,
on: :manual_change
default_value_for
:category
,
'issue_tracker'
# Pattern used to extract links from comments
...
...
@@ -92,4 +94,13 @@ class IssueTrackerService < Service
def
issues_tracker
Gitlab
.
config
.
issues_tracker
[
to_param
]
end
def
one_issue_tracker
return
if
template?
return
if
project
.
blank?
if
project
.
services
.
external_issue_trackers
.
where
.
not
(
id:
id
).
any?
errors
.
add
(
:base
,
'Another issue tracker is already in use. Only one issue tracker service can be active at a time'
)
end
end
end
changelogs/unreleased/adam-prevent-two-issue-trackers.yml
0 → 100644
View file @
6bc3edee
---
title
:
Prevent more than one issue tracker to be active for the same project
merge_request
:
author
:
luisdgs19
spec/models/project_services/issue_tracker_service_spec.rb
0 → 100644
View file @
6bc3edee
require
'spec_helper'
describe
IssueTrackerService
,
models:
true
do
describe
'Validations'
do
let
(
:project
)
{
create
:project
}
describe
'only one issue tracker per project'
do
let
(
:service
)
{
RedmineService
.
new
(
project:
project
,
active:
true
)
}
before
do
create
(
:service
,
project:
project
,
active:
true
,
category:
'issue_tracker'
)
end
context
'when service is changed manually by user'
do
it
'executes the validation'
do
valid
=
service
.
valid?
(
:manual_change
)
expect
(
valid
).
to
be_falsey
expect
(
service
.
errors
[
:base
]).
to
include
(
'Another issue tracker is already in use. Only one issue tracker service can be active at a time'
)
end
end
context
'when service is changed internally'
do
it
'does not execute the validation'
do
expect
(
service
.
valid?
).
to
be_truthy
end
end
end
end
end
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