changeset 6155:9b80c2a64781

admin: don't redirect back to the list of users after creating a user Staying on the user page gives a more natural flow, instead of having to click the link in the 'Created' flash message to get back to the user.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 06 Sep 2016 00:51:18 +0200
parents e8bd3f074b4e
children d9757113c013
files kallithea/controllers/admin/users.py kallithea/tests/functional/test_admin_users.py
diffstat 2 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/users.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/controllers/admin/users.py	Tue Sep 06 00:51:18 2016 +0200
@@ -122,10 +122,9 @@
         try:
             form_result = user_form.to_python(dict(request.POST))
             user = user_model.create(form_result)
-            usr = form_result['username']
-            action_logger(self.authuser, 'admin_created_user:%s' % usr,
+            action_logger(self.authuser, 'admin_created_user:%s' % user.username,
                           None, self.ip_addr, self.sa)
-            h.flash(h.literal(_('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))),
+            h.flash(_('Created user %s') % user.username,
                     category='success')
             Session().commit()
         except formencode.Invalid as errors:
@@ -142,7 +141,7 @@
             log.error(traceback.format_exc())
             h.flash(_('Error occurred during creation of user %s') \
                     % request.POST.get('username'), category='error')
-        raise HTTPFound(location=url('users'))
+        raise HTTPFound(location=url('edit_user', id=user.user_id))
 
     def new(self, format='html'):
         c.default_extern_type = auth_internal.KallitheaAuthPlugin.name
--- a/kallithea/tests/functional/test_admin_users.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/tests/functional/test_admin_users.py	Tue Sep 06 00:51:18 2016 +0200
@@ -76,9 +76,13 @@
              'extern_type': 'internal',
              'email': email,
              '_authentication_token': self.authentication_token()})
+        # 302 Found
+        # The resource was found at http://localhost/_admin/users/5/edit; you should be redirected automatically.
 
-        self.checkSessionFlash(response, '''Created user <a href="/_admin/users/''')
-        self.checkSessionFlash(response, '''/edit">%s</a>''' % (username))
+        self.checkSessionFlash(response, '''Created user %s''' % username)
+
+        response = response.follow()
+        response.mustcontain("""%s user settings""" % username) # in <title>
 
         new_user = Session().query(User). \
             filter(User.username == username).one()
@@ -89,10 +93,6 @@
         assert new_user.lastname == lastname
         assert new_user.email == email
 
-        response.follow()
-        response = response.follow()
-        response.mustcontain("""newtestuser""")
-
     def test_create_err(self):
         self.log_user()
         username = 'new_user'