[Mpuls-commits] r1456 - wasko/branches/2.0/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 10 12:55:53 CET 2010


Author: torsten
Date: 2010-02-10 12:55:53 +0100 (Wed, 10 Feb 2010)
New Revision: 1456

Modified:
   wasko/branches/2.0/mpulsweb/controllers/administration.py
Log:
* mpulsweb/controllers/administration.py
(AdministrationController.deleteUser): Copied from waskaweb. Removed
try/except blocks. Adapted c-vars for dialogs.


Modified: wasko/branches/2.0/mpulsweb/controllers/administration.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/administration.py	2010-02-10 11:55:25 UTC (rev 1455)
+++ wasko/branches/2.0/mpulsweb/controllers/administration.py	2010-02-10 11:55:53 UTC (rev 1456)
@@ -17,6 +17,14 @@
 RESET_PASSWORD_CONFIRM_QUESTION = _('adm_reset_user_password_question')
 EDIT_USER_SUCCESS_HEADER = _('adm_edit_user_header')
 EDIT_USER_SUCCESS_TEXT = _('adm_edit_user_text')
+DELETE_USER_CONFIRM = _('adm_delete_user_confirm_header')
+DELETE_USER_CONFIRM_QUESTION = _('adm_delete_user_confirm_text')
+DELETE_USER_SUCCESS_HEADER = _('adm_delete_user_success_header')
+DELETE_USER_SUCCESS_TEXT = _('adm_delete_user_success_text')
+DELETE_SELFUSER_FAILURE = _('adm_delete_selfuser_notification_header')
+DELETE_SELFUSER_FAILURE_TEXT = _('adm_delete_selfuser_notification_text')
+DELETE_USER_HASCASES = _('Test') 
+DELETE_USER_HASCASES_TEXT = _('TesTestt')
 
 NEW_USERGROUP_SUCCESS_HEADER = _('adm_new_usergroup_success_header')
 NEW_USERGROUP_SUCCESS_TEXT = _('adm_new_usergroup_success_text')
@@ -33,6 +41,9 @@
 
 log = logging.getLogger(__name__)
 
+def user_has_cases(user):
+    return True
+
 class AdministrationController(BaseController):
 
     # USER
@@ -124,6 +135,44 @@
             c.url_no = "/administration/showUser/%s" % id
             return render('/administration/dialogs/confirm_resetpassword.mako')
 
+    @checkRole('admin_ka')
+    def deleteUser(self, id, confirmed='0'):
+        id = self._checkInt(id)
+        confirmed = self._checkBool(confirmed)
+        uo = UserObject(id)
+
+        # Make sure that the user can not delete himself
+        if uo.id == session.get('USER_AUTHORIZED').id:
+            c.dialog_title = DELETE_SELFUSER_FAILURE
+            c.dialog_text = DELETE_SELFUSER_FAILURE_TEXT
+            c.url_ok = "/administration/overviewUser"
+            return render('/administration/dialogs/failed_delete_user.mako')
+
+        if confirmed:
+            # Check if there are cases for which the user is the editor. If
+            # he is an editor then raise a error dialog 
+            if user_has_cases(uo):
+                c.dialog_title = DELETE_USER_HASCASES 
+                c.dialog_text = DELETE_USER_HASCASES_TEXT
+                c.url_ok = "/administration/overviewUser"
+                return render('/administration/dialogs/failed_delete_user.mako')
+            else:
+                uo.delete()
+                c.dialog_title = DELETE_USER_SUCCESS_HEADER
+                c.dialog_text = DELETE_USER_SUCCESS_TEXT
+                c.url_ok = "/administration/overviewUser"
+                return render('/administration/dialogs/success_delete_user.mako')
+
+        else:
+            c.context = "../main.mako"
+            c.dialog_title = DELETE_USER_CONFIRM
+            c.dialog_text = DELETE_USER_CONFIRM_QUESTION % (uo.last_name,
+                                                         uo.first_name,
+                                                         uo.login)
+            c.url_yes = "/administration/deleteUser/%s/1" % id
+            c.url_no = "/administration/overviewUser/"
+            return render('/administration/dialogs/confirm_deleteuser.mako')
+
     # USERGROUPS
     @checkRole('admin_ka')
     def overviewUserGroups(self):



More information about the Mpuls-commits mailing list