Skip to content

Commit 76ebeff

Browse files
authored
Merge pull request #6242 from saadmk11/allow-only-post
Allow only post requests for delete views
2 parents a684c9b + 2df26fd commit 76ebeff

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

readthedocs/projects/views/private.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ def form_valid(self, form):
210210

211211
class ProjectVersionDeleteHTML(ProjectVersionMixin, GenericModelView):
212212

213-
http_method_names = ['get', 'post']
213+
http_method_names = ['post']
214214

215-
def get(self, request, *args, **kwargs):
215+
def post(self, request, *args, **kwargs):
216216
version = self.get_object()
217217
if not version.active:
218218
version.built = False
@@ -228,9 +228,6 @@ def get(self, request, *args, **kwargs):
228228
)
229229
return HttpResponseRedirect(self.get_success_url())
230230

231-
def post(self, request, *args, **kwargs):
232-
return self.get(request, *args, **kwargs)
233-
234231

235232
class ImportWizardView(
236233
ProjectImportMixin, ProjectSpamMixin, PrivateViewMixin,
@@ -635,17 +632,14 @@ def get_context_data(self, **kwargs):
635632

636633
class ProjectTranslationsDelete(ProjectTranslationsMixin, GenericView):
637634

638-
http_method_names = ['get', 'post']
635+
http_method_names = ['post']
639636

640-
def get(self, request, *args, **kwargs):
637+
def post(self, request, *args, **kwargs):
641638
project = self.get_project()
642639
translation = self.get_translation(kwargs['child_slug'])
643640
project.translations.remove(translation)
644641
return HttpResponseRedirect(self.get_success_url())
645642

646-
def post(self, request, *args, **kwargs):
647-
return self.get(request, *args, **kwargs)
648-
649643
def get_translation(self, slug):
650644
project = self.get_project()
651645
translation = get_object_or_404(

readthedocs/rtd_tests/tests/test_privacy_urls.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
240240
'/dashboard/import/manual/demo/': {'status_code': 302},
241241
'/dashboard/pip/': {'status_code': 301},
242242
'/dashboard/pip/subprojects/delete/sub/': {'status_code': 302},
243-
'/dashboard/pip/translations/delete/sub/': {'status_code': 302},
244-
245-
# This depends on an inactive project
246-
'/dashboard/pip/version/latest/delete_html/': {'status_code': 400},
247243

248244
# 405's where we should be POST'ing
249245
'/dashboard/pip/users/delete/': {'status_code': 405},
@@ -254,6 +250,8 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
254250
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
255251
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
256252
'/dashboard/pip/environmentvariables/{environmentvariable_id}/delete/': {'status_code': 405},
253+
'/dashboard/pip/translations/delete/sub/': {'status_code': 405},
254+
'/dashboard/pip/version/latest/delete_html/': {'status_code': 405},
257255
}
258256

259257
def get_url_path_ctx(self):
@@ -290,6 +288,8 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
290288
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
291289
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
292290
'/dashboard/pip/environmentvariables/{environmentvariable_id}/delete/': {'status_code': 405},
291+
'/dashboard/pip/translations/delete/sub/': {'status_code': 405},
292+
'/dashboard/pip/version/latest/delete_html/': {'status_code': 405},
293293
}
294294

295295
# Filtered out by queryset on projects that we don't own.

readthedocs/templates/projects/project_translations.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ <h3> {% trans "Existing Translations" %} </h3>
4444
{{ lang_project.name }} ({{ lang_project.get_language_display }})
4545
</a>
4646
<ul class="module-item-menu">
47-
<li><a href="{% url "projects_translations_delete" project.slug lang_project.slug %}">{% trans "Remove" %}</a></li>
47+
<li>
48+
<form method="post" action="{% url "projects_translations_delete" project.slug lang_project.slug %}">
49+
{% csrf_token %}
50+
<input type="submit" value="{% trans 'Remove' %}">
51+
</form>
52+
</li>
4853
</ul>
4954
</li>
5055
{% empty %}

readthedocs/templates/projects/project_version_detail.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ <h2> Editing {{ version.slug }} </h2>
1919

2020
{% if request.user|is_admin:project %}
2121
{% if not version.active and version.built %}
22+
<form name="version_delete_html" method="post" action="{% url "project_version_delete_html" project.slug version.slug %}">
23+
{% csrf_token %}
24+
</form>
2225
<p class="empty">
23-
{% url "project_version_delete_html" project.slug version.slug as version_delete_url %}
26+
{# We are submitting the form using javascript because it breaks the UI design if we use buttons #}
2427
{% blocktrans trimmed %}
2528
This version is inactive but its documentation is still available online.
26-
You can <a href="{{ version_delete_url }}">delete this version's documentation</a> if you want to remove it completely.
29+
You can <a href="#" onclick="document.forms['version_delete_html'].submit();">delete this version's documentation</a> if you want to remove it completely.
2730
{% endblocktrans %}
2831
</p>
2932
{% endif %}

0 commit comments

Comments
 (0)