Skip to content

Commit

Permalink
Bug: 13660 Don't show private events in daily agenda email.
Browse files Browse the repository at this point in the history
Conflicts:
	kronolith/lib/Kronolith.php
  • Loading branch information
mrubinsk committed Nov 3, 2014
1 parent d4c314b commit de5eff0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
5 changes: 4 additions & 1 deletion kronolith/bin/kronolith-agenda
Expand Up @@ -88,6 +88,9 @@ function send_agendas()
continue;
}

// Initialize the CalendarsManager for this user.
$GLOBALS['calendar_manager'] = new Kronolith_CalendarsManager($user);

// Try to find an email address for the user.
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
$email = $identity->getDefaultFromAddress(true);
Expand Down Expand Up @@ -137,7 +140,7 @@ function send_agendas()
foreach ($events as $dayevents) {
foreach ($dayevents as $event) {
// The event list contains events starting at 12am.
if ($event->start->compareDate($runtime)) {
if ($event->start->compareDate($runtime) || $event->isPrivate($user)) {
continue;
}
$eventlist[] = $event;
Expand Down
19 changes: 15 additions & 4 deletions kronolith/lib/CalendarsManager.php
Expand Up @@ -124,21 +124,32 @@ class Kronolith_CalendarsManager
* - displayRemote
* - displayExternal
* - displayHolidays
*
* @param string $user The user to initialize for, if not the current.
* @since 4.2.4
*/
public function __construct()
public function __construct($user = null)
{
$emptyUser = false;
if (empty($user)) {
$user = $GLOBALS['registry']->getAuth();
$emptyUser = true;
}
// Always perform the display related checks.
$this->_checkDisplayCals();
$this->_checkToggleCalendars();

// Check that all selected shares still exist.
foreach (Kronolith::listInternalCalendars() as $id => $calendar) {
foreach (Kronolith::listInternalCalendars(false, Horde_Perms::SHOW, $user) as $id => $calendar) {
$this->_allCalendars[$id] = new Kronolith_Calendar_Internal(array('share' => $calendar));
}
$this->_displayCalendars = array_intersect($this->_displayCalendars, array_keys($this->_allCalendars));

// Check that the user owns a calendar.
$this->_checkForOwnedCalendar();
// Check that the user owns a calendar if we aren't loading a different
// user.
if ($emptyUser) {
$this->_checkForOwnedCalendar();
}
}

/**
Expand Down
21 changes: 13 additions & 8 deletions kronolith/lib/Event.php
Expand Up @@ -2604,26 +2604,31 @@ public function boundExceptions($flat = true)
* Returns whether the event should be considered private.
*
* The event's private flag can be overriden if the current user
* is an administrator and the code is run from command line. This
* is to allow full event notifications in alarm messages or
* agendas.
* is an administrator and the code is run from command line, and no
* $user parameter was passed. This is to allow full event notifications in
* alarm messages (agendas know the user the agenda is being prepared for).
*
* @param string $user The current user.
* @param string $user The current user. If omitted, uses the current user.
*
* @return boolean Whether to consider the event as private.
*/
public function isPrivate($user = null)
{
global $registry;

$haveNullUser = false;
if ($user === null) {
$user = $GLOBALS['registry']->getAuth();
$user = $registry->getAuth();
$haveNullUser = true;
}

if (!(Horde_Cli::runningFromCLI() && $GLOBALS['registry']->isAdmin()) &&
if (!(Horde_Cli::runningFromCLI() && $registry->isAdmin()) &&
$this->private && $this->creator != $user) {
return true;
}
if ($GLOBALS['registry']->isAdmin() ||
$this->hasPermission(Horde_Perms::READ, $user)) {

if (($registry->isAdmin() && $haveNullUser) ||
$this->hasPermission(Horde_Perms::READ, $user)) {
return false;
}
return true;
Expand Down
19 changes: 13 additions & 6 deletions kronolith/lib/Kronolith.php
Expand Up @@ -987,24 +987,31 @@ static public function buildStatusWidget($name,
* @param boolean $owneronly Only return calenders that this user owns?
* Defaults to false.
* @param integer $permission The permission to filter calendars by.
* @param string $user The user to list calendars for, if not
* the current.
*
* @return array The calendar list.
*/
static public function listInternalCalendars($owneronly = false,
$permission = Horde_Perms::SHOW)
public static function listInternalCalendars($owneronly = false,
$permission = Horde_Perms::SHOW,
$user = null)
{
if ($owneronly && !$GLOBALS['registry']->getAuth()) {
return array();
}

if (empty($user)) {
$user = $GLOBALS['registry']->getAuth();
}

$kronolith_shares = $GLOBALS['injector']->getInstance('Kronolith_Shares');

if ($owneronly || empty($GLOBALS['conf']['share']['hidden'])) {
try {
$calendars = $kronolith_shares->listShares(
$GLOBALS['registry']->getAuth(),
$user,
array('perm' => $permission,
'attributes' => $owneronly ? $GLOBALS['registry']->getAuth() : null,
'attributes' => $owneronly ? $user : null,
'sort_by' => 'name'));
} catch (Horde_Share_Exception $e) {
Horde::log($e);
Expand All @@ -1015,7 +1022,7 @@ static public function listInternalCalendars($owneronly = false,
$calendars = $kronolith_shares->listShares(
$GLOBALS['registry']->getAuth(),
array('perm' => $permission,
'attributes' => $GLOBALS['registry']->getAuth(),
'attributes' => $user,
'sort_by' => 'name'));
} catch (Horde_Share_Exception $e) {
Horde::log($e);
Expand All @@ -1026,7 +1033,7 @@ static public function listInternalCalendars($owneronly = false,
foreach ($display_calendars as $id) {
try {
$calendar = $kronolith_shares->getShare($id);
if ($calendar->hasPermission($GLOBALS['registry']->getAuth(), $permission)) {
if ($calendar->hasPermission($user, $permission)) {
$calendars[$id] = $calendar;
}
} catch (Horde_Exception_NotFound $e) {
Expand Down

0 comments on commit de5eff0

Please sign in to comment.