From 04b90633371d14867aa0a3106266300cd5bfa34b Mon Sep 17 00:00:00 2001
From: vijeth-aradhya <vijthaaa@gmail.com>
Date: Fri, 20 Jan 2017 12:31:12 +0530
Subject: [PATCH] user_pages: Remove checkbox prompt while deletion

The usage of a checkbox prompt while deleting media
or collection with the dialogue is not necessary.

Fixes #986
---
 .../user_pages/collection_confirm_delete.html      |   5 -
 .../user_pages/collection_item_confirm_remove.html |   5 -
 .../user_pages/media_confirm_delete.html           |   5 -
 mediagoblin/tests/test_submission.py               |  11 +-
 mediagoblin/user_pages/views.py                    | 124 +++++++++------------
 5 files changed, 52 insertions(+), 98 deletions(-)

diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html b/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html
index 0827834..5ded731 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html
@@ -42,11 +42,6 @@
 
       <br />
 
-      <p class="delete_checkbox_box">
-	{{ form.confirm }}
-	{{ wtforms_util.render_label(form.confirm) }}
-      </p>
-
       <div class="form_submit_buttons">
         {# TODO: This isn't a button really... might do unexpected things :) #}
         <a class="button_action" href="
diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html b/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
index d7ff495..fc6345f 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
@@ -48,11 +48,6 @@
 
       <br />
 
-      <p class="delete_checkbox_box">
-	{{ form.confirm }}
-	{{ wtforms_util.render_label(form.confirm) }}
-      </p>
-
       <div class="form_submit_buttons">
         {# TODO: This isn't a button really... might do unexpected things :) #}
         <a class="button_action" href="
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html b/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
index 243edff..1361011 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
@@ -38,11 +38,6 @@
 
       <br />
 
-      <p class="delete_checkbox_box">
-	{{ form.confirm }}
-	{{ wtforms_util.render_label(form.confirm) }}
-      </p>
-
       <div class="form_submit_buttons">
         {# TODO: This isn't a button really... might do unexpected things :) #}
 	<a class="button_action" href="{{ media.url_for_self(request.urlgen) }}">{% trans %}Cancel{% endtrans %}</a>
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index f51b132..ae5c9d5 100644
--- a/mediagoblin/tests/test_submission.py
+++ b/mediagoblin/tests/test_submission.py
@@ -341,19 +341,12 @@ class TestSubmissionBasics(BaseTestSubmission):
                                 url=comment_url, do_follow=True)[0]
         self.check_comments(request, media_id, 1)
 
-        # Do not confirm deletion
+        # Check Deletion
         # ---------------------------------------------------
         delete_url = request.urlgen(
             'mediagoblin.user_pages.media_confirm_delete',
             user=self.our_user().username, media_id=media_id)
-        # Empty data means don't confirm
-        response = self.do_post({}, do_follow=True, url=delete_url)[0]
-        media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
-        media_id = media.id
-
-        # Confirm deletion
-        # ---------------------------------------------------
-        response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT,
+        response, request = self.do_post({}, *REQUEST_CONTEXT,
                                          do_follow=True, url=delete_url)
         self.check_media(request, {'id': media_id}, 0)
         self.check_comments(request, media_id, 0)
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index eaae1bd..4cd284b 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -332,40 +332,32 @@ def media_confirm_delete(request, media):
     form = user_forms.ConfirmDeleteForm(request.form)
 
     if request.method == 'POST' and form.validate():
-        if form.confirm.data is True:
-            username = media.get_actor.username
+        username = media.get_actor.username
 
-            # This probably is already filled but just in case it has slipped
-            # through the net somehow, we need to try and make sure the
-            # MediaEntry has a public ID so it gets properly soft-deleted.
-            media.get_public_id(request.urlgen)
+        # This probably is already filled but just in case it has slipped
+        # through the net somehow, we need to try and make sure the
+        # MediaEntry has a public ID so it gets properly soft-deleted.
+        media.get_public_id(request.urlgen)
 
-            # Decrement the users uploaded quota.
-            media.get_actor.uploaded = media.get_actor.uploaded - \
-                media.file_size
-            media.get_actor.save()
+        # Decrement the users uploaded quota.
+        media.get_actor.uploaded = media.get_actor.uploaded - \
+            media.file_size
+        media.get_actor.save()
 
-            # Delete MediaEntry and all related files, comments etc.
-            media.delete()
-            messages.add_message(
-                request,
-                messages.SUCCESS,
-                _('You deleted the media.'))
-
-            location = media.url_to_next(request.urlgen)
-            if not location:
-                location=media.url_to_prev(request.urlgen)
-            if not location:
-                location=request.urlgen("mediagoblin.user_pages.user_home",
-                                        user=username)
-            return redirect(request, location=location)
-        else:
-            messages.add_message(
-                request,
-                messages.ERROR,
-                _("The media was not deleted because you didn't check "
-                  "that you were sure."))
-            return redirect_obj(request, media)
+        # Delete MediaEntry and all related files, comments etc.
+        media.delete()
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('You deleted the media.'))
+
+        location = media.url_to_next(request.urlgen)
+        if not location:
+            location=media.url_to_prev(request.urlgen)
+        if not location:
+            location=request.urlgen("mediagoblin.user_pages.user_home",
+                                    user=username)
+        return redirect(request, location=location)
 
     if ((request.user.has_privilege(u'admin') and
          request.user.id != media.actor)):
@@ -436,24 +428,17 @@ def collection_item_confirm_remove(request, collection_item):
         username = collection_item.in_collection.get_actor.username
         collection = collection_item.in_collection
 
-        if form.confirm.data is True:
-            obj = collection_item.get_object()
-            obj.save()
+        obj = collection_item.get_object()
+        obj.save()
 
-            collection_item.delete()
-            collection.num_items = collection.num_items - 1
-            collection.save()
+        collection_item.delete()
+        collection.num_items = collection.num_items - 1
+        collection.save()
 
-            messages.add_message(
-                request,
-                messages.SUCCESS,
-                _('You deleted the item from the collection.'))
-        else:
-            messages.add_message(
-                request,
-                messages.ERROR,
-                _("The item was not removed because you didn't check "
-                  "that you were sure."))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('You deleted the item from the collection.'))
 
         return redirect_obj(request, collection)
 
