fixed many issues with distribution lists as vCard groups, also adding/removing contacts from a list in web-GUI is working again

This commit is contained in:
Ralf Becker 2012-01-31 19:47:52 +00:00
parent 349b237f25
commit 5c020ac87d
5 changed files with 43 additions and 19 deletions

View File

@ -1723,6 +1723,7 @@ class addressbook_bo extends addressbook_so
{
$owner = $list_data['list_owner'];
}
//error_log(__METHOD__."($list, $required, $owner) grants[$owner]=".$this->grants[$owner]." returning ".array2string(!!($this->grants[$owner] & $required)));
return !!($this->grants[$owner] & $required);
}
@ -1737,9 +1738,9 @@ class addressbook_bo extends addressbook_so
*/
function add_list($keys,$owner,$contacts=array(),array &$data=array())
{
if (!$this->check_list(null,EGW_ACL_ADD,$owner)) return false;
if (!$this->check_list(null,EGW_ACL_ADD|EGW_ACL_EDIT,$owner)) return false;
return parent::add_list($name,$owner,$contacts,$data);
return parent::add_list($keys,$owner,$contacts,$data);
}
/**

View File

@ -207,7 +207,7 @@ class addressbook_groupdav extends groupdav_handler
// add groups after contacts
if (!$start || count($contacts) < $start[1])
{
if (($lists = $this->bo->read_lists(array('list_owner' => $filter['contact_owner']?$filter['contact_owner']:array_keys($this->bo->grants)))))
if (($lists = $this->bo->read_lists(array('list_owner' => isset($filter['contact_owner'])?$filter['contact_owner']:array_keys($this->bo->grants)))))
{
//_debug_array($lists);
foreach($lists as $list)
@ -437,6 +437,7 @@ class addressbook_groupdav extends groupdav_handler
$oldContact = $this->_common_get_put_delete('PUT',$options,$id);
if (!is_null($oldContact) && !is_array($oldContact))
{
if ($this->debug) error_log(__METHOD__."(,'$id', $user, '$prefix') returning ".array2string($oldContact));
return $oldContact;
}
@ -477,7 +478,7 @@ class addressbook_groupdav extends groupdav_handler
$contactId = -1;
$retval = '201 Created';
}
$is_group = $contact['##X-CALENDARSERVER-KIND'] == 'group';
$is_group = $contact['##X-ADDRESSBOOKSERVER-KIND'] == 'group';
if ($oldContact && $is_group !== isset($oldContact['list_id']))
{
throw new egw_exception_assertion_failed(__METHOD__."(,'$id',$user,'$prefix') can contact into group or visa-versa!");
@ -512,6 +513,7 @@ class addressbook_groupdav extends groupdav_handler
if ($oldContact && $user != $oldContact['owner'] && !($this->bo->grants[$user] & EGW_ACL_ADD) &&
(!$this->bo->grants[$oldContact['owner']] & EGW_ACL_DELETE))
{
if ($this->debug) error_log(__METHOD__."(,'$id', $user, '$prefix') returning '403 Forbidden'");
return '403 Forbidden';
}
$contact['owner'] = $user;
@ -543,6 +545,7 @@ class addressbook_groupdav extends groupdav_handler
header($h='Location: '.$this->base_uri.$path.self::get_path($contact));
if ($this->debug) error_log(__METHOD__."($method,,$id) header('$h'): $retval");
}
if ($this->debug > 1) error_log(__METHOD__."(,'$id', $user, '$prefix') returning ".array2string($retval));
return $retval;
}
@ -606,6 +609,7 @@ class addressbook_groupdav extends groupdav_handler
if ($to_delete_ids) $this->bo->remove_from_list($to_delete_ids, $list_id);
}
}
if ($this->debug > 1) error_log(__METHOD__.'('.array2string($contact).', '.array2string($oldContact).') returning '.array2string($list_id));
return $list_id;
}
@ -766,11 +770,16 @@ class addressbook_groupdav extends groupdav_handler
$contact[$name] = $contact['list_'.$name];
}
}
elseif($contact === array()) // not found from read_lists()
{
$contact = null;
}
if ($contact && $contact['tid'] == addressbook_so::DELETED_TYPE)
{
$contact = null; // handle deleted events, as not existing (404 Not Found)
}
if ($this->debug > 1) error_log(__METHOD__."('$id') returning ".array2string($contact));
return $contact;
}

View File

@ -987,7 +987,7 @@ class addressbook_so
{
if (!method_exists($this->somain,'add_list')) return false;
return $this->somain->add_list($name,$owner,$contacts,$data);
return $this->somain->add_list($keys,$owner,$contacts,$data);
}
/**

View File

@ -497,12 +497,19 @@ class addressbook_sql extends so_sql_cf
*/
function add_list($keys,$owner,$contacts=array(),array &$data=array())
{
if (!$keys || !(int)$owner) return false;
error_log(__METHOD__.'('.array2string($keys).", $owner, ..., ".array2string($data).')');
if (!$keys && !$data || !(int)$owner) return false;
if (!is_array($keys)) $keys = array('list_name' => $keys);
$keys['list_owner'] = $owner;
if (!($list_id = $this->select($this->lists_table,'list_id',$keys)->fetchColumn()))
if ($keys && !is_array($keys)) $keys = array('list_name' => $keys);
if ($keys)
{
$keys['list_owner'] = $owner;
}
else
{
$data['list_owner'] = $owner;
}
if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys)->fetchColumn()))
{
$data['list_created'] = time();
$data['list_creator'] = $GLOBALS['egw_info']['user']['account_id'];
@ -513,6 +520,7 @@ class addressbook_sql extends so_sql_cf
}
$data['list_modified'] = time();
$data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
if (!$data['list_id']) unset($data['list_id']);
if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false;
@ -522,18 +530,18 @@ class addressbook_sql extends so_sql_cf
$update = array();
if (!isset($data['list_uid']))
{
$update['list_uid'] = $data['list_uid'] = common::generate_uid('addresbook-lists', $list_idD);
$update['list_uid'] = $data['list_uid'] = common::generate_uid('addresbook-lists', $list_id);
}
if (!isset($data['list_carddav_name']))
{
$update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf';
}
$this->db->update($this->lists_table,$update,array('list_id'=>$list_id));
$this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__);
$this->add2list($list_id,$contacts,array());
}
$data += $keys;
if ($keys) $data += $keys;
//error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id));
return $list_id;
}
@ -549,7 +557,14 @@ class addressbook_sql extends so_sql_cf
{
if (!(int)$list || !is_array($contact) && !(int)$contact) return false;
if (!is_array($existing)) $existing = $this->read_list($list);
if (!is_array($existing))
{
$existing = array();
foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row)
{
$existing[] = $row['contact_id'];
}
}
if (!($to_add = array_diff((array)$contact,$existing)))
{
return true; // no need to insert it, would give sql error
@ -564,7 +579,7 @@ class addressbook_sql extends so_sql_cf
),array(),__LINE__,__FILE__);
}
// update etag
return $this->db->update($this->list_table,array(
return $this->db->update($this->lists_table,array(
'list_etag=list_etag+1',
'list_modified' => time(),
'list_modifier' => $GLOBALS['egw_info']['user']['account_id'],
@ -605,7 +620,7 @@ class addressbook_sql extends so_sql_cf
}
foreach((array)$list as $list_id)
{
$this->db->update($this->list_table,array(
$this->db->update($this->lists_table,array(
'list_etag=list_etag+1',
'list_modified' => time(),
'list_modifier' => $GLOBALS['egw_info']['user']['account_id'],

View File

@ -971,9 +971,8 @@ class addressbook_vcal extends addressbook_bo
}
}
// add unsupported attributes as with '##' prefix
else
elseif(($attribute = $vcardValues[$vcardKey]) && !in_array($attribute['name'],array('PRODID','REV')))
{
$attribute = $vcardValues[$vcardKey];
// for attributes with multiple values in multiple lines, merge the values
if (isset($contact['##'.$attribute['name']]))
{