fix bug about type of credentials
This commit is contained in:
parent
815f43d980
commit
b6360f27fc
|
@ -186,7 +186,7 @@ class ImportForm(forms.Form):
|
|||
return user
|
||||
|
||||
def create_credential(self, user, row):
|
||||
return VerificableCredential(
|
||||
cred = VerificableCredential(
|
||||
verified=False,
|
||||
user=user,
|
||||
csv_data=json.dumps(row),
|
||||
|
@ -194,6 +194,8 @@ class ImportForm(forms.Form):
|
|||
schema=self._schema,
|
||||
eidas1_did=self._eidas1
|
||||
)
|
||||
cred.set_type()
|
||||
return cred
|
||||
|
||||
def exception(self, msg):
|
||||
File_datas.objects.create(file_name=self.file_name, success=False)
|
||||
|
|
|
@ -165,22 +165,12 @@ class CredentialTable(tables.Table):
|
|||
orderable=False
|
||||
)
|
||||
|
||||
def render_type(self, record):
|
||||
return record.type()
|
||||
|
||||
def render_details(self, record):
|
||||
return record.description()
|
||||
|
||||
def render_view_credential(self):
|
||||
return format_html('<i class="bi bi-eye"></i>')
|
||||
|
||||
def order_type(self, queryset, is_descending):
|
||||
queryset = queryset.order_by(
|
||||
("-" if is_descending else "") + "schema__type"
|
||||
)
|
||||
|
||||
return (queryset, True)
|
||||
|
||||
class Meta:
|
||||
model = VerificableCredential
|
||||
template_name = "idhub/custom_table.html"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.5 on 2024-01-22 15:44
|
||||
# Generated by Django 4.2.5 on 2024-01-24 15:04
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -160,6 +160,7 @@ class Migration(migrations.Migration):
|
|||
verbose_name='ID',
|
||||
),
|
||||
),
|
||||
('type', models.CharField(max_length=250)),
|
||||
('id_string', models.CharField(max_length=250)),
|
||||
('verified', models.BooleanField()),
|
||||
('created_on', models.DateTimeField(auto_now=True)),
|
||||
|
|
|
@ -192,7 +192,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_DELETED_BY_ADMIN(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was deleted").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id,
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -203,7 +203,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_DELETED(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was deleted from your wallet").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -215,7 +215,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_ISSUED_FOR_USER(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was issued for user {username}").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id,
|
||||
username=cred.user.username
|
||||
)
|
||||
|
@ -227,7 +227,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_ISSUED(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was issued and stored in your wallet").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -241,7 +241,7 @@ class Event(models.Model):
|
|||
msg = "The credential of type '{type}' and ID: '{id}' "
|
||||
msg += "was presented by user {username} to verifier '{verifier}"
|
||||
msg = _(msg).format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id,
|
||||
username=cred.user.username,
|
||||
verifier=verifier
|
||||
|
@ -256,7 +256,7 @@ class Event(models.Model):
|
|||
msg = "The credential of type '{type}' and ID: '{id}' "
|
||||
msg += "was presented to verifier '{verifier}'"
|
||||
msg = _(msg).format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id,
|
||||
verifier=verifier
|
||||
)
|
||||
|
@ -269,7 +269,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_ENABLED(cls, cred):
|
||||
msg = _("The credential of type '{type}' was enabled for user {username}").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
username=cred.user.username
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -280,7 +280,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_CAN_BE_REQUESTED(cls, cred):
|
||||
msg = _("You can request the '{type}' credential").format(
|
||||
type=cred.type()
|
||||
type=cred.type
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_CAN_BE_REQUESTED,
|
||||
|
@ -291,7 +291,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_REVOKED_BY_ADMIN(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was revoked for ").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -302,7 +302,7 @@ class Event(models.Model):
|
|||
@classmethod
|
||||
def set_EV_CREDENTIAL_REVOKED(cls, cred):
|
||||
msg = _("The credential of type '{type}' and ID: '{id}' was revoked by admin").format(
|
||||
type=cred.type(),
|
||||
type=cred.type,
|
||||
id=cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
|
@ -550,6 +550,7 @@ class VerificableCredential(models.Model):
|
|||
REVOKED = 3, _("Revoked")
|
||||
EXPIRED = 4, _("Expired")
|
||||
|
||||
type = models.CharField(max_length=250)
|
||||
id_string = models.CharField(max_length=250)
|
||||
verified = models.BooleanField()
|
||||
created_on = models.DateTimeField(auto_now=True)
|
||||
|
@ -599,9 +600,6 @@ class VerificableCredential(models.Model):
|
|||
def set_data(self, value, password):
|
||||
self.data = self.user.encrypt_data(value, password)
|
||||
|
||||
def type(self):
|
||||
return self.schema.type
|
||||
|
||||
def get_description(self):
|
||||
return self.schema._description or ''
|
||||
|
||||
|
@ -704,6 +702,15 @@ class VerificableCredential(models.Model):
|
|||
|
||||
return ''
|
||||
|
||||
def set_type(self):
|
||||
template_name = 'credentials/{}'.format(
|
||||
self.schema.file_schema
|
||||
)
|
||||
tmpl = get_template(template_name)
|
||||
d = json.loads(tmpl.render({}))
|
||||
self.type = d.get('type')[-1]
|
||||
|
||||
|
||||
def filter_dict(self, dic):
|
||||
new_dict = OrderedDict()
|
||||
for key, value in dic.items():
|
||||
|
|
|
@ -124,13 +124,6 @@ class CredentialsTable(tables.Table):
|
|||
def render_status(self, record):
|
||||
return record.get_status()
|
||||
|
||||
def order_type(self, queryset, is_descending):
|
||||
queryset = queryset.order_by(
|
||||
("-" if is_descending else "") + "schema__type"
|
||||
)
|
||||
|
||||
return (queryset, True)
|
||||
|
||||
def order_description(self, queryset, is_descending):
|
||||
queryset = queryset.order_by(
|
||||
("-" if is_descending else "") + "schema__template_description"
|
||||
|
|
|
@ -26,7 +26,7 @@ class AuthorizeForm(forms.Form):
|
|||
reg = r'({})'.format('|'.join(self.presentation_definition))
|
||||
|
||||
self.all_credentials = self.user.vcredentials.filter(
|
||||
schema__type__iregex=reg,
|
||||
type__iregex=reg,
|
||||
)
|
||||
self.credentials = self.all_credentials.filter(
|
||||
status=VerificableCredential.Status.ISSUED.value
|
||||
|
|
Loading…
Reference in New Issue