From 6ab83a0e17d4e1362b8d4df520c9fef9c82035df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Tue, 29 Mar 2022 16:55:03 +0200 Subject: [PATCH] applications: add link to delete applications (#63273) --- .../hobo/applications/app_confirm_delete.html | 19 +++++++++++ hobo/applications/urls.py | 1 + hobo/applications/views.py | 11 +++++++ tests/test_application.py | 33 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 hobo/applications/templates/hobo/applications/app_confirm_delete.html diff --git a/hobo/applications/templates/hobo/applications/app_confirm_delete.html b/hobo/applications/templates/hobo/applications/app_confirm_delete.html new file mode 100644 index 0000000..d0018dc --- /dev/null +++ b/hobo/applications/templates/hobo/applications/app_confirm_delete.html @@ -0,0 +1,19 @@ +{% extends "hobo/base.html" %} +{% load i18n %} + +{% block appbar %} +

{% blocktrans with title=object.name %}Removal of "{{ title }}"{% endblocktrans %}

+{% endblock %} + +{% block content %} +
+ {% csrf_token %} +

+ {% trans 'Are you sure you want to remove this application?' %} +

+
+ + {% trans 'Cancel' %} +
+
+{% endblock %} diff --git a/hobo/applications/urls.py b/hobo/applications/urls.py index ff62091..51eb09c 100644 --- a/hobo/applications/urls.py +++ b/hobo/applications/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ url(r'^$', views.home, name='applications-home'), url(r'^create/$', views.init, name='application-init'), url(r'^install/$', views.install, name='application-install'), + url(r'^manifest/(?P[\w-]+)/delete/$', views.delete, name='application-delete'), url(r'^manifest/(?P[\w-]+)/$', views.manifest, name='application-manifest'), url(r'^manifest/(?P[\w-]+)/metadata/$', views.metadata, name='application-metadata'), url(r'^manifest/(?P[\w-]+)/scandeps/$', views.scandeps, name='application-scandeps'), diff --git a/hobo/applications/views.py b/hobo/applications/views.py index d7d1e2b..c4b8746 100644 --- a/hobo/applications/views.py +++ b/hobo/applications/views.py @@ -298,3 +298,14 @@ class Install(FormView): install = Install.as_view() + + +class AppDeleteView(DeleteView): + model = Application + template_name = 'hobo/applications/app_confirm_delete.html' + + def get_success_url(self): + return reverse('applications-home') + + +delete = AppDeleteView.as_view() diff --git a/tests/test_application.py b/tests/test_application.py index 60f04b6..55ddc84 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -178,6 +178,39 @@ def test_create_application(app, admin_user, settings): assert b'' in resp.content +def test_delete_application(app, admin_user, settings): + Wcs.objects.create(base_url='https://wcs.example.invalid', slug='foobar', title='Foobar') + + settings.KNOWN_SERVICES = { + 'wcs': { + 'foobar': { + 'title': 'Foobar', + 'url': 'https://wcs.example.invalid/', + 'orig': 'example.org', + 'secret': 'xxx', + } + } + } + + login(app) + + Application.objects.create(name='AppToDelete', slug='app_to_delete') + Application.objects.create(name='OtherApp', slug='other_app') + + assert Application.objects.count() == 2 + + resp = app.get('/applications/manifest/app_to_delete/delete/') + + resp = resp.forms[0].submit() + resp = resp.follow() + + assert '/applications/' in resp + assert 'AppToDelete' not in resp.text + + assert Application.objects.count() == 1 + assert Application.objects.first().name == 'OtherApp' + + @pytest.fixture def app_bundle(): tar_io = io.BytesIO()