From 568ce1a622430862c8a7075f9a54dcc5b3b9fbcc Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 8 Nov 2010 23:55:47 +0100 Subject: [PATCH] Add a setting whether to create default shares if the user doesn't own any. Create default shares with random IDs instead of the user name as the ID. Instead of checking if a user has write access to share, check if the user owns a share, to determine whether to create a new one. --- horde/config/conf.xml | 3 ++ horde/docs/CHANGES | 1 + kronolith/calendars/delete.php | 4 --- kronolith/docs/CHANGES | 2 ++ kronolith/lib/Kronolith.php | 29 +++++------------ mnemo/docs/CHANGES | 2 ++ mnemo/lib/Forms/DeleteNotepad.php | 20 ------------ mnemo/lib/Mnemo.php | 42 +++++++++---------------- mnemo/notepads/delete.php | 4 --- nag/docs/CHANGES | 2 ++ nag/lib/Nag.php | 46 +++++++++------------------ nag/tasklists/delete.php | 4 --- turba/docs/CHANGES | 1 + turba/lib/Turba.php | 65 +++++++++++++++------------------------ 14 files changed, 71 insertions(+), 154 deletions(-) diff --git a/horde/config/conf.xml b/horde/config/conf.xml index eacc07eb8..5e7838577 100644 --- a/horde/config/conf.xml +++ b/horde/config/conf.xml @@ -949,6 +949,9 @@ editing permissions on their shares. This will keep a user from granting other users (or guests) access to their address book, notebook, calendar, etc.">false + true true diff --git a/horde/docs/CHANGES b/horde/docs/CHANGES index 618be10d4..79e924823 100644 --- a/horde/docs/CHANGES +++ b/horde/docs/CHANGES @@ -2,6 +2,7 @@ v4.0-cvs -------- +[jan] Add a configuration switch for automatic creation of default shares. [cjh] Move from Net_DNS to Net_DNS2. [jan] Translations for the framework packages are now bundled with those packages. diff --git a/kronolith/calendars/delete.php b/kronolith/calendars/delete.php index 2885282e3..62d6bd1ad 100644 --- a/kronolith/calendars/delete.php +++ b/kronolith/calendars/delete.php @@ -20,10 +20,6 @@ if (!$GLOBALS['registry']->getAuth()) { $vars = Horde_Variables::getDefaultVariables(); $calendar_id = $vars->get('c'); -if ($calendar_id == $GLOBALS['registry']->getAuth()) { - $notification->push(_("This calendar cannot be deleted."), 'horde.warning'); - Horde::url('calendars/', true)->redirect(); -} if (Kronolith::showAjaxView()) { Horde::url('', true)->setAnchor('calendar:internal|' . $calendar_id)->redirect(); diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index e00bd5233..272351535 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -2,6 +2,8 @@ v3.0-git -------- +[jan] Default calendars no longer have the user name as the ID. +[jan] Create a default calendar if the user doesn't own any yet. [jan] Add CalDAV client support (Request #8525). [jan] Send agenda emails with HTML part and convert to Horde_View. [mjr] More complete handling of recurring event exceptions when dealing with the diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 8dde0a933..c0d735eec 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -367,7 +367,7 @@ class Kronolith } } return $json; - } + } /** * Returns all the alarms active on a specific date. @@ -1149,25 +1149,16 @@ class Kronolith } $GLOBALS['prefs']->setValue('display_external_cals', serialize($GLOBALS['display_external_calendars'])); - /* If an authenticated user has no calendars visible and their - * personal calendar doesn't exist, create it. */ - if ($GLOBALS['registry']->getAuth() && - !count($GLOBALS['display_calendars']) && - !$GLOBALS['kronolith_shares']->exists($GLOBALS['registry']->getAuth())) { + /* If an authenticated doesn't own a calendar, create it. */ + if (!empty($GLOBALS['conf']['share']['auto_create']) && + $GLOBALS['registry']->getAuth() && + !count(Kronolith::listInternalCalendars(true))) { $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); - $name = $identity->getValue('fullname'); - if (trim($name) == '') { - $name = $GLOBALS['registry']->getAuth('original'); - } - $share = $GLOBALS['kronolith_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth()); - $share->set('name', sprintf(_("%s's Calendar"), $name)); + $share = $GLOBALS['kronolith_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid())); + $share->set('name', sprintf(_("Calendar of %s"), $identity->getName())); $GLOBALS['kronolith_shares']->addShare($share); $GLOBALS['all_calendars'][$GLOBALS['registry']->getAuth()] = new Kronolith_Calendar_Internal(array('share' => $share)); - - /* Make sure the personal calendar is displayed by default. */ - if (!in_array($GLOBALS['registry']->getAuth(), $GLOBALS['display_calendars'])) { - $GLOBALS['display_calendars'][] = $GLOBALS['registry']->getAuth(); - } + $GLOBALS['display_calendars'][] = $share->getName(); /* Calendar auto-sharing with the user's groups */ if ($GLOBALS['conf']['autoshare']['shareperms'] != 'none') { @@ -1702,10 +1693,6 @@ class Kronolith */ public static function deleteShare($calendar) { - if ($calendar->getName() == $GLOBALS['registry']->getAuth()) { - throw new Kronolith_Exception(_("This calendar cannot be deleted.")); - } - if (!$GLOBALS['registry']->getAuth() || ($calendar->get('owner') != $GLOBALS['registry']->getAuth() && (!is_null($calendar->get('owner')) || !$GLOBALS['registry']->isAdmin()))) { diff --git a/mnemo/docs/CHANGES b/mnemo/docs/CHANGES index 1ba41edfc..736e2d68f 100644 --- a/mnemo/docs/CHANGES +++ b/mnemo/docs/CHANGES @@ -2,6 +2,8 @@ v3.0-cvs -------- +[jan] Default notepads no longer have the user name as the ID. +[jan] Create a default notepad if the user doesn't own any yet. [jan] Try to create ISO-8859-1 encoded PDFs if this matches the user's language. [jan] Add script to convert notes to UTF-8 in the backend. diff --git a/mnemo/lib/Forms/DeleteNotepad.php b/mnemo/lib/Forms/DeleteNotepad.php index 625783211..c357cdf80 100644 --- a/mnemo/lib/Forms/DeleteNotepad.php +++ b/mnemo/lib/Forms/DeleteNotepad.php @@ -69,26 +69,6 @@ class Mnemo_DeleteNotepadForm extends Horde_Form { } } - // Make sure we still own at least one notepad. - if (count(Mnemo::listNotepads(true)) == 0) { - // If the default share doesn't exist then create it. - if (!$GLOBALS['mnemo_shares']->exists($GLOBALS['registry']->getAuth())) { - - $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); - $name = $identity->getValue('fullname'); - if (trim($name) == '') { - $name = $GLOBALS['registry']->getAuth(); - } - try { - $notepad = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth()); - } catch (Horde_Share_Exception $e) { - return; - } - $notepad->set('name', sprintf(_("%s's Notepad"), $name)); - $GLOBALS['mnemo_shares']->addShare($notepad); - } - } - return true; } diff --git a/mnemo/lib/Mnemo.php b/mnemo/lib/Mnemo.php index 88c9094d4..45a4383ee 100644 --- a/mnemo/lib/Mnemo.php +++ b/mnemo/lib/Mnemo.php @@ -433,35 +433,21 @@ class Mnemo { } } - if (count($GLOBALS['display_notepads']) == 0) { - $lists = Mnemo::listNotepads(true); - if (!$GLOBALS['registry']->getAuth()) { - /* All notepads for guests. */ - $GLOBALS['display_notepads'] = array_keys($lists); - } else { - /* Make sure at least the default notepad is visible. */ - $default_notepad = Mnemo::getDefaultNotepad(Horde_Perms::READ); - if ($default_notepad) { - $GLOBALS['display_notepads'] = array($default_notepad); - } + /* All tasklists for guests. */ + if (!count($GLOBALS['display_notepads']) && + !$GLOBALS['registry']->getAuth()) { + $GLOBALS['display_tasklists'] = array_keys($_all); + } - /* If the user's personal notepad doesn't exist, then create it. */ - if (!$GLOBALS['mnemo_shares']->exists($GLOBALS['registry']->getAuth())) { - $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); - $name = $identity->getValue('fullname'); - if (trim($name) == '') { - $name = $GLOBALS['registry']->getAuth(); - } - $share = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth()); - $share->set('name', sprintf(_("%s's Notepad"), $name)); - $GLOBALS['mnemo_shares']->addShare($share); - - /* Make sure the personal notepad is displayed by default. */ - if (!in_array($GLOBALS['registry']->getAuth(), $GLOBALS['display_notepads'])) { - $GLOBALS['display_notepads'][] = $GLOBALS['registry']->getAuth(); - } - } - } + /* If the user doesn't own a notepad, create one. */ + if (!empty($GLOBALS['conf']['share']['auto_create']) && + $GLOBALS['registry']->getAuth() && + !count(Mnemo::listNotepads(true))) { + $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); + $share = $GLOBALS['mnemo_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid())); + $share->set('name', sprintf(_("Notepad of %s"), $identity->getName())); + $GLOBALS['mnemo_shares']->addShare($share); + $GLOBALS['display_notepads'][] = $share->getName(); } $GLOBALS['prefs']->setValue('display_notepads', serialize($GLOBALS['display_notepads'])); diff --git a/mnemo/notepads/delete.php b/mnemo/notepads/delete.php index 350f03ac1..a01d8f57b 100644 --- a/mnemo/notepads/delete.php +++ b/mnemo/notepads/delete.php @@ -21,10 +21,6 @@ if (!$GLOBALS['registry']->getAuth()) { $vars = Horde_Variables::getDefaultVariables(); $notepad_id = $vars->get('n'); -if ($notepad_id == $GLOBALS['registry']->getAuth()) { - $notification->push(_("This notepad cannot be deleted"), 'horde.warning'); - Horde::url('notepads/', true)->redirect(); -} try { $notepad = $mnemo_shares->getShare($notepad_id); } catch (Horde_Share_Exception $e) { diff --git a/nag/docs/CHANGES b/nag/docs/CHANGES index 950d3cbc9..b9f812d4d 100644 --- a/nag/docs/CHANGES +++ b/nag/docs/CHANGES @@ -2,6 +2,8 @@ v3.0-git -------- +[jan] Default task lists no longer have the user name as the ID. +[jan] Create a default task list if the user doesn't own any yet. [jan] Add start date to possible colums in task list (Joel Smith , Request #9083). [jan] Add system task lists (Request #2059). diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index c601bb246..a89450ce8 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -505,10 +505,6 @@ class Nag */ public static function deleteTasklist($tasklist) { - if ($tasklist->getName() == $GLOBALS['registry']->getAuth()) { - throw new Horde_Exception_PermissionDenied(_("This task list cannot be deleted.")); - } - if (!$GLOBALS['registry']->getAuth() || ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() && (!is_null($tasklist->get('owner')) || !$GLOBALS['registry']->isAdmin()))) { @@ -723,35 +719,21 @@ class Nag } } - if (count($GLOBALS['display_tasklists']) == 0) { - $lists = Nag::listTasklists(true); - if (!$GLOBALS['registry']->getAuth()) { - /* All tasklists for guests. */ - $GLOBALS['display_tasklists'] = array_keys($lists); - } else { - /* Make sure at least the default tasklist is visible. */ - $default_tasklist = Nag::getDefaultTasklist(Horde_Perms::READ); - if ($default_tasklist) { - $GLOBALS['display_tasklists'] = array($default_tasklist); - } - - /* If the user's personal tasklist doesn't exist, then create it. */ - if (!$GLOBALS['nag_shares']->exists($GLOBALS['registry']->getAuth())) { - $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); - $name = $identity->getValue('fullname'); - if (trim($name) == '') { - $name = $GLOBALS['registry']->getAuth('original'); - } - $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth()); - $share->set('name', sprintf(_("%s's Task List"), $name)); - $GLOBALS['nag_shares']->addShare($share); + /* All tasklists for guests. */ + if (!count($GLOBALS['display_tasklists']) && + !$GLOBALS['registry']->getAuth()) { + $GLOBALS['display_tasklists'] = array_keys($GLOBALS['all_tasklists']); + } - /* Make sure the personal tasklist is displayed by default. */ - if (!in_array($GLOBALS['registry']->getAuth(), $GLOBALS['display_tasklists'])) { - $GLOBALS['display_tasklists'][] = $GLOBALS['registry']->getAuth(); - } - } - } + /* If the user doesn't own a task list, create one. */ + if (!empty($GLOBALS['conf']['share']['auto_create']) && + $GLOBALS['registry']->getAuth() && + !count(Nag::listTasklists(true))) { + $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); + $share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid())); + $share->set('name', sprintf(_("Task list of %s"), $identity->getName())); + $GLOBALS['nag_shares']->addShare($share); + $GLOBALS['display_tasklists'][] = $share->getName(); } $GLOBALS['prefs']->setValue('display_tasklists', serialize($GLOBALS['display_tasklists'])); diff --git a/nag/tasklists/delete.php b/nag/tasklists/delete.php index 884c80c9d..9d609c764 100644 --- a/nag/tasklists/delete.php +++ b/nag/tasklists/delete.php @@ -18,10 +18,6 @@ if (!$GLOBALS['registry']->getAuth()) { $vars = Horde_Variables::getDefaultVariables(); $tasklist_id = $vars->get('t'); -if ($tasklist_id == $GLOBALS['registry']->getAuth()) { - $notification->push(_("This task list cannot be deleted."), 'horde.warning'); - Horde::url('tasklists/', true)->redirect(); -} try { $tasklist = $nag_shares->getShare($tasklist_id); } catch (Horde_Share_Exception $e) { diff --git a/turba/docs/CHANGES b/turba/docs/CHANGES index 7e82bad59..42cf84a5c 100644 --- a/turba/docs/CHANGES +++ b/turba/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Create a default address book if the user doesn't own any yet. [jan] Rename sources.php to backends.php. [mjr] If default addressbook is not browsable, try one from the addressbook pref (Request: 6536). diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index b134c208b..da8319767 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -375,59 +375,45 @@ class Turba { */ function getConfigFromShares($sources) { - global $notification; - try { $shares = Turba::listShares(); } catch (Horde_Share_Exception $e) { - // Notify the user if we failed, but still return the $cfgSource array. - $notification->push($e, 'horde.error'); + // Notify the user if we failed, but still return the $cfgSource + // array. + $GLOBALS['notification']->push($e, 'horde.error'); return $sources; } $sortedShares = $defaults = $vbooks = array(); - $defaults = array(); - foreach (array_keys($shares) as $name) { + $personal = false; + foreach ($shares as $name => &$share) { if (isset($sources[$name])) { continue; } - $params = @unserialize($shares[$name]->get('params')); + $personal |= $share->get('owner') == $GLOBALS['registry']->getAuth(); + + $params = @unserialize($share->get('params')); if (isset($params['type']) && $params['type'] == 'vbook') { // We load vbooks last in case they're based on other shares. - $params['share'] = $shares[$name]; + $params['share'] = $share; $vbooks[$name] = $params; } elseif (!empty($params['source']) && !empty($sources[$params['source']]['use_shares'])) { if (empty($params['name'])) { $params['name'] = $name; - $shares[$name]->set('params', serialize($params)); - $shares[$name]->save(); + $share->set('params', serialize($params)); + $share->save(); } - // Default share? - if (empty($defaults[$params['source']])) { - try { - $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($params['source']); - if ($driver->hasPermission(Horde_Perms::EDIT)) { - $defaults[$params['source']] = $driver->checkDefaultShare( - $shares[$name], - $sources[$params['source']] - ); - } - } catch (Turba_Exception $e) { - $notification->push($e, 'horde.error'); - } - } - - $share = $sources[$params['source']]; - $share['params']['config'] = $sources[$params['source']]; - $share['params']['config']['params']['share'] = $shares[$name]; - $share['params']['config']['params']['name'] = $params['name']; - $share['title'] = $shares[$name]->get('name'); - $share['type'] = 'share'; - $share['use_shares'] = false; - $sortedSources[$params['source']][$name] = $share; + $info = $sources[$params['source']]; + $info['params']['config'] = $sources[$params['source']]; + $info['params']['config']['params']['share'] = $share; + $info['params']['config']['params']['name'] = $params['name']; + $info['title'] = $share->get('name'); + $info['type'] = 'share'; + $info['use_shares'] = false; + $sortedSources[$params['source']][$name] = $info; } } @@ -441,16 +427,16 @@ class Turba { if (isset($sortedSources[$source])) { $newSources = array_merge($newSources, $sortedSources[$source]); } - if ($GLOBALS['registry']->getAuth() && empty($defaults[$source])) { + if ($GLOBALS['registry']->getAuth() && !$personal) { // User's default share is missing. try { $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source); } catch (Turba_Exception $e) { - $notification->push($driver, 'horde.error'); + $GLOBALS['notification']->push($driver, 'horde.error'); continue; } - $sourceKey = strval(new Horde_Support_RandomId()); + $sourceKey = strval(new Horde_Support_Randomid()); try { $share = $driver->createShare( $sourceKey, @@ -470,6 +456,7 @@ class Turba { $source_config = $sources[$source]; $source_config['params']['share'] = $share; $newSources[$sourceKey] = $source_config; + $personal = true; } } @@ -562,11 +549,7 @@ class Turba { if (!isset($params['name'])) { /* Sensible default for empty display names */ $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); - $name = $identity->getValue('fullname'); - if (trim($name) == '') { - $name = $GLOBALS['registry']->getAuth('original'); - } - $name = sprintf(_("%s's Address Book"), $name); + $name = sprintf(_("Address book of %s"), $identity->getName()); } else { $name = $params['name']; unset($params['name']); -- 2.11.0