Fixes #3641 - Migration 3.6.1 to 4.1 : No configured business hours found!

This commit is contained in:
Mantas Masalskis 2021-07-02 06:57:00 +00:00 committed by Thorsten Eckel
parent f85d2adff5
commit d09a3c5b85
4 changed files with 33 additions and 15 deletions

View file

@ -8,11 +8,14 @@ class Calendar < ApplicationModel
store :business_hours
store :public_holidays
before_create :validate_public_holidays, :validate_hours, :fetch_ical
after_create :sync_default, :min_one_check
before_update :validate_public_holidays, :validate_hours, :fetch_ical
after_update :sync_default, :min_one_check
validate :validate_hours
before_save :ensure_public_holidays_details, :fetch_ical
after_destroy :min_one_check
after_save :min_one_check
after_save :sync_default
=begin
@ -391,8 +394,8 @@ returns
true
end
# validate format of public holidays
def validate_public_holidays
# ensure integrity of details of public holidays
def ensure_public_holidays_details
# fillup feed info
before = public_holidays_was
@ -414,7 +417,13 @@ returns
# get business hours
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
begin
@ -423,10 +432,8 @@ returns
end
Biz.time(10, :minutes).after(Time.zone.parse('Tue, 05 Feb 2019 21:40:28 UTC +00:00'))
rescue => e
raise Exceptions::UnprocessableEntity, e.message
errors.add :base, e.message
end
true
end
end

View file

@ -7,8 +7,10 @@ class Issue3618GoogleCalendarUrlHttps < ActiveRecord::Migration[5.2]
Calendar
.where('ical_url LIKE ?', 'http://www.google.com/calendar/ical/%')
.each do |calendar|
calendar.ical_url.sub!(%r{^http://}, 'https://')
calendar.save
new_url = calendar.ical_url.sub(%r{^http://}, 'https://')
# 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

View file

@ -12,4 +12,13 @@ RSpec.describe Issue3618GoogleCalendarUrlHttps, type: :db_migration, db_strategy
.from(false)
.to(true)
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

View file

@ -211,14 +211,14 @@ RSpec.describe Calendar, type: :model do
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
it 'fails for blank structure' do
expect do
create(:calendar,
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