Fixes #3641 - Migration 3.6.1 to 4.1 : No configured business hours found!
This commit is contained in:
parent
f85d2adff5
commit
d09a3c5b85
4 changed files with 33 additions and 15 deletions
|
@ -8,11 +8,14 @@ class Calendar < ApplicationModel
|
||||||
store :business_hours
|
store :business_hours
|
||||||
store :public_holidays
|
store :public_holidays
|
||||||
|
|
||||||
before_create :validate_public_holidays, :validate_hours, :fetch_ical
|
validate :validate_hours
|
||||||
after_create :sync_default, :min_one_check
|
|
||||||
before_update :validate_public_holidays, :validate_hours, :fetch_ical
|
before_save :ensure_public_holidays_details, :fetch_ical
|
||||||
after_update :sync_default, :min_one_check
|
|
||||||
after_destroy :min_one_check
|
after_destroy :min_one_check
|
||||||
|
after_save :min_one_check
|
||||||
|
|
||||||
|
after_save :sync_default
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
@ -391,8 +394,8 @@ returns
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# validate format of public holidays
|
# ensure integrity of details of public holidays
|
||||||
def validate_public_holidays
|
def ensure_public_holidays_details
|
||||||
|
|
||||||
# fillup feed info
|
# fillup feed info
|
||||||
before = public_holidays_was
|
before = public_holidays_was
|
||||||
|
@ -414,7 +417,13 @@ returns
|
||||||
|
|
||||||
# get business hours
|
# get business hours
|
||||||
hours = business_hours_to_hash
|
hours = business_hours_to_hash
|
||||||
raise Exceptions::UnprocessableEntity, 'No configured business hours found!' if hours.blank?
|
|
||||||
|
if hours.blank?
|
||||||
|
errors.add :base, 'No configured business hours found!'
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
#raise Exceptions::UnprocessableEntity, 'No configured business hours found!' if hours.blank?
|
||||||
|
|
||||||
# validate if business hours are usable by execute a try calculation
|
# validate if business hours are usable by execute a try calculation
|
||||||
begin
|
begin
|
||||||
|
@ -423,10 +432,8 @@ returns
|
||||||
end
|
end
|
||||||
Biz.time(10, :minutes).after(Time.zone.parse('Tue, 05 Feb 2019 21:40:28 UTC +00:00'))
|
Biz.time(10, :minutes).after(Time.zone.parse('Tue, 05 Feb 2019 21:40:28 UTC +00:00'))
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Exceptions::UnprocessableEntity, e.message
|
errors.add :base, e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,10 @@ class Issue3618GoogleCalendarUrlHttps < ActiveRecord::Migration[5.2]
|
||||||
Calendar
|
Calendar
|
||||||
.where('ical_url LIKE ?', 'http://www.google.com/calendar/ical/%')
|
.where('ical_url LIKE ?', 'http://www.google.com/calendar/ical/%')
|
||||||
.each do |calendar|
|
.each do |calendar|
|
||||||
calendar.ical_url.sub!(%r{^http://}, 'https://')
|
new_url = calendar.ical_url.sub(%r{^http://}, 'https://')
|
||||||
calendar.save
|
# skipping validation allows to update old misconfigured calendar
|
||||||
|
# https://github.com/zammad/zammad/issues/3641
|
||||||
|
calendar.update_attribute :ical_url, new_url # rubocop:disable Rails/SkipsModelValidations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,4 +12,13 @@ RSpec.describe Issue3618GoogleCalendarUrlHttps, type: :db_migration, db_strategy
|
||||||
.from(false)
|
.from(false)
|
||||||
.to(true)
|
.to(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'other' do
|
||||||
|
calendar.update_attribute(:business_hours, nil)
|
||||||
|
|
||||||
|
expect { migrate }
|
||||||
|
.to change { calendar.reload.ical_url.starts_with? 'https://' }
|
||||||
|
.from(false)
|
||||||
|
.to(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -211,14 +211,14 @@ RSpec.describe Calendar, type: :model do
|
||||||
timeframes: [['09:00', '00:00']]
|
timeframes: [['09:00', '00:00']]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end.to raise_error(Exceptions::UnprocessableEntity, 'nonsensical hours provided')
|
end.to raise_error(ActiveRecord::RecordInvalid, %r{nonsensical hours provided})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails for blank structure' do
|
it 'fails for blank structure' do
|
||||||
expect do
|
expect do
|
||||||
create(:calendar,
|
create(:calendar,
|
||||||
business_hours: {})
|
business_hours: {})
|
||||||
end.to raise_error(Exceptions::UnprocessableEntity, 'No configured business hours found!')
|
end.to raise_error(ActiveRecord::RecordInvalid, %r{No configured business hours found!})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue