Jelajahi Sumber

HUE-797 [useradmin] Admin cannot delete a user account.

The list_users.mako template had a javascript function that created a popup.
The template for the popup was taken and put into delete_user.mako.
Then, the delete_user view was updated to include appropriate context vars.
New javascript code was added to appropriately call an HTML page by sending X-Requested-With header.
The result of this call is placed into a container, which is then shown to the user.

test_user_admin was updated to reflect updates in views.
abec 13 tahun lalu
induk
melakukan
9a40ef8580

+ 28 - 0
apps/useradmin/src/useradmin/templates/delete_user.mako

@@ -0,0 +1,28 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from django.utils.translation import ugettext as _
+%>
+<form id="deleteUserForm" action="${path}" method="POST">
+    <div class="modal-header">
+        <a href="#" class="close" data-dismiss="modal">&times;</a>
+        <h3 id="deleteUserMessage">${_("Are you sure you want to delete ")} ${username}${_("?")}</h3>
+    </div>
+    <div class="modal-footer">
+        <input type="submit" class="btn primary" value="${_('Yes')}"/>
+        <a href="#" class="btn secondary" data-dismiss="modal">${_('No')}</a>
+    </div>
+</form>

+ 12 - 16
apps/useradmin/src/useradmin/templates/list_users.mako

@@ -100,18 +100,8 @@ ${layout.menubar(section='users', _=_)}
         </div>
     </div>
 
-    <div id="deleteUser" class="modal hide fade userModal">
-        <form id="deleteUserForm" action="" method="POST">
-        <div class="modal-header">
-            <a href="#" class="close" data-dismiss="modal">&times;</a>
-            <h3 id="deleteUserMessage">${_('Confirm action')}</h3>
-        </div>
-        <div class="modal-footer">
-            <input type="submit" class="btn primary" value="${_('Yes')}"/>
-            <a href="#" class="btn secondary" data-dismiss="modal">${_('No')}</a>
-        </div>
-        </form>
-    </div>
+    <div id="deleteUser" class="modal hide fade"></div>
+
 </div>
 
     <script type="text/javascript" charset="utf-8">
@@ -136,11 +126,17 @@ ${layout.menubar(section='users', _=_)}
 
             $(".confirmationModal").click(function(){
                 var _this = $(this);
-                $.getJSON(_this.attr("data-confirmation-url"), function(data){
-                    $("#deleteUserForm").attr("action", data.path);
-                    $("#deleteUserMessage").text(_this.attr("alt"));
+                $.ajax({
+                    url: _this.attr("data-confirmation-url"),
+                    beforeSend: function(xhr){
+                        xhr.setRequestHeader("X-Requested-With", "Hue");
+                    },
+                    dataType: "html",
+                    success: function(data){
+                        $("#deleteUser").html(data);
+                        $("#deleteUser").modal("show");
+                    }
                 });
-                $("#deleteUser").modal("show");
             });
 
             $("#filterInput").keyup(function(){

+ 1 - 1
apps/useradmin/src/useradmin/tests.py

@@ -347,7 +347,7 @@ def test_user_admin():
   # Delete that regular user
   funny_profile = UserProfile.objects.get(user=test_user)
   response = c_su.post('/useradmin/users/delete/%s' % (FUNNY_NAME_QUOTED,))
-  assert_true("Hue Users" in response.content)
+  assert_equal(302, response.status_code)
   assert_false(User.objects.filter(username=FUNNY_NAME).exists())
   assert_false(UserProfile.objects.filter(id=funny_profile.id).exists())
 

+ 2 - 4
apps/useradmin/src/useradmin/views.py

@@ -70,13 +70,11 @@ def delete_user(request, username):
         __users_lock.release()
 
       # Send a flash message saying "deleted"?
-      return list_users(request)
+      return redirect(reverse(list_users))
     except User.DoesNotExist:
       raise PopupException(_("User not found."))
   else:
-    return render("confirm.mako",
-      request,
-      dict(path=request.path, title=_("Delete user?")))
+    return render("delete_user.mako", request, dict(path=request.path, username=username))
 
 def delete_group(request, name):
   if not request.user.is_superuser: