2023-10-26 11:33:13 +00:00
|
|
|
import json
|
2023-11-02 16:13:49 +00:00
|
|
|
import requests
|
2023-11-14 16:45:08 +00:00
|
|
|
import datetime
|
2023-09-26 07:15:28 +00:00
|
|
|
from django.db import models
|
2023-10-16 17:08:18 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-11-14 17:12:34 +00:00
|
|
|
from utils.idhub_ssikit import (
|
|
|
|
generate_did_controller_key,
|
|
|
|
keydid_from_controller_key,
|
|
|
|
)
|
2023-10-25 15:49:17 +00:00
|
|
|
from idhub_auth.models import User
|
2023-09-26 07:15:28 +00:00
|
|
|
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-11-09 16:58:06 +00:00
|
|
|
class Event(models.Model):
|
|
|
|
class Types(models.IntegerChoices):
|
|
|
|
EV_USR_REGISTERED = 1, "EV_USR_REGISTERED"
|
|
|
|
EV_USR_WELCOME = 2, "EV_USR_WELCOME"
|
|
|
|
EV_DATA_UPDATE_REQUESTED_BY_USER = 3, "EV_DATA_UPDATE_REQUESTED_BY_USER"
|
|
|
|
EV_DATA_UPDATE_REQUESTED = 4, "EV_DATA_UPDATE_REQUESTED"
|
|
|
|
EV_USR_UPDATED_BY_ADMIN = 5, "EV_USR_UPDATED_BY_ADMIN"
|
|
|
|
EV_USR_UPDATED = 6, "EV_USR_UPDATED"
|
|
|
|
EV_USR_DELETED_BY_ADMIN = 7, "EV_USR_DELETED_BY_ADMIN"
|
|
|
|
EV_DID_CREATED_BY_USER = 8, "EV_DID_CREATED_BY_USER"
|
|
|
|
EV_DID_CREATED = 9, "EV_DID_CREATED"
|
|
|
|
EV_DID_DELETED = 10, "EV_DID_DELETED"
|
|
|
|
EV_CREDENTIAL_DELETED_BY_ADMIN = 11, "EV_CREDENTIAL_DELETED_BY_ADMIN"
|
|
|
|
EV_CREDENTIAL_DELETED = 12, "EV_CREDENTIAL_DELETED"
|
|
|
|
EV_CREDENTIAL_ISSUED_FOR_USER = 13, "EV_CREDENTIAL_ISSUED_FOR_USER"
|
|
|
|
EV_CREDENTIAL_ISSUED = 14, "EV_CREDENTIAL_ISSUED"
|
|
|
|
EV_CREDENTIAL_PRESENTED_BY_USER = 15, "EV_CREDENTIAL_PRESENTED_BY_USER"
|
|
|
|
EV_CREDENTIAL_PRESENTED = 16, "EV_CREDENTIAL_PRESENTED"
|
|
|
|
EV_CREDENTIAL_ENABLED = 17, "EV_CREDENTIAL_ENABLED"
|
|
|
|
EV_CREDENTIAL_CAN_BE_REQUESTED = 18, "EV_CREDENTIAL_CAN_BE_REQUESTED"
|
|
|
|
EV_CREDENTIAL_REVOKED_BY_ADMIN = 19, "EV_CREDENTIAL_REVOKED_BY_ADMIN"
|
|
|
|
EV_CREDENTIAL_REVOKED = 20, "EV_CREDENTIAL_REVOKED"
|
|
|
|
EV_ROLE_CREATED_BY_ADMIN = 21, "EV_ROLE_CREATED_BY_ADMIN"
|
|
|
|
EV_ROLE_MODIFIED_BY_ADMIN = 22, "EV_ROLE_MODIFIED_BY_ADMIN"
|
|
|
|
EV_ROLE_DELETED_BY_ADMIN = 23, "EV_ROLE_DELETED_BY_ADMIN"
|
|
|
|
EV_SERVICE_CREATED_BY_ADMIN = 24, "EV_SERVICE_CREATED_BY_ADMIN"
|
|
|
|
EV_SERVICE_MODIFIED_BY_ADMIN = 25, "EV_SERVICE_MODIFIED_BY_ADMIN"
|
|
|
|
EV_SERVICE_DELETED_BY_ADMIN = 26, "EV_SERVICE_DELETED_BY_ADMIN"
|
|
|
|
EV_ORG_DID_CREATED_BY_ADMIN = 27, "EV_ORG_DID_CREATED_BY_ADMIN"
|
|
|
|
EV_ORG_DID_DELETED_BY_ADMIN = 28, "EV_ORG_DID_DELETED_BY_ADMIN"
|
|
|
|
EV_USR_DEACTIVATED_BY_ADMIN = 29, "EV_USR_DEACTIVATED_BY_ADMIN"
|
|
|
|
EV_USR_ACTIVATED_BY_ADMIN = 30, "EV_USR_ACTIVATED_BY_ADMIN"
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-11-09 16:58:06 +00:00
|
|
|
created = models.DateTimeField(auto_now=True)
|
|
|
|
message = models.CharField(max_length=350)
|
|
|
|
type = models.PositiveSmallIntegerField(
|
|
|
|
choices=Types.choices,
|
|
|
|
)
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='events',
|
|
|
|
null=True,
|
|
|
|
)
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-11-09 16:58:06 +00:00
|
|
|
def get_type(self):
|
|
|
|
return self.Types(self.type).label
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_REGISTERED(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The user {username} was registered: name: {first_name}, last name: {last_name}").format(
|
|
|
|
username=user.username,
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_REGISTERED,
|
|
|
|
message=msg
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_WELCOME(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("Welcome. You has been registered: name: {first_name}, last name: {last_name}").format(
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_WELCOME,
|
|
|
|
message=msg,
|
|
|
|
user=user
|
|
|
|
)
|
|
|
|
|
|
|
|
# Is required?
|
|
|
|
@classmethod
|
|
|
|
def set_EV_DATA_UPDATE_REQUESTED_BY_USER(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The user '{username}' has request the update of the following information: ")
|
2023-11-09 16:58:06 +00:00
|
|
|
msg += "['field1':'value1', 'field2':'value2'>,...]".format(
|
2023-11-10 15:22:41 +00:00
|
|
|
username=user.username,
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_DATA_UPDATE_REQUESTED_BY_USER,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Is required?
|
|
|
|
@classmethod
|
|
|
|
def set_EV_DATA_UPDATE_REQUESTED(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("You have requested the update of the following information: ")
|
2023-11-09 16:58:06 +00:00
|
|
|
msg += "['field1':'value1', 'field2':'value2'>,...]"
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_DATA_UPDATE_REQUESTED,
|
|
|
|
message=msg,
|
|
|
|
user=user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_UPDATED_BY_ADMIN(cls, user):
|
|
|
|
msg = "The admin has updated the following user 's information: "
|
2023-11-10 15:22:41 +00:00
|
|
|
msg += "name: {first_name}, last name: {last_name}"
|
|
|
|
msg = _(msg).format(
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_UPDATED_BY_ADMIN,
|
|
|
|
message=msg
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_UPDATED(cls, user):
|
|
|
|
msg = "The admin has updated your personal information: "
|
2023-11-10 15:22:41 +00:00
|
|
|
msg += "name: {first_name}, last name: {last_name}"
|
|
|
|
msg = _(msg).format(
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_UPDATED,
|
|
|
|
message=msg,
|
|
|
|
user=user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_DELETED_BY_ADMIN(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The admin has deleted the user: username: {username}").format(
|
|
|
|
username=user.username,
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_DELETED_BY_ADMIN,
|
|
|
|
message=msg
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_DID_CREATED_BY_USER(cls, did):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("New DID with DID-ID: '{did}' created by user '{username}'").format(
|
|
|
|
did=did.did,
|
|
|
|
username=did.user.username
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_DID_CREATED_BY_USER,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_DID_CREATED(cls, did):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("New DID with label: '{label}' and DID-ID: '{did}' was created'").format(
|
|
|
|
label=did.label,
|
|
|
|
did=did.did
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_DID_CREATED,
|
|
|
|
message=msg,
|
|
|
|
user=did.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_DID_DELETED(cls, did):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The DID with label '{label}' and DID-ID: '{did}' was deleted from your wallet").format(
|
|
|
|
label=did.label,
|
|
|
|
did=did.did
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_DID_DELETED,
|
|
|
|
message=msg,
|
|
|
|
user=did.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_DELETED_BY_ADMIN(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was deleted").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id,
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_DELETED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_DELETED(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was deleted from your wallet").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_DELETED,
|
|
|
|
message=msg,
|
|
|
|
user=cred.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_ISSUED_FOR_USER(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was issued for user {username}").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id,
|
|
|
|
username=cred.user.username
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_ISSUED_FOR_USER,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_ISSUED(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was issued and stored in your wallet").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_ISSUED,
|
|
|
|
message=msg,
|
|
|
|
user=cred.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_PRESENTED_BY_USER(cls, cred, verifier):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = "The credential of type '{type}' and ID: '{id}' "
|
|
|
|
msg += "was presented by user {username} to verifier '{verifier}"
|
|
|
|
msg = _(msg).format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id,
|
|
|
|
username=cred.user.username,
|
|
|
|
verifier=verifier
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_PRESENTED_BY_USER,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_PRESENTED(cls, cred, verifier):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = "The credential of type '{type}' and ID: '{id}' "
|
|
|
|
msg += "was presented to verifier '{verifier}'"
|
|
|
|
msg = _(msg).format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id,
|
|
|
|
verifier=verifier
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_PRESENTED,
|
|
|
|
message=msg,
|
|
|
|
user=cred.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_ENABLED(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' was enabled for user {username}").format(
|
|
|
|
type=cred.type(),
|
|
|
|
username=cred.user.username
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_ENABLED,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_CAN_BE_REQUESTED(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("You can request the '{type}' credential").format(
|
|
|
|
type=cred.type()
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_CAN_BE_REQUESTED,
|
|
|
|
message=msg,
|
|
|
|
user=cred.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_REVOKED_BY_ADMIN(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was revoked for ").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_REVOKED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_CREDENTIAL_REVOKED(cls, cred):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("The credential of type '{type}' and ID: '{id}' was revoked by admin").format(
|
|
|
|
type=cred.type(),
|
|
|
|
id=cred.id
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_CREDENTIAL_REVOKED,
|
|
|
|
message=msg,
|
|
|
|
user=cred.user
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_ROLE_CREATED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('A new role was created by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_ROLE_CREATED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_ROLE_MODIFIED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('The role was modified by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_ROLE_MODIFIED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_ROLE_DELETED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('The role was removed by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_ROLE_DELETED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_SERVICE_CREATED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('A new service was created by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_SERVICE_CREATED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_SERVICE_MODIFIED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('The service was modified by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_SERVICE_MODIFIED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_SERVICE_DELETED_BY_ADMIN(cls):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _('The service was removed by admin')
|
2023-11-09 16:58:06 +00:00
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_SERVICE_DELETED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_ORG_DID_CREATED_BY_ADMIN(cls, did):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("New Organisational DID with label: '{label}' and DID-ID: '{did}' was created").format(
|
|
|
|
label=did.label,
|
|
|
|
did=did.did
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_ORG_DID_CREATED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_ORG_DID_DELETED_BY_ADMIN(cls, did):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = _("Organisational DID with label: '{label}' and DID-ID: '{did}' was removed").format(
|
|
|
|
label=did.label,
|
|
|
|
did=did.did
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_ORG_DID_DELETED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_DEACTIVATED_BY_ADMIN(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = "The user '{username}' was temporarily deactivated: "
|
|
|
|
msg += "[name:'{first_name}', last name:'{last_name}']"
|
|
|
|
msg = _(msg).format(
|
|
|
|
username=user.username,
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_DEACTIVATED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_EV_USR_ACTIVATED_BY_ADMIN(cls, user):
|
2023-11-10 15:22:41 +00:00
|
|
|
msg = "The user '{username}' was activated: "
|
|
|
|
msg += "name:'{first_name}', last name:'{last_name}']"
|
|
|
|
msg = _(msg).format(
|
|
|
|
username=user.username,
|
|
|
|
first_name=user.first_name,
|
|
|
|
last_name=user.last_name
|
2023-11-09 16:58:06 +00:00
|
|
|
)
|
|
|
|
cls.objects.create(
|
|
|
|
type=cls.Types.EV_USR_ACTIVATED_BY_ADMIN,
|
|
|
|
message=msg,
|
|
|
|
)
|
|
|
|
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-10-10 06:43:08 +00:00
|
|
|
class DID(models.Model):
|
2023-10-26 16:06:52 +00:00
|
|
|
created_at = models.DateTimeField(auto_now=True)
|
2023-10-10 06:43:08 +00:00
|
|
|
label = models.CharField(max_length=50)
|
2023-11-14 17:12:34 +00:00
|
|
|
did = models.CharField(max_length=250)
|
2023-11-14 08:11:16 +00:00
|
|
|
# In JWK format. Must be stored as-is and passed whole to library functions.
|
|
|
|
# Example key material:
|
|
|
|
# '{"kty":"OKP","crv":"Ed25519","x":"oB2cPGFx5FX4dtS1Rtep8ac6B__61HAP_RtSzJdPxqs","d":"OJw80T1CtcqV0hUcZdcI-vYNBN1dlubrLaJa0_se_gU"}'
|
|
|
|
key_material = models.CharField(max_length=250)
|
2023-10-16 17:08:18 +00:00
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='dids',
|
2023-10-26 11:33:13 +00:00
|
|
|
null=True,
|
2023-10-16 17:08:18 +00:00
|
|
|
)
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-10-26 16:09:07 +00:00
|
|
|
@property
|
|
|
|
def is_organization_did(self):
|
|
|
|
if not self.user:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2023-11-14 08:48:36 +00:00
|
|
|
def set_did(self):
|
2023-11-14 17:12:34 +00:00
|
|
|
self.key_material = generate_did_controller_key()
|
|
|
|
self.did = keydid_from_controller_key(self.key_material)
|
2023-11-14 08:48:36 +00:00
|
|
|
|
|
|
|
def get_key(self):
|
|
|
|
return json.loads(self.key_material)
|
|
|
|
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-10-25 15:49:17 +00:00
|
|
|
class Schemas(models.Model):
|
|
|
|
file_schema = models.CharField(max_length=250)
|
|
|
|
data = models.TextField()
|
|
|
|
created_at = models.DateTimeField(auto_now=True)
|
|
|
|
|
2023-10-26 11:33:13 +00:00
|
|
|
@property
|
|
|
|
def get_schema(self):
|
|
|
|
if not self.data:
|
|
|
|
return {}
|
|
|
|
return json.loads(self.data)
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return self.get_schema.get('name', '')
|
|
|
|
|
|
|
|
def description(self):
|
|
|
|
return self.get_schema.get('description', '')
|
|
|
|
|
2023-10-25 15:49:17 +00:00
|
|
|
|
2023-10-30 12:53:19 +00:00
|
|
|
class VerificableCredential(models.Model):
|
2023-10-26 11:33:13 +00:00
|
|
|
"""
|
|
|
|
Definition of Verificable Credentials
|
|
|
|
"""
|
|
|
|
class Status(models.IntegerChoices):
|
2023-10-31 16:07:43 +00:00
|
|
|
ENABLED = 1, _("Enabled")
|
2023-11-02 13:17:07 +00:00
|
|
|
ISSUED = 2, _("Issued")
|
|
|
|
REVOKED = 3, _("Revoked")
|
|
|
|
EXPIRED = 4, _("Expired")
|
2023-10-26 11:33:13 +00:00
|
|
|
|
2023-09-28 09:01:14 +00:00
|
|
|
id_string = models.CharField(max_length=250)
|
|
|
|
verified = models.BooleanField()
|
2023-10-25 10:18:42 +00:00
|
|
|
created_on = models.DateTimeField(auto_now=True)
|
2023-11-14 16:45:08 +00:00
|
|
|
issued_on = models.DateTimeField(null=True)
|
2023-10-10 06:43:08 +00:00
|
|
|
did_issuer = models.CharField(max_length=250)
|
|
|
|
did_subject = models.CharField(max_length=250)
|
2023-10-26 11:33:13 +00:00
|
|
|
data = models.TextField()
|
|
|
|
status = models.PositiveSmallIntegerField(
|
|
|
|
choices=Status.choices,
|
2023-10-31 16:07:43 +00:00
|
|
|
default=Status.ENABLED
|
2023-10-26 11:33:13 +00:00
|
|
|
)
|
2023-10-16 17:08:18 +00:00
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='vcredentials',
|
|
|
|
)
|
2023-10-10 06:43:08 +00:00
|
|
|
|
2023-10-26 11:33:13 +00:00
|
|
|
@property
|
|
|
|
def get_schema(self):
|
|
|
|
if not self.data:
|
|
|
|
return {}
|
|
|
|
return json.loads(self.data)
|
|
|
|
|
|
|
|
def type(self):
|
|
|
|
return self.get_schema.get('name', '')
|
|
|
|
|
|
|
|
def description(self):
|
|
|
|
return self.get_schema.get('description', '')
|
|
|
|
|
|
|
|
def get_status(self):
|
|
|
|
return self.Status(self.status).label
|
2023-10-10 06:43:08 +00:00
|
|
|
|
2023-10-30 12:53:19 +00:00
|
|
|
def get_datas(self):
|
|
|
|
data = json.loads(self.data).get('instance').items()
|
|
|
|
return data
|
2023-11-02 13:17:07 +00:00
|
|
|
|
2023-11-14 16:45:08 +00:00
|
|
|
def issue(self, did):
|
2023-11-02 13:17:07 +00:00
|
|
|
self.status = self.Status.ISSUED
|
|
|
|
self.did_subject = did
|
2023-11-14 16:45:08 +00:00
|
|
|
self.issued_on = datetime.datetime.now()
|
|
|
|
|
|
|
|
def get_issued_on(self):
|
|
|
|
return self.issued_on.strftime("%m/%d/%Y")
|
2023-10-30 12:53:19 +00:00
|
|
|
|
2023-10-10 06:43:08 +00:00
|
|
|
class VCTemplate(models.Model):
|
|
|
|
wkit_template_id = models.CharField(max_length=250)
|
|
|
|
data = models.TextField()
|
|
|
|
|
|
|
|
|
2023-10-25 10:18:42 +00:00
|
|
|
class File_datas(models.Model):
|
|
|
|
file_name = models.CharField(max_length=250)
|
|
|
|
success = models.BooleanField(default=True)
|
|
|
|
created_at = models.DateTimeField(auto_now=True)
|
|
|
|
|
|
|
|
|
2023-10-16 17:08:18 +00:00
|
|
|
class Membership(models.Model):
|
|
|
|
"""
|
|
|
|
This model represent the relation of this user with the ecosystem.
|
|
|
|
"""
|
|
|
|
class Types(models.IntegerChoices):
|
|
|
|
BENEFICIARY = 1, _('Beneficiary')
|
|
|
|
EMPLOYEE = 2, _('Employee')
|
2023-11-13 09:15:52 +00:00
|
|
|
MEMBER = 3, _('Member')
|
2023-10-16 17:08:18 +00:00
|
|
|
|
|
|
|
type = models.PositiveSmallIntegerField(_('Type of membership'), choices=Types.choices)
|
|
|
|
start_date = models.DateField(
|
|
|
|
_('Start date'),
|
|
|
|
help_text=_('What date did the membership start?'),
|
|
|
|
blank=True,
|
|
|
|
null=True
|
|
|
|
)
|
|
|
|
end_date = models.DateField(
|
|
|
|
_('End date'),
|
2023-11-13 09:15:52 +00:00
|
|
|
help_text=_('What date will the membership end?'),
|
2023-10-16 17:08:18 +00:00
|
|
|
blank=True,
|
|
|
|
null=True
|
|
|
|
)
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='memberships',
|
|
|
|
)
|
2023-10-17 08:53:03 +00:00
|
|
|
|
|
|
|
def get_type(self):
|
|
|
|
return dict(self.Types.choices).get(self.type)
|
2023-10-17 11:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Rol(models.Model):
|
2023-11-14 14:55:17 +00:00
|
|
|
name = models.CharField(_("name"), max_length=250)
|
|
|
|
description = models.CharField(_("Description"), max_length=250, null=True)
|
2023-10-17 13:49:56 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Service(models.Model):
|
2023-11-13 17:09:37 +00:00
|
|
|
domain = models.CharField(_("Domain"), max_length=250)
|
|
|
|
description = models.CharField(_("Description"), max_length=250)
|
2023-10-19 13:20:06 +00:00
|
|
|
rol = models.ManyToManyField(
|
2023-10-17 13:49:56 +00:00
|
|
|
Rol,
|
|
|
|
)
|
2023-10-17 15:42:48 +00:00
|
|
|
|
2023-10-19 13:20:06 +00:00
|
|
|
def get_roles(self):
|
2023-11-14 16:45:08 +00:00
|
|
|
if self.rol.exists():
|
|
|
|
return ", ".join([x.name for x in self.rol.all()])
|
|
|
|
return _("None")
|
2023-10-19 13:20:06 +00:00
|
|
|
|
2023-10-17 15:42:48 +00:00
|
|
|
def __str__(self):
|
2023-10-27 09:19:10 +00:00
|
|
|
return "{} -> {}".format(self.domain, self.get_roles())
|
2023-10-17 15:42:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserRol(models.Model):
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='roles',
|
|
|
|
)
|
|
|
|
service = models.ForeignKey(
|
|
|
|
Service,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='users',
|
|
|
|
)
|
2023-11-02 16:13:49 +00:00
|
|
|
|
2023-11-14 14:55:17 +00:00
|
|
|
class Meta:
|
|
|
|
unique_together = ('user', 'service',)
|
|
|
|
|
2023-11-02 16:13:49 +00:00
|
|
|
|
|
|
|
class Organization(models.Model):
|
|
|
|
name = models.CharField(max_length=250)
|
|
|
|
url = models.CharField(
|
|
|
|
help_text=_("Url where to send the presentation"),
|
|
|
|
max_length=250
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def send(self, cred):
|
|
|
|
return
|
|
|
|
requests.post(self.url, data=cred.data)
|