fix credentials <-> schemas
This commit is contained in:
parent
73ec25e897
commit
821b6d3889
2
examples/membership-card.csv
Normal file
2
examples/membership-card.csv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
name surnames email typeOfPerson membershipType organisation validFrom validUntil identityDocType identityNumber
|
||||||
|
Pepe Gómez user1@example.org individual Member Pangea 01-01-2023
|
|
|
@ -1,11 +1,11 @@
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from jsonschema import validate
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from utils import credtools
|
||||||
from idhub.models import (
|
from idhub.models import (
|
||||||
DID,
|
DID,
|
||||||
File_datas,
|
File_datas,
|
||||||
|
@ -78,7 +78,7 @@ class ImportForm(forms.Form):
|
||||||
for n in range(df.last_valid_index()+1):
|
for n in range(df.last_valid_index()+1):
|
||||||
row = {}
|
row = {}
|
||||||
for k in data_pd.keys():
|
for k in data_pd.keys():
|
||||||
row[k] = data_pd[k][n]
|
row[k] = data_pd[k][n] or ''
|
||||||
|
|
||||||
user = self.validate_jsonld(n, row)
|
user = self.validate_jsonld(n, row)
|
||||||
self.rows[user] = row
|
self.rows[user] = row
|
||||||
|
@ -100,7 +100,7 @@ class ImportForm(forms.Form):
|
||||||
|
|
||||||
def validate_jsonld(self, line, row):
|
def validate_jsonld(self, line, row):
|
||||||
try:
|
try:
|
||||||
validate(instance=row, schema=self.json_schema)
|
credtools.validate_json(row, self.json_schema)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = "line {}: {}".format(line+1, e)
|
msg = "line {}: {}".format(line+1, e)
|
||||||
self.exception(msg)
|
self.exception(msg)
|
||||||
|
|
|
@ -772,7 +772,7 @@ class SchemasNewView(SchemasMix):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
data = f.read().decode('utf-8')
|
data = f.read().decode('utf-8')
|
||||||
json.loads(data)
|
assert credtools.validate_schema(json.loads(data))
|
||||||
except Exception:
|
except Exception:
|
||||||
messages.error(self.request, _('This is not a schema valid!'))
|
messages.error(self.request, _('This is not a schema valid!'))
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,6 +3,7 @@ import pytz
|
||||||
import requests
|
import requests
|
||||||
import datetime
|
import datetime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from utils.idhub_ssikit import (
|
from utils.idhub_ssikit import (
|
||||||
|
@ -492,10 +493,19 @@ class VerificableCredential(models.Model):
|
||||||
return json.loads(self.data)
|
return json.loads(self.data)
|
||||||
|
|
||||||
def type(self):
|
def type(self):
|
||||||
return self.get_schema.get('name', '')
|
if self.data:
|
||||||
|
return self.get_schema.get('type')[-1]
|
||||||
|
|
||||||
|
return self.schema.name()
|
||||||
|
|
||||||
def description(self):
|
def description(self):
|
||||||
return self.get_schema.get('description', '')
|
if not self.data:
|
||||||
|
return self.schema.description()
|
||||||
|
|
||||||
|
for des in self.get_schema.get('description', []):
|
||||||
|
if settings.LANGUAGE_CODE == des.get('lang'):
|
||||||
|
return des.get('value', '')
|
||||||
|
return ''
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return self.Status(self.status).label
|
return self.Status(self.status).label
|
||||||
|
@ -526,6 +536,8 @@ class VerificableCredential(models.Model):
|
||||||
'issuer_did': self.issuer_did.did,
|
'issuer_did': self.issuer_did.did,
|
||||||
'subject_did': self.subject_did,
|
'subject_did': self.subject_did,
|
||||||
'issuance_date': issuance_date,
|
'issuance_date': issuance_date,
|
||||||
|
'first_name': self.user.first_name,
|
||||||
|
'last_name': self.user.last_name,
|
||||||
}
|
}
|
||||||
context.update(d)
|
context.update(d)
|
||||||
return context
|
return context
|
||||||
|
|
101
idhub/templates/credentials/membership-card.json
Normal file
101
idhub/templates/credentials/membership-card.json
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/2018/credentials/v1",
|
||||||
|
{
|
||||||
|
"individual": "https://schema.org/Person",
|
||||||
|
"Member": "https://schema.org/Member",
|
||||||
|
"startDate": "https://schema.org/startDate",
|
||||||
|
"jsonSchema": "https://schema.org/jsonSchema",
|
||||||
|
"$ref": "https://schema.org/jsonSchemaRef",
|
||||||
|
"credentialSchema": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#credentialSchema",
|
||||||
|
"organisation": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#organisation",
|
||||||
|
"membershipType": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#membershipType",
|
||||||
|
"membershipId": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#membershipId",
|
||||||
|
"typeOfPerson": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#typeOfPerson",
|
||||||
|
"identityDocType": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#identityDocType",
|
||||||
|
"identityNumber": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#identityNumber",
|
||||||
|
"name": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#name",
|
||||||
|
"description": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#description",
|
||||||
|
"value": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#value",
|
||||||
|
"lang": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#lang",
|
||||||
|
"surnames": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#surnames",
|
||||||
|
"email": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/vocab#email",
|
||||||
|
"issued": "https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Verifiable+Attestation#issued",
|
||||||
|
"validFrom": "https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Verifiable+Attestation#validFrom",
|
||||||
|
"validUntil": "https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Verifiable+Attestation#validUntil"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": [
|
||||||
|
"VerifiableCredential",
|
||||||
|
"VerifiableAttestation",
|
||||||
|
"MembershipCard"
|
||||||
|
],
|
||||||
|
"id": "{{ vc_id }}",
|
||||||
|
"issuer": {
|
||||||
|
"id": "{{ issuer_did }}",
|
||||||
|
"name": "Pangea",
|
||||||
|
"description": [
|
||||||
|
{
|
||||||
|
"value": "Pangea.org is a service provider leveraging open-source technologies to provide affordable and accessible solutions for social enterprises and solidarity organisations.",
|
||||||
|
"lang": "en"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "Pangea.org és un proveïdor de serveis que aprofita les tecnologies de codi obert per oferir solucions assequibles i accessibles per a empreses socials i organitzacions solidàries.",
|
||||||
|
"lang": "ca_ES"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "Pangea.org es un proveedor de servicios que aprovecha tecnologías de código abierto para proporcionar soluciones asequibles y accesibles para empresas sociales y organizaciones solidarias.",
|
||||||
|
"lang": "es"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"issuanceDate": "{{ issuance_date }}",
|
||||||
|
"issued": "{{ issuance_date }}",
|
||||||
|
"validFrom": "{{ issuance_date }}",
|
||||||
|
"validUntil": "{{ validUntil }}",
|
||||||
|
"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": "{{ subject_did }}",
|
||||||
|
"organisation": "Pangea",
|
||||||
|
"membershipType": "{{ membershipType }}",
|
||||||
|
"membershipId": "{{ vc_id }}",
|
||||||
|
"AffiliatedFrom": "{{ AffiliatedFrom }}",
|
||||||
|
"AffiliatedUntil": "{{ AffiliatedUntil }}",
|
||||||
|
"typeOfPerson": "{{ typeOfPerson }}",
|
||||||
|
"name": "{{ first_name }}",
|
||||||
|
"surnames": "{{ last_name }}",
|
||||||
|
"email": "{{ email }}",
|
||||||
|
"credentialSchema": {
|
||||||
|
"id": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/membership-card-schema.json",
|
||||||
|
"type": "JsonSchema"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
schemas/membership-card.json
Normal file
64
schemas/membership-card.json
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
"$id": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/membership-card-schema.json",
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"name": "MembershipCard",
|
||||||
|
"description": "MembershipCard credential using JsonSchema",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"credentialSubject": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"organisation": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"membershipType": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"AffiliatedFrom": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"AffiliatedUntil": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"typeOfPerson": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"individual",
|
||||||
|
"org"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"identityDocType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"DNI",
|
||||||
|
"NIF",
|
||||||
|
"NIE",
|
||||||
|
"PASSPORT"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"identityNumber": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"surnames": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "email"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"organisation",
|
||||||
|
"typeOfPerson",
|
||||||
|
"name",
|
||||||
|
"surnames",
|
||||||
|
"email"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue