add revoke and cancel credentials

This commit is contained in:
Cayo Puigdefabregas 2023-11-03 17:10:09 +01:00
parent f7f13bbea7
commit d581ce0a19
3 changed files with 78 additions and 6 deletions

View File

@ -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):

View File

@ -11,8 +11,11 @@
</div>
<div class="col text-end">
{% if object.get_status == 'Issued' %}
<a class="btn btn-yellow" href="{% url 'idhub:user_credential_json' object.id %}">{% trans 'Revoke' %}</a>
<a class="btn btn-orange" href="{% url 'idhub:user_credential_json' object.id %}">{% trans 'Delete' %}</a>
<a class="btn btn-yellow" class="btn btn-orange" data-bs-toggle="modal" data-bs-target="#confirm-revoke" href="javascript:void()">{% trans 'Revoke' %}</a>
<a class="btn btn-orange" class="btn btn-orange" data-bs-toggle="modal" data-bs-target="#confirm-delete" href="javascript:void()">{% trans 'Delete' %}</a>
{% endif %}
{% if object.get_status == 'Revoked' %}
<a class="btn btn-orange" class="btn btn-orange" data-bs-toggle="modal" data-bs-target="#confirm-delete" href="javascript:void()">{% trans 'Delete' %}</a>
{% endif %}
</div>
</div>
@ -53,4 +56,40 @@
</div>
</div>
</div>
<!-- Modal Revoke -->
<div class="modal" id="confirm-revoke" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans 'Revoke credential' %} {{ object.get_type }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% trans 'Are you sure that you want revoke this credential?' %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Clancel</button>
<a href="{% url 'idhub:admin_credentials_revoke' object.id %}" type="button" class="btn btn-danger">{% trans 'Revoke' %}</a>
</div>
</div>
</div>
</div>
<!-- Modal Delete -->
<div class="modal" id="confirm-delete" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans 'Delete credential' %} {{ object.get_type }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% trans 'Are you sure that you want delete this Credential?' %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Clancel</button>
<a href="{% url 'idhub:admin_credentials_delete' object.id %}" type="button" class="btn btn-danger">{% trans 'Delete' %}</a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -137,8 +137,10 @@ urlpatterns = [
name='admin_credential'),
path('admin/credentials/<int:pk>/json', views_admin.CredentialJsonView.as_view(),
name='admin_credential_json'),
path('admin/credentials/revoke/', views_admin.RevokeCredentialsView.as_view(),
path('admin/credentials/<int:pk>/revoke/', views_admin.RevokeCredentialsView.as_view(),
name='admin_credentials_revoke'),
path('admin/credentials/<int:pk>/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(),