Fixes #2157 - Ical escaltion update the calendar entry to 2:00 am

This commit is contained in:
Mantas 2021-08-26 23:58:51 +03:00 committed by Thorsten Eckel
parent f8a231f59c
commit c305ff89be
3 changed files with 37 additions and 11 deletions

View file

@ -5,6 +5,7 @@ class CalendarSubscriptions
def initialize(user) def initialize(user)
@user = user @user = user
@preferences = {} @preferences = {}
@time_zone = Setting.get('timezone_default').presence || 'UTC'
default_preferences = Setting.where(area: 'Defaults::CalendarSubscriptions') default_preferences = Setting.where(area: 'Defaults::CalendarSubscriptions')
default_preferences.each do |calendar_subscription| default_preferences.each do |calendar_subscription|
@ -42,7 +43,7 @@ class CalendarSubscriptions
if @preferences[ object_name ].present? if @preferences[ object_name ].present?
sub_class_name = object_name.to_s.capitalize sub_class_name = object_name.to_s.capitalize
object = "CalendarSubscriptions::#{sub_class_name}".constantize object = "CalendarSubscriptions::#{sub_class_name}".constantize
instance = object.new(@user, @preferences[ object_name ]) instance = object.new(@user, @preferences[ object_name ], @time_zone)
method = instance.method(method_name) method = instance.method(method_name)
events_data += method.call events_data += method.call
end end
@ -56,8 +57,8 @@ class CalendarSubscriptions
events_data.each do |event_data| events_data.each do |event_data|
cal.event do |e| cal.event do |e|
e.dtstart = Icalendar::Values::DateTime.new(event_data[:dtstart], 'tzid' => 'UTC') e.dtstart = Icalendar::Values::DateTime.new(event_data[:dtstart], 'tzid' => @time_zone)
e.dtend = Icalendar::Values::DateTime.new(event_data[:dtend], 'tzid' => 'UTC') e.dtend = Icalendar::Values::DateTime.new(event_data[:dtend], 'tzid' => @time_zone)
if event_data[:alarm] if event_data[:alarm]
e.alarm do |a| e.alarm do |a|
a.action = 'DISPLAY' a.action = 'DISPLAY'

View file

@ -2,10 +2,10 @@
class CalendarSubscriptions::Tickets class CalendarSubscriptions::Tickets
def initialize(user, preferences) def initialize(user, preferences, time_zone)
@user = user @user = user
@preferences = preferences @preferences = preferences
@tzid = 'UTC' @time_zone = time_zone
end end
def all def all
@ -86,8 +86,8 @@ class CalendarSubscriptions::Tickets
translated_state = Translation.translate(user_locale, ticket.state.name) translated_state = Translation.translate(user_locale, ticket.state.name)
event_data[:dtstart] = Icalendar::Values::Date.new(Time.zone.today, 'tzid' => @tzid) event_data[:dtstart] = Icalendar::Values::Date.new(Time.zone.today, 'tzid' => @time_zone)
event_data[:dtend] = Icalendar::Values::Date.new(Time.zone.today, 'tzid' => @tzid) event_data[:dtend] = Icalendar::Values::Date.new(Time.zone.today, 'tzid' => @time_zone)
event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}'" event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}'"
event_data[:description] = "T##{ticket.number}" event_data[:description] = "T##{ticket.number}"
@ -144,8 +144,8 @@ class CalendarSubscriptions::Tickets
translated_state = Translation.translate(user_locale, ticket.state.name) translated_state = Translation.translate(user_locale, ticket.state.name)
event_data[:dtstart] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @tzid) event_data[:dtstart] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @time_zone)
event_data[:dtend] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @tzid) event_data[:dtend] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @time_zone)
event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}" event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}"
event_data[:description] = "T##{ticket.number}" event_data[:description] = "T##{ticket.number}"
if alarm? if alarm?
@ -198,8 +198,8 @@ class CalendarSubscriptions::Tickets
escalation_at = Time.zone.today escalation_at = Time.zone.today
end end
event_data[:dtstart] = Icalendar::Values::DateTime.new(escalation_at, 'tzid' => @tzid) event_data[:dtstart] = Icalendar::Values::DateTime.new(escalation_at, 'tzid' => @time_zone)
event_data[:dtend] = Icalendar::Values::DateTime.new(escalation_at, 'tzid' => @tzid) event_data[:dtend] = Icalendar::Values::DateTime.new(escalation_at, 'tzid' => @time_zone)
event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}" event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}"
event_data[:description] = "T##{ticket.number}" event_data[:description] = "T##{ticket.number}"
if alarm? if alarm?

View file

@ -10,4 +10,29 @@ RSpec.describe 'iCal endpoints', type: :request do
expect(response.body).to eq("HTTP Basic: Access denied.\n") expect(response.body).to eq("HTTP Basic: Access denied.\n")
end end
end end
describe 'time zone', authenticated_as: :user do
let(:group) { create(:group) }
let(:user) { create(:agent) }
before do
user.groups << group
create(:ticket, group: group, owner: user, state_name: 'open', pending_time: 1.day.ago)
end
it 'returns zero offset time if no time zone set' do
get '/ical/tickets'
expect(response.body).to match %r{DTSTART:\d{8}T0{6}Z}
end
it 'returns selected time zone' do
Setting.set 'timezone_default', 'Europe/Vilnius'
get '/ical/tickets'
expect(response.body).to match %r{DTSTART;TZID=Europe/Vilnius:\d{8}T0{6}}
end
end
end end