@@ -482,37 +467,28 @@ def collection_confirm_delete(request, collection):
     if request.method == 'POST' and form.validate():
 
         username = collection.get_actor.username
+        
+        collection_title = collection.title
 
-        if form.confirm.data is True:
-            collection_title = collection.title
-
-            # Firstly like with the MediaEntry delete, lets ensure the
-            # public_id is populated as this is really important!
-            collection.get_public_id(request.urlgen)
-
-            # Delete all the associated collection items
-            for item in collection.get_collection_items():
-                obj = item.get_object()
-                obj.save()
-                item.delete()
+        # Firstly like with the MediaEntry delete, lets ensure the
+        # public_id is populated as this is really important!
+        collection.get_public_id(request.urlgen)
 
-            collection.delete()
-            messages.add_message(
-                request,
-                messages.SUCCESS,
-                _('You deleted the collection "%s"') %
-                    collection_title)
+        # Delete all the associated collection items
+        for item in collection.get_collection_items():
+            obj = item.get_object()
+            obj.save()
+            item.delete()
 
-            return redirect(request, "mediagoblin.user_pages.user_home",
-                user=username)
-        else:
-            messages.add_message(
-                request,
-                messages.ERROR,
-                _("The collection was not deleted because you didn't "
-                  "check that you were sure."))
+        collection.delete()
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('You deleted the collection "%s"') %
+                collection_title)
 
-            return redirect_obj(request, collection)
+        return redirect(request, "mediagoblin.user_pages.user_home",
+            user=username)
 
     if ((request.user.has_privilege(u'admin') and
          request.user.id != collection.actor)):
-- 
2.7.4

