fixed bug reported on the users list: if admin forced or set a default of 'personal' for the default addressbook where new accounts should be created, it prevents eg. syncml to create the contact, as it's the admins personal addressbook, to whom no user user has access, thanks to pgoerzen-at-hustlerturf.com

This commit is contained in:
Ralf Becker 2007-12-14 23:20:18 +00:00
parent b319e27c68
commit 9eb50fff4a
2 changed files with 29 additions and 5 deletions

View File

@ -112,6 +112,18 @@ class bocontacts extends socontacts
* @var array * @var array
*/ */
var $prefs; var $prefs;
/**
* Default addressbook for new contacts, if no addressbook is specified (user preference)
*
* @var int
*/
var $default_addressbook;
/**
* Default addressbook is the private one
*
* @var boolean
*/
var $default_private;
function bocontacts($contact_app='addressbook') function bocontacts($contact_app='addressbook')
{ {
@ -121,6 +133,18 @@ class bocontacts extends socontacts
$this->now_su = time() + $this->tz_offset_s; $this->now_su = time() + $this->tz_offset_s;
$this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook']; $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
// get the default addressbook from the users prefs
$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook'],-1) == 'p';
$this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook'] ?
(int)$GLOBALS['egw_info']['user']['preferences']['addressbook'] : $this->user;
if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user &&
($this->default_private ||
$this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default']) ||
$this->default_addressbook == (int)$GLOBALS['egw']->preferences->default['addressbook']['add_default'])
{
$this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook
}
$this->contact_fields = array( $this->contact_fields = array(
'id' => lang('Contact ID'), 'id' => lang('Contact ID'),
@ -461,8 +485,8 @@ class bocontacts extends socontacts
if (!$isUpdate) if (!$isUpdate)
{ {
// if no owner/addressbook set use the setting of the add_default prefs (if set, otherwise the users personal addressbook) // 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'] = (int)$this->prefs['add_default'] ? (int)$this->prefs['add_default'] : $this->user; if (!isset($contact['owner'])) $contact['owner'] = $this->default_addressbook;
if (!isset($contact['private'])) $contact['private'] = (int)(substr($this->prefs['add_default'],-1) == 'p'); if (!isset($contact['private'])) $contact['private'] = (int)$this->default_private;
// allow admins to import contacts with creator / created date set // allow admins to import contacts with creator / created date set
if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user; if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user;
if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su; if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su;

View File

@ -1270,8 +1270,8 @@ class uicontacts extends bocontacts
$content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p'); $content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p');
if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD)) if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD))
{ {
$content['owner'] = $this->prefs['add_default']; $content['owner'] = $this->default_addressbook;
$content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p'); $content['private'] = (int)$this->default_private;
if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD)) if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD))
{ {
@ -1298,7 +1298,7 @@ class uicontacts extends bocontacts
$content['id'])); $content['id']));
// create a new contact with the content of the old // create a new contact with the content of the old
foreach(array('id','modified','modifier','account_id') as $key) unset($content[$key]); foreach(array('id','modified','modifier','account_id') as $key) unset($content[$key]);
$content['owner'] = $this->prefs['add_default'] ? $this->prefs['add_default'] : $this->user; $content['owner'] = $this->default_private ? $this->user.'p' : $this->default_addressbook;
$content['creator'] = $this->user; $content['creator'] = $this->user;
$content['created'] = $this->now_su; $content['created'] = $this->now_su;
$content['msg'] = lang('Contact copied'); $content['msg'] = lang('Contact copied');