提交 6bc3edee 编写于 作者: L Luis Del Giudice 提交者: Adam Niedzielski

Prevent more than one issue tracker to be active for the same project

上级 81ad6111
......@@ -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.'
......
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
---
title: Prevent more than one issue tracker to be active for the same project
merge_request:
author: luisdgs19
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册