create a pre-credential

This commit is contained in:
Cayo Puigdefabregas 2023-11-14 18:50:23 +01:00
parent 2df87faf80
commit dc887c98c2
7 changed files with 26 additions and 48 deletions

View File

@ -114,12 +114,12 @@ class ImportForm(forms.Form):
return user.first() return user.first()
def create_credential(self, user, row): def create_credential(self, user, row):
d = self.json_schema.copy()
d['instance'] = row
return VerificableCredential( return VerificableCredential(
verified=False, verified=False,
user=user, user=user,
data=json.dumps(d) csv_data=json.dumps(row),
did_issuer=self._did.did,
schema=self._schema,
) )
def exception(self, msg): def exception(self, msg):

View File

@ -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.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -144,6 +144,7 @@ class Migration(migrations.Migration):
('did_issuer', models.CharField(max_length=250)), ('did_issuer', models.CharField(max_length=250)),
('did_subject', models.CharField(max_length=250)), ('did_subject', models.CharField(max_length=250)),
('data', models.TextField()), ('data', models.TextField()),
('csv_data', models.TextField()),
( (
'status', 'status',
models.PositiveSmallIntegerField( models.PositiveSmallIntegerField(
@ -156,6 +157,14 @@ class Migration(migrations.Migration):
default=1, default=1,
), ),
), ),
(
'schema',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='vcredentials',
to='idhub.schemas',
),
),
( (
'user', 'user',
models.ForeignKey( models.ForeignKey(

View File

@ -462,6 +462,7 @@ class VerificableCredential(models.Model):
did_issuer = models.CharField(max_length=250) did_issuer = models.CharField(max_length=250)
did_subject = models.CharField(max_length=250) did_subject = models.CharField(max_length=250)
data = models.TextField() data = models.TextField()
csv_data = models.TextField()
status = models.PositiveSmallIntegerField( status = models.PositiveSmallIntegerField(
choices=Status.choices, choices=Status.choices,
default=Status.ENABLED default=Status.ENABLED
@ -471,6 +472,11 @@ class VerificableCredential(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='vcredentials', related_name='vcredentials',
) )
schema = models.ForeignKey(
Schemas,
on_delete=models.CASCADE,
related_name='vcredentials',
)
@property @property
def get_schema(self): def get_schema(self):
@ -488,7 +494,7 @@ class VerificableCredential(models.Model):
return self.Status(self.status).label return self.Status(self.status).label
def get_datas(self): def get_datas(self):
data = json.loads(self.data).get('instance').items() data = json.loads(self.csv_data).items()
return data return data
def issue(self, did): def issue(self, did):
@ -497,8 +503,11 @@ class VerificableCredential(models.Model):
self.issued_on = datetime.datetime.now() self.issued_on = datetime.datetime.now()
def get_issued_on(self): def get_issued_on(self):
if self.issued_on:
return self.issued_on.strftime("%m/%d/%Y") return self.issued_on.strftime("%m/%d/%Y")
return ''
class VCTemplate(models.Model): class VCTemplate(models.Model):
wkit_template_id = models.CharField(max_length=250) wkit_template_id = models.CharField(max_length=250)
data = models.TextField() data = models.TextField()

View File

@ -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 from django.db import migrations, models

View File

@ -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"]
}

View File

@ -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", "$id": "https://pangea.org/schemas/member-credential-schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"name": "MemberCredential", "name": "MemberCredential",
@ -36,5 +19,3 @@
}, },
"required": ["name", "email", "membershipType"] "required": ["name", "email", "membershipType"]
} }
}
}