superuser tweaks.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 11 Jan 2011 00:56:13 +0000 (00:56 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 11 Jan 2011 00:56:13 +0000 (00:56 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1187 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/urls.py
conifer/syrup/views/admin.py
conifer/templates/admin/su.xhtml [new file with mode: 0644]

index 511935b..ba4965a 100644 (file)
@@ -54,7 +54,7 @@ urlpatterns = patterns('conifer.syrup.views',
     (r'^admin/update_depts_courses/$', 'admin_update_depts_courses'),
     (r'^admin/update_terms/$', 'admin_update_terms'),
     (r'^admin/staff/add/$', 'admin_staff_add'),
-    (r'^admin/su/(?P<userid>.*)', 'admin_su'),
+    (r'^admin/su/', 'admin_su'),
 
 
     # (r'^phys/$', 'phys_index'),
index 432e780..17a83e0 100644 (file)
@@ -177,13 +177,17 @@ def admin_staff_add(request):
         return g.render('admin/staff_add.xhtml', **locals())
 
 @admin_only
-def admin_su(request, userid):
-    user, created = User.objects.get_or_create(username=userid)
-    user.maybe_decorate()
-    if created and not user.last_name:
-        raise Exception(user)
-        user.delete()
-    elif user.is_active:
-        request.session['_auth_user_id'] = user.id
-    return HttpResponseRedirect('../../')
+def admin_su(request):
+    if request.method != 'POST':
+        return g.render('admin/su.xhtml')
+    else:
+        userid = request.POST['userid'].lower().strip()
+        user, created = User.objects.get_or_create(username=userid)
+        user.maybe_decorate()
+        if created and not user.last_name:
+            user.delete()
+            return g.render('admin/su.xhtml')
+        elif user.is_active:
+            request.session['_auth_user_id'] = user.id
+        return HttpResponseRedirect('../../')
 
diff --git a/conifer/templates/admin/su.xhtml b/conifer/templates/admin/su.xhtml
new file mode 100644 (file)
index 0000000..87421ea
--- /dev/null
@@ -0,0 +1,22 @@
+<?python
+title = _('Impersonate another user')
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="../master.xhtml"/>
+<head>
+  <title>${title}</title>
+  <style type="text/css">
+    ul { margin-bottom: 2em; }
+  </style>
+</head>
+<body>
+  <h1>${title}</h1>
+  <form action="." method="POST">
+       <p>UWin ID to impersonate:</p>
+       <p><input type="text" name="userid"/></p>
+       <p><input type="submit" value="Impersonate"/></p>
+  </form>
+</body>
+</html>