fix caching in browser, if iCal holiday url get set or changed

This commit is contained in:
ralf 2024-04-10 10:46:01 +02:00
parent 785b61f34e
commit aa3d70202c
5 changed files with 24 additions and 5 deletions

View File

@ -139,7 +139,7 @@ egw.extend('calendar', egw.MODULE_GLOBAL, function (_app, _wnd)
// one widget listening for the response by the time it gets back,
// and we can't do that when it's queued.
_holiday_cache[year] = window.fetch(
egw.link('/calendar/holidays.php', {year: year})
egw.link('/calendar/holidays.php', {year: year, url: this.config('ical_holiday_url') || ''})
).then((response) =>
{
return _holiday_cache[year] = response.json();

View File

@ -257,7 +257,7 @@ class Config
'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file',
'markuntranslated','link_list_thumbnail','enabled_spellcheck','debug_minify',
'call_link','call_popup','fax_email','fax_email_regexp','geolocation_url', // addressbook
'hide_birthdays','calview_no_consolidate','fw_mobile_app_list'), // calendar
'hide_birthdays','calview_no_consolidate','fw_mobile_app_list', 'ical_holiday_url'), // calendar
'projectmanager' => array('hours_per_workday', 'duration_units'),
'manual' => array('manual_remote_egw_url'),
'infolog' => array('status'),

View File

@ -158,7 +158,7 @@ class calendar_holidays
* @param ?string $lang 2-digit iso language code or NULL
* @return array|Iterator parsed events
*/
protected static function fetch($country, $lang=null)
public static function fetch($country, $lang=null)
{
if (!($url = self::is_url($country) ? $country : self::ical_url($country, $lang)))
{

View File

@ -840,7 +840,26 @@ END:VALARM';
public static function config_validate()
{
$GLOBALS['egw_info']['server']['found_validation_hook'] = array('calendar_purge_old');
$GLOBALS['egw_info']['server']['found_validation_hook'] = [
'calendar_purge_old',
'ical_holiday_url' => 'calendar_hooks::ical_holiday_url',
];
}
/**
* Validate the iCal URL
*
* @param string $url
* @param Api\Config $c
* @return string|null error message or null on success
*/
public static function ical_holiday_url(string $url, Api\Config $c) : ?string
{
if (!empty($url) && (!preg_match('#^(/|https?://[^/]+/[^/]+)#', $url) || !calendar_holidays::fetch($url)))
{
return "Invalid iCalendar URL: $url";
}
return null;
}
/**

View File

@ -11,7 +11,7 @@
<row>
<et2-vbox>
<et2-description value="Custom URL for iCal with holidays for all users" label="%s:"></et2-description>
<et2-description label="(Without a custom URL we use nation of user preference to load holidays from %s)" href="https://www.thuderbird.net/en-US/calendar/holidays/" value="Mozilla Holiday Calendars" extraLinkTarget="_blank"></et2-description>
<et2-description label="(Without a custom URL we use nation of user preference to load holidays from %s)" href="https://www.thunderbird.net/en-US/calendar/holidays/" value="Mozilla Holiday Calendars" extraLinkTarget="_blank"></et2-description>
</et2-vbox>
<et2-url id="newsettings[ical_holiday_url]"></et2-url>
</row>