From 16ea7631dc18030fad3d3c104ba8f4bd1a71373c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 12 Jan 2024 20:09:19 +0100 Subject: [PATCH] filter_dict and new template membership --- idhub/models.py | 10 +- .../credentials/membership-card.json | 126 +++++++++--------- 2 files changed, 71 insertions(+), 65 deletions(-) diff --git a/idhub/models.py b/idhub/models.py index dd57062..b862dc1 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -1,6 +1,8 @@ import json +import ujson import pytz import datetime +from collections import OrderedDict from django.db import models from django.conf import settings from django.template.loader import get_template @@ -525,10 +527,13 @@ class VerificableCredential(models.Model): self.status = self.Status.ISSUED self.subject_did = did self.issued_on = datetime.datetime.now().astimezone(pytz.utc) - self.data = sign_credential( + data = sign_credential( self.render(), self.issuer_did.key_material ) + d_ordered = ujson.loads(data) + d_minimum = self.filter_dict(d_ordered) + self.data = ujson.dumps(d_minimum) def get_context(self): d = json.loads(self.csv_data) @@ -544,6 +549,7 @@ class VerificableCredential(models.Model): 'issuance_date': issuance_date, 'first_name': self.user.first_name, 'last_name': self.user.last_name, + 'email': self.user.email } context.update(d) return context @@ -564,7 +570,7 @@ class VerificableCredential(models.Model): return '' def filter_dict(self, dic): - new_dict = {} + new_dict = OrderedDict() for key, value in dic.items(): if isinstance(value, dict): new_value = self.filter_dict(value) diff --git a/idhub/templates/credentials/membership-card.json b/idhub/templates/credentials/membership-card.json index e618833..e3d1c15 100644 --- a/idhub/templates/credentials/membership-card.json +++ b/idhub/templates/credentials/membership-card.json @@ -1,67 +1,67 @@ { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://idhub.pangea.org/credentials/base/v1", - "https://idhub.pangea.org/credentials/membership-card/v1" - ], - "type": [ - "VerifiableCredential", - "VerifiableAttestation", - "MembershipCard" - ], - "id": "https://idhub.pangea.org/credentials/987654321", - "issuer": { - "id": "did:example:5678", - "name": "Pangea Internet Solidari" + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://idhub.pangea.org/credentials/base/v1", + "https://idhub.pangea.org/credentials/membership-card/v1" + ], + "type": [ + "VerifiableCredential", + "VerifiableAttestation", + "MembershipCard" + ], + "id": "[[PLACEHOLDER]]", + "issuer": { + "id": "[[PLACEHOLDER]]", + "name": "[[PLACEHOLDER]]" + }, + "issuanceDate": "[[PLACEHOLDER]]", + "issued": "[[PLACEHOLDER]]", + "validFrom": "[[PLACEHOLDER]]", + "validUntil": "[[PLACEHOLDER]]", + "name": [ + { + "value": "Membership Card", + "lang": "en" }, - "issuanceDate": "2023-12-06T19:23:24Z", - "issued": "2023-12-06T19:23:24Z", - "validFrom": "2023-12-06T19:23:24Z", - "validUntil": "2024-12-06T19:23:24Z", - "name": [ - { - "value": "Membership Card", - "lang": "en" - }, - { - "value": "Carnet de soci/a", - "lang": "ca_ES" - }, - { - "value": "Carnet de socio/a", - "lang": "es" - } - ], - "description": [ - { - "value": "The membership card specifies an individual's subscription or enrollment in specific services or benefits issued by an organization.", - "lang": "en" - }, - { - "value": "El carnet de soci especifica la subscripció o la inscripció d'un individu en serveis o beneficis específics emesos per una organització.", - "lang": "ca_ES" - }, - { - "value": "El carnet de socio especifica la suscripción o inscripción de un individuo en servicios o beneficios específicos emitidos por uns organización.", - "lang": "es" - } - ], - "credentialSubject": { - "id": "did:example:1234", - "firstName": "Joan", - "lastName": "Pera", - "email": "joan.pera@pangea.org", - "typeOfPerson": "natural", - "identityDocType": "DNI", - "identityNumber": "12345678A", - "organisation": "Pangea", - "membershipType": "individual", - "membershipId": "123456", - "affiliatedSince": "2023-01-01T00:00:00Z", - "affiliatedUntil": "2024-01-01T00:00:00Z" + { + "value": "Carnet de soci/a", + "lang": "ca_ES" }, - "credentialSchema": { - "id": "https://idhub.pangea.org/vc_schemas/membership-card.json", - "type": "FullJsonSchemaValidator2021" + { + "value": "Carnet de socio/a", + "lang": "es" } -} + ], + "description": [ + { + "value": "The membership card specifies an individual's subscription or enrollment in specific services or benefits issued by an organization.", + "lang": "en" + }, + { + "value": "El carnet de soci especifica la subscripció o la inscripció d'un individu en serveis o beneficis específics emesos per una organització.", + "lang": "ca_ES" + }, + { + "value": "El carnet de socio especifica la suscripción o inscripción de un individuo en servicios o beneficios específicos emitidos por uns organización.", + "lang": "es" + } + ], + "credentialSubject": { + "id": "[[PLACEHOLDER]]", + "firstName": "[[PLACEHOLDER]]", + "lastName": "[[PLACEHOLDER]]", + "email": "[[PLACEHOLDER]]", + "typeOfPerson": "[[PLACEHOLDER]]", + "identityDocType": "[[PLACEHOLDER]]", + "identityNumber": "[[PLACEHOLDER]]", + "organisation": "[[PLACEHOLDER]]", + "membershipType": "[[PLACEHOLDER]]", + "membershipId": "[[PLACEHOLDER]]", + "affiliatedSince": "[[PLACEHOLDER]]", + "affiliatedUntil": "[[PLACEHOLDER]]" + }, + "credentialSchema": { + "id": "https://idhub.pangea.org/vc_schemas/membership-card.json", + "type": "FullJsonSchemaValidator2021" + } +} \ No newline at end of file