On 06/03/2015 10:05 PM, Thomas De Schampheleire wrote:
# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schamphele...@gmail.com>
# Date 1433359538 -7200
#      Wed Jun 03 21:25:38 2015 +0200
# Node ID 6a6119935ed636def910c4c4495ac2e4213d9ae7
# Parent  6e8effd028bf41a132aee02e52ffc0bf990dadf4
admin: users: factorize check for default user

Note that one specific unittest has been commented because it relies on
pytest features (monkeypatch). When pytest is the default test runner, the
test should be uncommented.

diff --git a/kallithea/controllers/admin/users.py 
b/kallithea/controllers/admin/users.py
--- a/kallithea/controllers/admin/users.py
+++ b/kallithea/controllers/admin/users.py
@@ -34,6 +34,7 @@ from pylons import request, tmpl_context
  from pylons.controllers.util import redirect
  from pylons.i18n.translation import _
  from sqlalchemy.sql.expression import func
+from webob.exc import HTTPNotFound
import kallithea
  from kallithea.lib.exceptions import DefaultUserException, \
@@ -233,14 +234,17 @@ class UsersController(BaseController):
          # url('user', id=ID)
          User.get_or_404(-1)
+ def _get_user_or_raise_if_default(self, id):
+        try:
+            return User.get_or_404(id, allow_default=False)
+        except DefaultUserException:
+            h.flash(_("The default user cannot be edited"), category='warning')

i guess this really should be an error?

I can fix on the fly.

/Mads

+            raise HTTPNotFound
+
      def edit(self, id, format='html'):
          """GET /users/id/edit: Form to edit an existing item"""
          # url('edit_user', id=ID)
-        c.user = User.get_or_404(id)
-        if c.user.username == User.DEFAULT_USER:
-            h.flash(_("You can't edit this user"), category='warning')
-            return redirect(url('users'))
-
+        c.user = self._get_user_or_raise_if_default(id)
          c.active = 'profile'
          c.extern_type = c.user.extern_type
          c.extern_name = c.user.extern_name


_______________________________________________
kallithea-general mailing list
kallithea-general@sfconservancy.org
http://lists.sfconservancy.org/mailman/listinfo/kallithea-general

Reply via email to