[icinga-checkins] icinga.org: icinga-web/master: * Delete users fix ( remove cronks and cronk principals)

git at icinga.org git at icinga.org
Thu Dec 15 12:28:42 CET 2011


Module: icinga-web
Branch: master
Commit: 9f0bba3b6f75eefa8d066ecd66575eed44f50ae2
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=9f0bba3b6f75eefa8d066ecd66575eed44f50ae2

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Dec 15 12:28:20 2011 +0100

* Delete users fix (remove cronks and cronk principals)

---

 .../DataProvider/UserProviderAction.class.php      |   30 +++++++------------
 .../lib/database/models/generated/BaseNsmUser.php  |   11 +++++++
 app/modules/AppKit/lib/js/admin/UserManager.js     |    2 +-
 app/modules/AppKit/models/UserAdminModel.class.php |   30 ++++++++++++++++++-
 4 files changed, 51 insertions(+), 22 deletions(-)

diff --git a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
index e06a4ec..aeae56a 100644
--- a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
+++ b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
@@ -167,27 +167,19 @@ class AppKit_DataProvider_UserProviderAction extends AppKitBaseAction {
     }
 
     public function executeRemove(AgaviRequestDataHolder $rd) {
-
-        try {
-            AppKitDoctrineUtil::getConnection()->beginTransaction();
-            $useradmin = $this->getContext()->getModel('UserAdmin', 'AppKit');
-            $padmin = $this->getContext()->getModel('PrincipalAdmin', 'AppKit');
-            $ids = $rd->getParameter("ids",array());
-            foreach($ids as $id) {
-                $user = $useradmin->getUserById($id);
-
-                if (!$user) {
-                    continue;
-                }
-
-                $useradmin->removeUser($user);
+        $useradmin = $this->getContext()->getModel('UserAdmin', 'AppKit');
+        $padmin = $this->getContext()->getModel('PrincipalAdmin', 'AppKit');
+        
+        $ids = $rd->getParameter("ids",array());
+        
+        foreach($ids as $id) {
+            $user = $useradmin->getUserById($id);
+
+            if (!$user) {
+                continue;
             }
-            AppKitDoctrineUtil::getConnection()->commit();
-        } catch (Exception $e) {
-            try {
-                AppKitDoctrineUtil::getConnection()->rollback();
-            } catch (Doctrine_Transaction_Exception $e) {}
 
+            $useradmin->removeUser($user);
         }
 
         return 'Success';
diff --git a/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php b/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php
index 915e638..30aab75 100644
--- a/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php
+++ b/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php
@@ -176,6 +176,17 @@ abstract class BaseNsmUser extends Doctrine_Record {
         $this->hasMany('NsmUserRole as roles', array(
                            'local' => 'user_id',
                            'foreign' => 'usro_user_id'));
+        
+        $this->hasMany('Cronk as cronks', array(
+                           'local' => 'user_id',
+                           'foreign' => 'cronk_user_id'
+        ));
+        
+        $this->hasMany('CronkPrincipalCronk as cronkPrincipals', array(
+                           'local' => 'principal_user_id',
+                           'foreign' => 'principal_id',
+                           'refClass' => 'NsmPrincipal'
+        ));
     }
     public static function getInitialData() {
         return  array(
diff --git a/app/modules/AppKit/lib/js/admin/UserManager.js b/app/modules/AppKit/lib/js/admin/UserManager.js
index efb6c16..8d61d3a 100644
--- a/app/modules/AppKit/lib/js/admin/UserManager.js
+++ b/app/modules/AppKit/lib/js/admin/UserManager.js
@@ -59,7 +59,7 @@ Ext.ns("AppKit.Admin");
                 iconCls: 'icinga-icon-user',
 
                 deleteSelected: function () {
-                    Ext.Msg.confirm(_("Delete user"), _("Do you really want to delete these users?"), function (btn) {
+                    Ext.Msg.confirm(_("Delete user"), _("Do you really want to delete these users and their settings and cronks?"), function (btn) {
                         if (btn !== "yes") {
                             return false;
                         }
diff --git a/app/modules/AppKit/models/UserAdminModel.class.php b/app/modules/AppKit/models/UserAdminModel.class.php
index 2a55631..41b8cad 100644
--- a/app/modules/AppKit/models/UserAdminModel.class.php
+++ b/app/modules/AppKit/models/UserAdminModel.class.php
@@ -184,7 +184,32 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
 
     public function removeUser(NsmUser &$user) {
         try {
+            
+            /*
+            * These are our connections to any cronks
+            */
+        
+            foreach($user->cronkPrincipals as $cp) {
+                $re = AppKitDoctrineUtil::createQuery()->delete('CronkPrincipalCronk cpc')
+                ->andWhere('cpc.cpc_cronk_id=? and cpc.cpc_principal_id=?', array($cp->cpc_cronk_id, $cp->cpc_principal_id))
+                ->execute();
+            }
+            /*
+             * Our cronks
+            */
+            foreach ($user->cronks as $cronk) {
+                /*
+                 * All connections to our cronks
+                */
+                AppKitDoctrineUtil::createQuery()->delete('CronkPrincipalCronk cpc')
+                ->andWhere('cpc.cpc_cronk_id=?', array($cronk->cronk_id))
+                ->execute();
+            
+                $cronk->delete();
+            }
+            
             AppKitDoctrineUtil::getConnection()->beginTransaction();
+            
             $this->updateUserroles($user,array());
             $targets = $user->getTargets();
             foreach($targets as $target) {
@@ -194,7 +219,7 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
                 }
             }
             $principals = $user->getPrincipals();
-
+            
             if (!$principals instanceof NsmPrincipal) {
                 foreach($principals as $pr) {
                     if ($pr->NsmPrincipalTarget) {
@@ -214,8 +239,9 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
 
                 $principals->delete();
             }
-
+            
             $user->delete();
+            
             AppKitDoctrineUtil::getConnection()->commit();
 
             return true;





More information about the icinga-checkins mailing list