From cef163fcc0dddb267b8ea9e759eb22d75428e87f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 16 Jan 2018 06:56:40 +0100 Subject: [PATCH] Added support to ignore system id for follow up checks. --- app/models/ticket/number/date.rb | 4 ++ app/models/ticket/number/increment.rb | 4 ++ ..._ticket_number_ignore_system_id_support.rb | 37 ++++++++++++ db/seeds/settings.rb | 28 ++++++++++ test/unit/ticket_number_test.rb | 56 +++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 db/migrate/20180116000001_setting_ticket_number_ignore_system_id_support.rb diff --git a/app/models/ticket/number/date.rb b/app/models/ticket/number/date.rb index 5dc97969c..e32b53874 100644 --- a/app/models/ticket/number/date.rb +++ b/app/models/ticket/number/date.rb @@ -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) diff --git a/app/models/ticket/number/increment.rb b/app/models/ticket/number/increment.rb index 68da1f450..0e5b0d9a7 100644 --- a/app/models/ticket/number/increment.rb +++ b/app/models/ticket/number/increment.rb @@ -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) diff --git a/db/migrate/20180116000001_setting_ticket_number_ignore_system_id_support.rb b/db/migrate/20180116000001_setting_ticket_number_ignore_system_id_support.rb new file mode 100644 index 000000000..d696691ca --- /dev/null +++ b/db/migrate/20180116000001_setting_ticket_number_ignore_system_id_support.rb @@ -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 diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 6e6f2272e..b6bf3c2a3 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -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', diff --git a/test/unit/ticket_number_test.rb b/test/unit/ticket_number_test.rb index a72019bff..d708aee70 100644 --- a/test/unit/ticket_number_test.rb +++ b/test/unit/ticket_number_test.rb @@ -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