From d581ce0a198cb3e9acc0906f98f373a884f89bef Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 3 Nov 2023 17:10:09 +0100 Subject: [PATCH] add revoke and cancel credentials --- idhub/admin/views.py | 37 ++++++++++++++-- .../idhub/admin/issue_credentials.html | 43 ++++++++++++++++++- idhub/urls.py | 4 +- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index d340c7c..99e236e 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -445,9 +445,40 @@ class CredentialJsonView(Credentials): class RevokeCredentialsView(Credentials): - template_name = "idhub/admin/revoke_credentials.html" - subtitle = _('Revoke Credentials') - icon = '' + success_url = reverse_lazy('idhub:admin_credentials') + + def get(self, request, *args, **kwargs): + pk = kwargs['pk'] + self.object = get_object_or_404( + VerificableCredential, + pk=pk, + ) + if self.object.status == VerificableCredential.Status.ISSUED: + self.object.status = VerificableCredential.Status.REVOKED + self.object.save() + messages.success(self.request, _('Credential revoked successfully')) + + return redirect(self.success_url) + + +class DeleteCredentialsView(Credentials): + success_url = reverse_lazy('idhub:admin_credentials') + + def get(self, request, *args, **kwargs): + pk = kwargs['pk'] + self.object = get_object_or_404( + VerificableCredential, + pk=pk, + ) + status = [ + VerificableCredential.Status.REVOKED, + VerificableCredential.Status.ISSUED + ] + if self.object.status in status: + self.object.delete() + messages.success(self.request, _('Credential deleted successfully')) + + return redirect(self.success_url) class DidsView(Credentials): diff --git a/idhub/templates/idhub/admin/issue_credentials.html b/idhub/templates/idhub/admin/issue_credentials.html index dd18eda..953c806 100644 --- a/idhub/templates/idhub/admin/issue_credentials.html +++ b/idhub/templates/idhub/admin/issue_credentials.html @@ -11,8 +11,11 @@
{% if object.get_status == 'Issued' %} - {% trans 'Revoke' %} - {% trans 'Delete' %} + {% trans 'Revoke' %} + {% trans 'Delete' %} + {% endif %} + {% if object.get_status == 'Revoked' %} + {% trans 'Delete' %} {% endif %}
@@ -53,4 +56,40 @@ + + + + {% endblock %} diff --git a/idhub/urls.py b/idhub/urls.py index 21217e1..87ff563 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -137,8 +137,10 @@ urlpatterns = [ name='admin_credential'), path('admin/credentials//json', views_admin.CredentialJsonView.as_view(), name='admin_credential_json'), - path('admin/credentials/revoke/', views_admin.RevokeCredentialsView.as_view(), + path('admin/credentials//revoke/', views_admin.RevokeCredentialsView.as_view(), name='admin_credentials_revoke'), + path('admin/credentials//del/', views_admin.DeleteCredentialsView.as_view(), + name='admin_credentials_delete'), path('admin/wallet/identities/', views_admin.DidsView.as_view(), name='admin_dids'), path('admin/dids/new/', views_admin.DidRegisterView.as_view(),