Added support to ignore system id for follow up checks.

This commit is contained in:
Martin Edenhofer 2018-01-16 06:56:40 +01:00
parent 4c703fb38e
commit cef163fcc0
5 changed files with 129 additions and 0 deletions

View file

@ -81,6 +81,10 @@ module Ticket::Number::Date
ticket_hook_divider = Setting.get('ticket_hook_divider') || ''
ticket = nil
if Setting.get('ticket_number_ignore_system_id') == true
system_id = ''
end
# probe format
string.scan(/#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(\d{4,10}#{system_id}\d{2,40})/i) do
ticket = Ticket.find_by(number: $1)

View file

@ -78,6 +78,10 @@ module Ticket::Number::Increment
ticket_hook_divider = Setting.get('ticket_hook_divider') || ''
ticket = nil
if Setting.get('ticket_number_ignore_system_id') == true
system_id = ''
end
# probe format
string.scan(/#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(#{system_id}\d{2,48})/i) do
ticket = Ticket.find_by(number: $1)

View file

@ -0,0 +1,37 @@
class SettingTicketNumberIgnoreSystemIdSupport < ActiveRecord::Migration[4.2]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'Ticket Number ignore system_id',
name: 'ticket_number_ignore_system_id',
area: 'Ticket::Core',
description: '-',
options: {
form: [
{
display: 'Ignore system_id',
null: true,
name: 'ticket_number_ignore_system_id',
tag: 'boolean',
options: {
true => 'yes',
false => 'no',
},
},
],
},
state: {
ticket_number_ignore_system_id: false
},
preferences: {
permission: ['admin.ticket'],
hidden: true,
},
frontend: false
)
end
end

View file

@ -1672,6 +1672,34 @@ Setting.create_if_not_exists(
},
frontend: false
)
Setting.create_if_not_exists(
title: 'Ticket Number ignore system_id',
name: 'ticket_number_ignore_system_id',
area: 'Ticket::Core',
description: '-',
options: {
form: [
{
display: 'Ignore system_id',
null: true,
name: 'ticket_number_ignore_system_id',
tag: 'boolean',
options: {
true => 'yes',
false => 'no',
},
},
],
},
state: {
ticket_number_ignore_system_id: false
},
preferences: {
permission: ['admin.ticket'],
hidden: true,
},
frontend: false
)
Setting.create_if_not_exists(
title: 'Enable Ticket creation',

View file

@ -58,6 +58,33 @@ class TicketNumberTest < ActiveSupport::TestCase
end
test 'number check' do
Setting.set('ticket_number_increment', { checksum: false, min_size: 5 })
ticket = Ticket.create!(
title: 'test 1',
group: Group.lookup(name: 'Users'),
customer_id: 2,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
subject = ticket.subject_build(ticket.title)
ticket_check = Ticket::Number.check(subject)
assert_equal(ticket.id, ticket_check.id)
Setting.set('system_id', 999)
ticket_check = Ticket::Number.check(subject)
assert_not(ticket_check)
Setting.set('ticket_number_ignore_system_id', true)
ticket_check = Ticket::Number.check(subject)
assert_equal(ticket.id, ticket_check.id)
end
test 'date' do
Setting.set('ticket_number', 'Ticket::Number::Date')
Setting.set('ticket_number_date', { checksum: false })
@ -103,4 +130,33 @@ class TicketNumberTest < ActiveSupport::TestCase
end
test 'date check' do
Setting.set('ticket_number', 'Ticket::Number::Date')
Setting.set('ticket_number_date', { checksum: false })
ticket = Ticket.create!(
title: 'test 1',
group: Group.lookup(name: 'Users'),
customer_id: 2,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
subject = ticket.subject_build(ticket.title)
ticket_check = Ticket::Number.check(subject)
assert_equal(ticket.id, ticket_check.id)
Setting.set('system_id', 999)
ticket_check = Ticket::Number.check(subject)
assert_not(ticket_check)
Setting.set('ticket_number_ignore_system_id', true)
ticket_check = Ticket::Number.check(subject)
assert_equal(ticket.id, ticket_check.id)
end
end