From 61e2dc0d9cc8ec6cf2b0f053641ae3d3c3cd34eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 29 Feb 2024 13:00:59 +0100 Subject: [PATCH 1/4] . --- idhub/admin/views.py | 7 ++++++- idhub/models.py | 5 +++++ idhub/templates/idhub/admin/schemas.html | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index e2dd58f..d33c3a7 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,7 +870,12 @@ class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() self.pk = kwargs['pk'] - self.object = get_object_or_404(Schemas, pk=self.pk) + schema.vcredentials.filter(status=VerificableCredential.Status.ISSUED).count() + self.object = get_object_or_404( + Schemas, + pk=self.pk, + vcredentials__status=VerificableCredential.Status.ISSUED + ) self.object.delete() return redirect('idhub:admin_schemas') diff --git a/idhub/models.py b/idhub/models.py index f1eea85..38f926f 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -527,6 +527,11 @@ class Schemas(models.Model): return name + @property + def has_credentials(self, request=None): + return self.vcredentials.filter( + status=VerificableCredential.Status.ISSUED).exists() + def _get_language_code(self, request=None): language_code = settings.LANGUAGE_CODE if request: diff --git a/idhub/templates/idhub/admin/schemas.html b/idhub/templates/idhub/admin/schemas.html index 543c89b..6b0e816 100644 --- a/idhub/templates/idhub/admin/schemas.html +++ b/idhub/templates/idhub/admin/schemas.html @@ -13,6 +13,7 @@ {% for schema in object_list %} +{% if not schema.has_credentials %} +{% endif %} {% endfor %} {% endblock %} From abb1baddb37d85034735178e336ad501de821818 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 29 Feb 2024 17:53:24 +0100 Subject: [PATCH 2/4] clean --- idhub/admin/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index d33c3a7..b50f2d2 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,7 +870,6 @@ class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() self.pk = kwargs['pk'] - schema.vcredentials.filter(status=VerificableCredential.Status.ISSUED).count() self.object = get_object_or_404( Schemas, pk=self.pk, From 156b0b4586924334e5592e52336aa975def8a488 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 29 Feb 2024 18:23:56 +0100 Subject: [PATCH 3/4] Emitted credentials won't show as available to be deleted --- idhub/admin/tables.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 74dcc6f..0fcb58e 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -253,6 +253,12 @@ class TemplateTable(tables.Table): return (queryset, True) + def render_delete_schema(self, value, record): + if record.has_credentials(): + return value + else: + return "" + class Meta: model = Schemas template_name = "idhub/custom_table.html" From 55355f9e6984d591177b53325347737befbf917b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 1 Mar 2024 09:31:43 +0100 Subject: [PATCH 4/4] fix delete schemas --- idhub/admin/tables.py | 7 ++++--- idhub/admin/views.py | 4 ++-- idhub/models.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 0fcb58e..51df7e8 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -229,7 +229,7 @@ class TemplateTable(tables.Table): delete_template_code = """""" delete_schema = tables.TemplateColumn(template_code=delete_template_code, @@ -254,8 +254,9 @@ class TemplateTable(tables.Table): return (queryset, True) def render_delete_schema(self, value, record): - if record.has_credentials(): - return value + if not record.has_credentials: + tmpl = self.delete_template_code.format(record.id) + return format_html(tmpl) else: return "" diff --git a/idhub/admin/views.py b/idhub/admin/views.py index b50f2d2..a030f99 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,10 +870,10 @@ class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() self.pk = kwargs['pk'] + issued = VerificableCredential.Status.ISSUED self.object = get_object_or_404( - Schemas, + Schemas.objects.exclude(vcredentials__status=issued), pk=self.pk, - vcredentials__status=VerificableCredential.Status.ISSUED ) self.object.delete() diff --git a/idhub/models.py b/idhub/models.py index 38f926f..db8522f 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -528,7 +528,7 @@ class Schemas(models.Model): return name @property - def has_credentials(self, request=None): + def has_credentials(self): return self.vcredentials.filter( status=VerificableCredential.Status.ISSUED).exists()