Merge pull request 'feature/129-add-delete-boton' (#186) from feature/129-add-delete-boton into release

Reviewed-on: https://gitea.pangea.org/trustchain-oc1-orchestral/IdHub/pulls/186
This commit is contained in:
cayop 2024-03-13 09:15:39 +00:00
commit 2f73c5942d
4 changed files with 33 additions and 1 deletions

View File

@ -211,11 +211,18 @@ class DIDTable(tables.Table):
class DataTable(tables.Table): class DataTable(tables.Table):
created_at = tables.Column(verbose_name="Date") created_at = tables.Column(verbose_name="Date")
file_name = tables.Column(verbose_name="File") file_name = tables.Column(verbose_name="File")
delete_template_code = """<a class="text-danger"
href="{% url 'idhub:admin_import_del' record.id %}"
title="Remove"
><i class="bi bi-trash"></i></a>"""
delete_data = tables.TemplateColumn(template_code=delete_template_code,
orderable=False,
verbose_name="Delete")
class Meta: class Meta:
model = File_datas model = File_datas
template_name = "idhub/custom_table.html" template_name = "idhub/custom_table.html"
fields = ("created_at", "file_name", "success") fields = ("created_at", "file_name", "success", "delete_data")
class TemplateTable(tables.Table): class TemplateTable(tables.Table):

View File

@ -1078,3 +1078,16 @@ class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView):
messages.error(self.request, e.message) messages.error(self.request, e.message)
return super().form_valid(form) return super().form_valid(form)
class ImportDeleteView(AdminView, DeleteView):
model = File_datas
def get(self, request, *args, **kwargs):
self.check_valid_user()
self.pk = kwargs['pk']
self.object = get_object_or_404(self.model, pk=self.pk)
self.object.delete()
return redirect('idhub:admin_import')

View File

@ -239,3 +239,13 @@ class CredentialsViewTest(TestCase):
def test_user_require_credential(self): def test_user_require_credential(self):
for p in PILOTS: for p in PILOTS:
self._user_require_credentail(p) self._user_require_credentail(p)
def test_remove_file_data(self):
p = PILOTS[0]
self.admin_login()
self._upload_data_membership(p)
url = reverse('idhub:admin_import_del', args=[1])
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse('idhub:admin_import'))

View File

@ -176,6 +176,8 @@ urlpatterns = [
name='admin_terms_and_conditions'), name='admin_terms_and_conditions'),
path('admin/import/new', views_admin.ImportAddView.as_view(), path('admin/import/new', views_admin.ImportAddView.as_view(),
name='admin_import_add'), name='admin_import_add'),
path('admin/import/<int:pk>/del', views_admin.ImportDeleteView.as_view(),
name='admin_import_del'),
path('admin/enc/', views_admin.EncryptionKeyView.as_view(), name='encryption_key'), path('admin/enc/', views_admin.EncryptionKeyView.as_view(), name='encryption_key'),
path('admin/auth/<uuid:admin2fauth>', views_admin.DobleFactorAuthView.as_view(), path('admin/auth/<uuid:admin2fauth>', views_admin.DobleFactorAuthView.as_view(),
name='admin_2fauth'), name='admin_2fauth'),