move logic of which addressbook/calendars are shared into app-handler

This commit is contained in:
Ralf Becker 2012-02-04 01:03:56 +00:00
parent d43e93cf7f
commit d21be8d871
4 changed files with 88 additions and 61 deletions

View File

@ -780,4 +780,39 @@ class addressbook_groupdav extends groupdav_handler
{ {
return $this->bo->check_perms($acl,$contact); return $this->bo->check_perms($acl,$contact);
} }
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
$shared = array();
$addressbook_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set'];
if (empty($addressbook_home_set)) $addressbook_home_set = 'P'; // personal addressbook
$addressbook_home_set = explode(',',$addressbook_home_set);
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
'U' => '0',
) as $sym => $id)
{
if (($key = array_search($sym, $addressbook_home_set)) !== false)
{
$addressbook_home_set[$key] = $id;
}
}
foreach($this->bo->get_addressbooks(EGW_ACL_READ) as $id => $label)
{
if (($id || !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) &&
$user != $id && // no current user and no accounts, if disabled in ab prefs
(in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) &&
is_numeric($id) && ($owner = $id ? $this->accounts->id2name($id) : 'accounts'))
{
$shared[$id] = $owner;
}
}
return $shared;
}
} }

View File

@ -1218,4 +1218,37 @@ class calendar_groupdav extends groupdav_handler
if ($this->debug > 1) error_log("ical Handler called: " . $this->agent); if ($this->debug > 1) error_log("ical Handler called: " . $this->agent);
return $handler; return $handler;
} }
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
$shared = array();
$calendar_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set'];
$calendar_home_set = $calendar_home_set ? explode(',',$calendar_home_set) : array();
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
) as $sym => $id)
{
if (($key = array_search($sym, $calendar_home_set)) !== false)
{
$calendar_home_set[$key] = $id;
}
}
foreach(ExecMethod('calendar.calendar_bo.list_cals') as $entry)
{
$id = $entry['grantor'];
if ($id && $user != $id && // no current user and no accounts yet (todo)
(in_array('A',$calendar_home_set) || in_array((string)$id,$calendar_home_set)) &&
is_numeric($id) && ($owner = $this->accounts->id2name($id)))
{
$shared[$id] = $owner;
}
}
return $shared;
}
} }

View File

@ -643,71 +643,20 @@ class groupdav extends HTTP_WebDAV_Server
protected function add_shared(array &$files, $path, $app, $user) protected function add_shared(array &$files, $path, $app, $user)
{ {
// currently only show shared calendars/addressbooks for current user and not in the root // currently only show shared calendars/addressbooks for current user and not in the root
if ($path == '/' || $user != $GLOBALS['egw_info']['user']['account_id']) if ($path == '/' || $user != $GLOBALS['egw_info']['user']['account_id'] ||
!isset($GLOBALS['egw_info']['user']['apps'][$app])) // also avoids principals, inbox and outbox
{ {
return true; return true;
} }
switch($app) $handler = $this->app_handler($app);
if (($shared = $handler->get_shared()))
{ {
case 'addressbook': foreach($shared as $id => $owner)
$addressbook_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set']; {
if (empty($addressbook_home_set)) $addressbook_home_set = 'P'; // personal addressbook $file = $this->add_app($app,false,$id,$path.$app.'-'.$owner.'/');
$addressbook_home_set = explode(',',$addressbook_home_set); $file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
// replace symbolic id's with real nummeric id's $files[] = $file;
foreach(array( }
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
'U' => '0',
) as $sym => $id)
{
if (($key = array_search($sym, $addressbook_home_set)) !== false)
{
$addressbook_home_set[$key] = $id;
}
}
foreach(ExecMethod('addressbook.addressbook_bo.get_addressbooks',EGW_ACL_READ) as $id => $label)
{
if (($id || !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) &&
$user != $id && // no current user and no accounts, if disabled in ab prefs
(in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) &&
is_numeric($id) && ($owner = $id ? $this->accounts->id2name($id) : 'accounts'))
{
$file = $this->add_app($app,false,$id,$path.'addressbook-'.$owner.'/');
$file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
$files[] = $file;
}
}
break;
case 'calendar':
$calendar_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set'];
$calendar_home_set = $calendar_home_set ? explode(',',$calendar_home_set) : array();
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
) as $sym => $id)
{
if (($key = array_search($sym, $calendar_home_set)) !== false)
{
$calendar_home_set[$key] = $id;
}
}
foreach(ExecMethod('calendar.calendar_bo.list_cals') as $entry)
{
$id = $entry['grantor'];
if ($id && $user != $id && // no current user and no accounts yet (todo)
(in_array('A',$calendar_home_set) || in_array((string)$id,$calendar_home_set)) &&
is_numeric($id) && ($owner = $this->accounts->id2name($id)))
{
$file = $this->add_app($app,false,$id,$path.'calendar-'.$owner.'/');
$file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
$files[] = $file;
}
}
break;
case 'infolog':
// ToDo:
break;
} }
return true; return true;
} }

View File

@ -457,6 +457,16 @@ abstract class groupdav_handler
return $entry[self::$path_attr].self::$path_extension; return $entry[self::$path_attr].self::$path_extension;
} }
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
return array();
}
/** /**
* Add a resource * Add a resource
* *