From dc887c98c2031c6d79b7d9671cb18062b0d10361 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 14 Nov 2023 18:50:23 +0100 Subject: [PATCH] create a pre-credential --- idhub/admin/forms.py | 6 +++--- idhub/migrations/0001_initial.py | 11 +++++++++- idhub/models.py | 13 ++++++++++-- .../{member-credential.json => member.json} | 0 idhub_auth/migrations/0001_initial.py | 2 +- schemas/member-schema.json | 21 ------------------- schemas/member.json | 21 +------------------ 7 files changed, 26 insertions(+), 48 deletions(-) rename idhub/templates/credentials/{member-credential.json => member.json} (100%) delete mode 100644 schemas/member-schema.json diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 8ff83b5..1f01555 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -114,12 +114,12 @@ class ImportForm(forms.Form): return user.first() def create_credential(self, user, row): - d = self.json_schema.copy() - d['instance'] = row return VerificableCredential( verified=False, user=user, - data=json.dumps(d) + csv_data=json.dumps(row), + did_issuer=self._did.did, + schema=self._schema, ) def exception(self, msg): diff --git a/idhub/migrations/0001_initial.py b/idhub/migrations/0001_initial.py index e95751c..d06dde8 100644 --- a/idhub/migrations/0001_initial.py +++ b/idhub/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.5 on 2023-11-14 17:08 +# Generated by Django 4.2.5 on 2023-11-14 17:48 from django.conf import settings from django.db import migrations, models @@ -144,6 +144,7 @@ class Migration(migrations.Migration): ('did_issuer', models.CharField(max_length=250)), ('did_subject', models.CharField(max_length=250)), ('data', models.TextField()), + ('csv_data', models.TextField()), ( 'status', models.PositiveSmallIntegerField( @@ -156,6 +157,14 @@ class Migration(migrations.Migration): default=1, ), ), + ( + 'schema', + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='vcredentials', + to='idhub.schemas', + ), + ), ( 'user', models.ForeignKey( diff --git a/idhub/models.py b/idhub/models.py index 68a0f8d..58fe233 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -462,6 +462,7 @@ class VerificableCredential(models.Model): did_issuer = models.CharField(max_length=250) did_subject = models.CharField(max_length=250) data = models.TextField() + csv_data = models.TextField() status = models.PositiveSmallIntegerField( choices=Status.choices, default=Status.ENABLED @@ -471,6 +472,11 @@ class VerificableCredential(models.Model): on_delete=models.CASCADE, related_name='vcredentials', ) + schema = models.ForeignKey( + Schemas, + on_delete=models.CASCADE, + related_name='vcredentials', + ) @property def get_schema(self): @@ -488,7 +494,7 @@ class VerificableCredential(models.Model): return self.Status(self.status).label def get_datas(self): - data = json.loads(self.data).get('instance').items() + data = json.loads(self.csv_data).items() return data def issue(self, did): @@ -497,7 +503,10 @@ class VerificableCredential(models.Model): self.issued_on = datetime.datetime.now() def get_issued_on(self): - return self.issued_on.strftime("%m/%d/%Y") + if self.issued_on: + return self.issued_on.strftime("%m/%d/%Y") + + return '' class VCTemplate(models.Model): wkit_template_id = models.CharField(max_length=250) diff --git a/idhub/templates/credentials/member-credential.json b/idhub/templates/credentials/member.json similarity index 100% rename from idhub/templates/credentials/member-credential.json rename to idhub/templates/credentials/member.json diff --git a/idhub_auth/migrations/0001_initial.py b/idhub_auth/migrations/0001_initial.py index c15aee0..205b13a 100644 --- a/idhub_auth/migrations/0001_initial.py +++ b/idhub_auth/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.5 on 2023-11-14 17:08 +# Generated by Django 4.2.5 on 2023-11-14 17:48 from django.db import migrations, models diff --git a/schemas/member-schema.json b/schemas/member-schema.json deleted file mode 100644 index 38199be..0000000 --- a/schemas/member-schema.json +++ /dev/null @@ -1,21 +0,0 @@ - { - "$id": "https://pangea.org/schemas/member-credential-schema.json", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "name": "MemberCredential", - "description": "MemberCredential using JsonSchemaCredential", - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "email": { - "type": "string", - "format": "email" - }, - "membershipType": { - "type": "string", - "enum": ["individual", "organization"] - } - }, - "required": ["name", "email", "membershipType"] - } diff --git a/schemas/member.json b/schemas/member.json index 845ab50..38199be 100644 --- a/schemas/member.json +++ b/schemas/member.json @@ -1,21 +1,4 @@ -{ - "@context": [ - "https://www.w3.org/ns/credentials/v2", - "https://www.w3.org/ns/credentials/examples/v2" - ], - "id": "https://example.com/credentials/3734", - "type": ["VerifiableCredential", "JsonSchemaCredential"], - "issuer": "https://pangea.org/issuers/10", - "issuanceDate": "2023-09-01T19:23:24Z", - "credentialSchema": { - "id": "https://www.w3.org/2022/credentials/v2/json-schema-credential-schema.json", - "type": "JsonSchema", - "digestSRI": "sha384-S57yQDg1MTzF56Oi9DbSQ14u7jBy0RDdx0YbeV7shwhCS88G8SCXeFq82PafhCrW" - }, - "credentialSubject": { - "id": "https://pangea.org/schemas/member-credential-schema.json", - "type": "JsonSchema", - "jsonSchema": { + { "$id": "https://pangea.org/schemas/member-credential-schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "name": "MemberCredential", @@ -36,5 +19,3 @@ }, "required": ["name", "email", "membershipType"] } - } -}