0012584: cronuser needs to be in admin group
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 31 Jan 2017 08:26:40 +0000 (09:26 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 31 Jan 2017 14:35:37 +0000 (15:35 +0100)
https://forge.tine20.org/view.php?id=12584

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

index 6509a51..61a5131 100644 (file)
@@ -618,8 +618,15 @@ class Setup_Frontend_Cli
                 Tinebase_User::getInstance()->setPassword($user, $password);
                 echo "User password has been reset.\n";
             }
-            
-            $this->_checkAdminGroupMembership($user);
+
+            try {
+                Tinebase_User::getInstance()->assertAdminGroupMembership($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();
+            }
+
             $this->_checkAdminRole($user);
             
         } catch (Tinebase_Exception_NotFound $tenf) {
@@ -634,27 +641,7 @@ class Setup_Frontend_Cli
         }
     }
 
-    /**
-     * 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";
-                // @todo clear roles/groups cache
-            } catch (Exception $e) {
-                Tinebase_Exception::log($e);
-                echo "Could not add user to default admin group: " . $e->getMessage();
-            }
-        }
-    }
-    
+
     /**
      * check admin role membership
      * 
index cf10f2b..4ccb18e 100644 (file)
@@ -303,6 +303,11 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
             $cronuserId = Tinebase_Config::getInstance()->get(Tinebase_Config::CRONUSERID);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting user with id ' . $cronuserId . ' as cronuser.');
             $cronuser = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $cronuserId, 'Tinebase_Model_FullUser');
+            try {
+                Tinebase_User::getInstance()->assertAdminGroupMembership($cronuser);
+            } catch (Exception $e) {
+                Tinebase_Exception::log($e);
+            }
         } catch (Tinebase_Exception_NotFound $tenf) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
             
@@ -312,7 +317,7 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
         
         return $cronuser;
     }
-    
+
     /**
      * create new cronuser
      * 
index 886fb4b..ce3fcae 100644 (file)
@@ -585,6 +585,20 @@ abstract class Tinebase_User_Abstract implements Tinebase_User_Interface
         return $backend->searchCount($filter);
     }
 
+    /**
+     * check admin group membership
+     *
+     * @param Tinebase_Model_FullUser $user
+     */
+    public function assertAdminGroupMembership($user)
+    {
+        $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
+        $memberships = Tinebase_Group::getInstance()->getGroupMemberships($user);
+        if (! in_array($adminGroup->getId(), $memberships)) {
+            Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
+        }
+    }
+
     /******************* abstract functions *********************/
     
     /**