Add a setting whether to create default shares if the user doesn't own any.
authorJan Schneider <jan@horde.org>
Mon, 8 Nov 2010 22:55:47 +0000 (23:55 +0100)
committerJan Schneider <jan@horde.org>
Mon, 8 Nov 2010 22:55:47 +0000 (23:55 +0100)
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.

14 files changed:
horde/config/conf.xml
horde/docs/CHANGES
kronolith/calendars/delete.php
kronolith/docs/CHANGES
kronolith/lib/Kronolith.php
mnemo/docs/CHANGES
mnemo/lib/Forms/DeleteNotepad.php
mnemo/lib/Mnemo.php
mnemo/notepads/delete.php
nag/docs/CHANGES
nag/lib/Nag.php
nag/tasklists/delete.php
turba/docs/CHANGES
turba/lib/Turba.php

index eacc07e..5e78385 100644 (file)
    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</configboolean>
+   <configboolean name="auto_create" required="false" desc="Automatically
+   create personal default shares for any users that don't own any
+   shares?">true</configboolean>
    <configboolean name="world" required="false" desc="If you enable this
    option, users will be able to share their resources with all (authenticated
    and guest) users on the system.">true</configboolean>
index 618be10..79e9248 100644 (file)
@@ -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.
index 2885282..62d6bd1 100644 (file)
@@ -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();
index e00bd52..2723515 100644 (file)
@@ -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
index 8dde0a9..c0d735e 100644 (file)
@@ -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()))) {
index 1ba41ed..736e2d6 100644 (file)
@@ -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.
 
index 6257832..c357cdf 100644 (file)
@@ -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;
     }
 
index 88c9094..45a4383 100644 (file)
@@ -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']));
index 350f03a..a01d8f5 100644 (file)
@@ -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) {
index 950d3cb..b9f812d 100644 (file)
@@ -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
       <js-horde@jk1.net>, Request #9083).
 [jan] Add system task lists (Request #2059).
index c601bb2..a89450c 100644 (file)
@@ -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']));
index 884c80c..9d609c7 100644 (file)
@@ -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) {
index 7e82bad..42cf84a 100644 (file)
@@ -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).
index b134c20..da83197 100644 (file)
@@ -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']);