#9858: allow to --create_admin for LDAP accounts backend
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 25 Apr 2014 09:17:50 +0000 (11:17 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 14 May 2014 14:04:13 +0000 (16:04 +0200)
* removes restiction to SQL backend
* adds helper fn for checking admin group membership

https://forge.tine20.org/mantisbt/view.php?id=9858

Change-Id: Iad94b2a2493d659d3353ab143955daea1a2b0e72
Reviewed-on: http://gerrit.tine20.com/customers/555
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Setup/Frontend/Cli.php

index 3ab8988..cc931f0 100644 (file)
@@ -441,6 +441,7 @@ class Setup_Frontend_Cli
      * @param Zend_Console_Getopt $_opts
      * 
      * @todo check role by rights and not by name
+     * @todo replace echos with stdout logger
      */
     protected function _createAdminUser(Zend_Console_Getopt $_opts)
     {
@@ -471,25 +472,10 @@ class Setup_Frontend_Cli
                 echo "User password has been reset.\n";
             }
             
-            // check admin group membership
-            $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
-            $memberships = Tinebase_Group::getInstance()->getGroupMemberships($user);
-            if (! in_array($adminGroup->getId(), $memberships)) {
-                try {
-                    Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
-                    echo "Added user to default admin group\n";
-                } catch (Zend_Ldap_Exception $zle) {
-                    echo "Could not add user to default admin group: " . $zle->getMessage();
-                }
-            }
-            
+            $this->_checkAdminGroupMembership($user);
             $this->_checkAdminRole($user);
             
         } catch (Tinebase_Exception_NotFound $tenf) {
-            if (Tinebase_User::getConfiguredBackend() !== Tinebase_User::SQL) {
-                die('It is not possible to create a new user with other user backend than SQL here.');
-            }
-            
             // create new admin user that expires tomorrow
             $password = $this->_promptPassword();
             Tinebase_User::createInitialAccounts(array(
@@ -500,6 +486,26 @@ class Setup_Frontend_Cli
             echo "Created new admin user '$username' that expires tomorrow.\n";
         }
     }
+
+    /**
+     * check admin group membership
+     * 
+     * @param Tinebase_Model_FullUser $user
+     */
+    protected function _checkAdminGroupMembership($user)
+    {
+        $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
+        $memberships = Tinebase_Group::getInstance()->getGroupMemberships($user);
+        if (! in_array($adminGroup->getId(), $memberships)) {
+            try {
+                Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
+                echo "Added user to default admin group\n";
+            } catch (Exception $e) {
+                Tinebase_Exception::log($e);
+                echo "Could not add user to default admin group: " . $e->getMessage();
+            }
+        }
+    }
     
     /**
      * check admin role membership