From f1ba35613cbac1c4c1a1a1dd772b35bcf7c6c46f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 23 Jul 2015 17:40:48 +0000 Subject: [PATCH] * CardDAV/Addressbook: fix iOS 8.4 problem allways creating new contacts for admins in accounts addressbook, using now default or personal addressbook --- addressbook/inc/class.addressbook_bo.inc.php | 10 ++++++++-- .../inc/class.addressbook_groupdav.inc.php | 15 +++++++++++---- addressbook/inc/class.addressbook_ui.inc.php | 5 +++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 5355b9c938..2d0e84b4bf 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -7,7 +7,7 @@ * @author Ralf Becker * @author Joerg Lehrke * @package addressbook - * @copyright (c) 2005-12 by Ralf Becker + * @copyright (c) 2005-15 by Ralf Becker * @copyright (c) 2005/6 by Cornelius Weiss * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ @@ -367,7 +367,8 @@ class addressbook_bo extends addressbook_so asort($to_sort); $addressbooks += $to_sort; } - if (!$preferences['addressbook']['hide_accounts'] && ( + if ($required != EGW_ACL_ADD && // do NOT allow to set accounts as default addressbook (AB can add accounts) + !$preferences['addressbook']['hide_accounts'] && ( ($grants[0] & $required) == $required || $preferences['common']['account_selection'] == 'groupmembers' && $this->account_repository != 'ldap' && ($required & EGW_ACL_READ))) @@ -862,6 +863,11 @@ class addressbook_bo extends addressbook_so // if no owner/addressbook set use the setting of the add_default prefs (if set, otherwise the users personal addressbook) if (!isset($contact['owner'])) $contact['owner'] = $this->default_addressbook; if (!isset($contact['private'])) $contact['private'] = (int)$this->default_private; + // do NOT allow to create new accounts via addressbook, they are broken without an account_id + if (!$contact['owner'] && empty($contact['account_id'])) + { + $contact['owner'] = $this->default_addressbook ? $this->default_addressbook : $this->user; + } // allow admins to import contacts with creator / created date set if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user; if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su; diff --git a/addressbook/inc/class.addressbook_groupdav.inc.php b/addressbook/inc/class.addressbook_groupdav.inc.php index fcd6403be3..d32b06965e 100644 --- a/addressbook/inc/class.addressbook_groupdav.inc.php +++ b/addressbook/inc/class.addressbook_groupdav.inc.php @@ -643,12 +643,12 @@ class addressbook_groupdav extends groupdav_handler $contact['carddav_name'] = $id; // only set owner, if user is explicitly specified in URL (check via prefix, NOT for /addressbook/) or sync-all-in-one!) - if ($prefix && !in_array('O',$this->home_set_pref)) + if ($prefix && !in_array('O',$this->home_set_pref) && $user) { $contact['owner'] = $user; } - // check if default addressbook is synced, if not use (always synced) personal addressbook - elseif($this->bo->default_addressbook && !in_array($this->bo->default_addressbook,$this->home_set_pref)) + // check if default addressbook is synced and not accounts, if not use (always synced) personal addressbook + elseif(!$this->bo->default_addressbook || !in_array($this->bo->default_addressbook,$this->home_set_pref)) { $contact['owner'] = $GLOBALS['egw_info']['user']['account_id']; } @@ -1027,7 +1027,14 @@ class addressbook_groupdav extends groupdav_handler */ public function get_grants() { - return $this->bo->get_grants($this->bo->user); + $grants = $this->bo->get_grants($this->bo->user); + + // remove add and delete grants for accounts (for admins too) + // as accounts can not be created as contacts, they eg. need further data + // and admins might not recognice they delete an account incl. its data + if (isset($grants[0])) $grants[0] &= ~(EGW_ACL_ADD|EGW_ACL_DELETE); + + return $grants; } /** diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 89e143b345..f27778a27b 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1129,10 +1129,11 @@ window.egw_LAB.wait(function() { if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) { if ($contact['owner'] || // regular contact or + empty($contact['account_id']) || // accounts without account_id // already deleted account (should no longer happen, but needed to allow for cleanup) $contact['tid'] == addressbook_so::DELETED_TYPE) { - $Ok = $this->delete($id, $contact['tid'] != addressbook_so::DELETED_TYPE); + $Ok = $this->delete($id, $contact['tid'] != addressbook_so::DELETED_TYPE && $contact['account_id']); } // delete single account --> redirect to admin elseif (count($checked) == 1 && $contact['account_id']) @@ -1641,7 +1642,7 @@ window.egw_LAB.wait(function() { { $row['tel_prefered'] = $row[$row['tel_prefer']].$prefer_marker; } - if (!$row['owner']) + if (!$row['owner'] && $row['account_id'] > 0) { $row['class'] .= 'rowAccount rowNoDelete '; }