Fix holidays in calendar sitemgr modules by adding access via holidays.php.

This lets the anonymous user get the holiday list without triggering a permission error.
This commit is contained in:
nathangray 2016-10-07 09:21:37 -06:00
parent 656d195494
commit fffa937f39
2 changed files with 61 additions and 8 deletions

53
calendar/inc/holidays.php Normal file
View File

@ -0,0 +1,53 @@
<?php
/**
* Load holidays from server
*
* Called from calendar_view widget to get cachable holiday list.
* It's broken out into a separate file to get around anonymous user not having
* calendar run rights in sitemgr.
*
* @link www.egroupware.org
* @author Nathan Gray
* @package calendar
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
use EGroupware\Api;
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
ini_set('zlib.output_compression', 0);
$GLOBALS['egw_info'] = array(
'flags' => array(
'currentapp' => 'api',
'noheader' => true,
'nocachecontrol' => true,
)
);
include '../../header.inc.php';
$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
$cal_bo = new calendar_bo();
$holidays = json_encode($cal_bo->read_holidays((int)$_GET['year']));
// use an etag over holidays
$etag = '"'.md5($holidays).'"';
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
Api\Session::cache_control(86400); // cache for one day
Header('Content-Type: application/json; charset=utf-8');
Header('ETag: '.$etag);
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
exit;
}
// Content-Lenght header is important, otherwise browsers dont cache!
Header('Content-Length: '.bytes($holidays));
echo $holidays;

View File

@ -619,25 +619,25 @@ jQuery.extend(et2_calendar_view,
get_holidays: function(widget,year)
{
// Loaded in an iframe or something
if(!egw.window.et2_calendar_view) return {};
var view = egw.window.et2_calendar_view ? egw.window.et2_calendar_view : this;
if(!view) return {};
var cache = egw.window.et2_calendar_view.holiday_cache[year];
var cache = view.holiday_cache[year];
if (typeof cache == 'undefined')
{
// Fetch with json instead of jsonq because there may be more than
// one widget listening for the response by the time it gets back,
// and we can't do that when it's queued.
egw.window.et2_calendar_view.holiday_cache[year] = egw.json(
'calendar_timegrid_etemplate_widget::ajax_get_holidays',
[year]
).sendRequest(true);
view.holiday_cache[year] = jQuery.getJSON(
egw.link('/calendar/inc/holidays.php', {year: year})
);
}
cache = egw.window.et2_calendar_view.holiday_cache[year];
cache = view.holiday_cache[year];
if(typeof cache.done == 'function')
{
// pending, wait for it
cache.done(jQuery.proxy(function(response) {
egw.window.et2_calendar_view.holiday_cache[this.year] = response.response[0].data||undefined;
view.holiday_cache[this.year] = response||undefined;
egw.window.setTimeout(jQuery.proxy(function() {
// Make sure widget hasn't been destroyed while we wait