Merge pull request 'remove-schemas' (#159) from remove-schemas into release

Reviewed-on: https://gitea.pangea.org/trustchain-oc1-orchestral/IdHub/pulls/159
This commit is contained in:
cayop 2024-03-01 08:38:46 +00:00
commit 0460ce6bce
4 changed files with 20 additions and 2 deletions

View File

@ -229,7 +229,7 @@ class TemplateTable(tables.Table):
delete_template_code = """<a class="text-danger" delete_template_code = """<a class="text-danger"
href="javascript:void()" href="javascript:void()"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#confirm-delete-{{ record.id }}" data-bs-target="#confirm-delete-{}"
title="Remove" title="Remove"
><i class="bi bi-trash"></i></a>""" ><i class="bi bi-trash"></i></a>"""
delete_schema = tables.TemplateColumn(template_code=delete_template_code, delete_schema = tables.TemplateColumn(template_code=delete_template_code,
@ -253,6 +253,13 @@ class TemplateTable(tables.Table):
return (queryset, True) return (queryset, True)
def render_delete_schema(self, value, record):
if not record.has_credentials:
tmpl = self.delete_template_code.format(record.id)
return format_html(tmpl)
else:
return ""
class Meta: class Meta:
model = Schemas model = Schemas
template_name = "idhub/custom_table.html" template_name = "idhub/custom_table.html"

View File

@ -870,7 +870,11 @@ class SchemasDeleteView(SchemasMix):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.check_valid_user() self.check_valid_user()
self.pk = kwargs['pk'] self.pk = kwargs['pk']
self.object = get_object_or_404(Schemas, pk=self.pk) issued = VerificableCredential.Status.ISSUED
self.object = get_object_or_404(
Schemas.objects.exclude(vcredentials__status=issued),
pk=self.pk,
)
self.object.delete() self.object.delete()
return redirect('idhub:admin_schemas') return redirect('idhub:admin_schemas')

View File

@ -527,6 +527,11 @@ class Schemas(models.Model):
return name return name
@property
def has_credentials(self):
return self.vcredentials.filter(
status=VerificableCredential.Status.ISSUED).exists()
def _get_language_code(self, request=None): def _get_language_code(self, request=None):
language_code = settings.LANGUAGE_CODE language_code = settings.LANGUAGE_CODE
if request: if request:

View File

@ -13,6 +13,7 @@
</div> </div>
<!-- Modal --> <!-- Modal -->
{% for schema in object_list %} {% for schema in object_list %}
{% if not schema.has_credentials %}
<div class="modal" id="confirm-delete-{{ schema.id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal" id="confirm-delete-{{ schema.id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
@ -30,5 +31,6 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}