[Mpuls-commits] r2084 - wasko/branches/2.0/mpulsweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Mar 23 14:55:22 CET 2010
Author: torsten
Date: 2010-03-23 14:55:21 +0100 (Tue, 23 Mar 2010)
New Revision: 2084
Modified:
wasko/branches/2.0/mpulsweb/controllers/administration.py
Log:
Added new dialog to delete users with helper to transfer cases to a new user.
Modified: wasko/branches/2.0/mpulsweb/controllers/administration.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/administration.py 2010-03-23 13:52:27 UTC (rev 2083)
+++ wasko/branches/2.0/mpulsweb/controllers/administration.py 2010-03-23 13:55:21 UTC (rev 2084)
@@ -10,9 +10,10 @@
from mpulsweb.lib.base import BaseController, render
from mpulsweb.lib.security import checkRole, getDbName
from mpulsweb.lib.validators import ValidatorStateObject, NewUserGroupForm, \
- EditUserGroupForm , NewUserForm, EditUserForm
+ EditUserGroupForm , NewUserForm, EditUserForm, DeleteUserHelperForm
from mpulsweb.model.user import UserListObject, UserObject, UserGroupList, \
UserGroup, UserGroupFactory
+from mpulsweb.model.case import MpulsCaseOverview, MpulsCaseBundle
RESET_PASSWORD_CONFIRM = _('adm_reset_user_password')
RESET_PASSWORD_CONFIRM_QUESTION = _('adm_reset_user_password_question')
@@ -26,6 +27,12 @@
DELETE_SELFUSER_FAILURE_TEXT = _('adm_delete_selfuser_notification_text')
DELETE_USER_HASCASES = _(u'Der Benutzer konnte nicht gelöscht werden')
DELETE_USER_HASCASES_TEXT = _(u'Der Benutzer konnte nicht gelöscht werden, da dieser noch Bearbeiter von mindestens einen Fall ist. Bitte übertragen Sie zunächst sämtliche Fälle dieses Nutzers an einen anderen Bearbeiter und wiederholen Sie den Vorgang erneut. Klicken Sie auf "OK", um zur Benutzerübersicht zurück zu kehren.')
+DIALOG_CONFIRM_SETEDITOR = _('adm_set_editor_header')
+SETEDITOR_NOTIFICATION_SUCCESS = _('adm_set_editor_success_text')
+SETEDITOR_NOTIFICATION_SUCCESS_REST = _('adm_set_editor_success_text_rest')
+SETEDITOR_NOTIFICATION_SUCCESS_HEAD = _('adm_set_editor_success_text_head')
+SETEDITOR_NOTIFICATION_SUCCESS_REST_HEAD = \
+ _('adm_set_editor_success_text_rest_head')
NEW_USERGROUP_SUCCESS_HEADER = _('adm_new_usergroup_success_header')
NEW_USERGROUP_SUCCESS_TEXT = _('adm_new_usergroup_success_text')
@@ -149,43 +156,133 @@
c.url_no = "/administration/showUser/%s" % id
return render('/administration/dialogs/confirm_resetpassword.mako')
- @checkRole('admin_ka')
+ # Old deleteUser method, which does not raise a helper dialog to transfer
+ # remaining cases to a another user before deletion. Simply raise an
+ # error-dialog an cance action.
+
+ #@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')
+
+ @checkRole('admin')
def deleteUser(self, id, confirmed='0'):
id = self._checkInt(id)
confirmed = self._checkBool(confirmed)
- uo = UserObject(id)
+ try:
+ uo = UserObject(id)
+ # Make sure that the user can not delete himself
+ if uo.id == session.get('USER_AUTHORIZED').id:
+ c.failed_for = DELETE_SELFUSER_FAILURE
+ c.failed_text = DELETE_SELFUSER_FAILURE_TEXT
+ c.url_ok = "/administration/overviewUser"
+ return render('/administration/dialogs/failed_delete_user.mako')
- # 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 dialog which allows the user to
+ # transfer the cases.
+ overview = MpulsCaseOverview()
+ overview.search('editor:%s;'
+ 'state:1;state:2;state:3;state:4;state:5'
+ % uo.id)
+ if overview.getDatasets():
+ list = UserListObject()
+ filter = [u.id for u in list.getAdminList()]
+ filter.append(uo.id) #the user we want to delete
+ c.user_list = list.getUserList(filter)
+ c.cases = overview
+ c.delete_user_id = id
+ return render('/administration/delete_user_helper.mako')
+ else:
+ uo.delete()
+ c.notification_for = DELETE_USER_NOTIFICATION_SUCCESS
+ c.notification_text = DELETE_USER_NOTIFICATION_TEXT_SUCCESS
+ c.success_for = DELETE_USER_SUCCESS_HEADER
+ c.success_text = DELETE_USER_SUCCESS_TEXT
+ c.url_ok = "/administration/overviewUser"
+ return render('/administration/dialogs/success_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')
+ c.context = "../main.mako"
+ c.confirm_for = DELETE_USER_CONFIRM
+ c.question = 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')
+ except:
+ return render('/tests/trace.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')
+ @checkRole('admin')
+ def deleteUserHelper(self):
+ validator = DeleteUserHelperForm()
+ all_cases = MpulsCaseOverview()
+ c.notification_for = DIALOG_CONFIRM_SETEDITOR
+ c.form_errors = {}
+ c.form_result = {}
+ try:
+ data = formencode.variabledecode.variable_decode(request.params)
+ form_result = validator.to_python(data)
+ case_bundle = MpulsCaseBundle(form_result.get('case_id', []))
+ new_editor = UserObject(form_result.get('editor'))
+ del_user = UserObject(form_result.get('user_id'))
+ all_cases.search('editor:%s;state:1;state:2;state:3;state:4;state:5'
+ % del_user.id)
+ num = case_bundle.setEditor(form_result.get('editor'))
+ rest = all_cases.numDatasets() - case_bundle.numDatasets()
+ c.url_ok = ("/administration/deleteUser/%s/1"
+ % form_result.get('user_id'))
+ c.success_for = SETEDITOR_NOTIFICATION_SUCCESS_HEAD
+ if rest > 0:
+ c.success_for = SETEDITOR_NOTIFICATION_SUCCESS_REST_HEAD
+ c.success_text = (SETEDITOR_NOTIFICATION_SUCCESS_REST
+ % (new_editor.first_name,
+ new_editor.last_name,
+ del_user.first_name, del_user.last_name))
+ else:
+ c.success_for = SETEDITOR_NOTIFICATION_SUCCESS_HEAD
+ c.success_text = (SETEDITOR_NOTIFICATION_SUCCESS
+ % (new_editor.first_name,
+ new_editor.last_name,
+ del_user.first_name, del_user.last_name))
+ return render('/administration/dialogs/notificate_delete_user_helper.mako')
+ except formencode.Invalid, error:
+ return self.deleteUser(form_result.get('user_id'), '1')
# USERGROUPS
@checkRole('admin_ka')
More information about the Mpuls-commits
mailing list