add events of the system
This commit is contained in:
parent
d154617ca3
commit
35d7f014be
|
@ -28,6 +28,7 @@ from idhub.email.views import NotifyActivateUserByEmail
|
|||
from idhub.admin.forms import ImportForm, SchemaForm
|
||||
from idhub.models import (
|
||||
DID,
|
||||
Event,
|
||||
File_datas,
|
||||
Membership,
|
||||
Rol,
|
||||
|
@ -45,6 +46,13 @@ class DashboardView(AdminView, TemplateView):
|
|||
icon = 'bi bi-bell'
|
||||
section = "Home"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'events': Event.objects.filter(user=None),
|
||||
})
|
||||
return context
|
||||
|
||||
class People(AdminView):
|
||||
title = _("People Management")
|
||||
section = "People"
|
||||
|
@ -114,8 +122,10 @@ class PeopleActivateView(PeopleView):
|
|||
|
||||
if self.object.is_active:
|
||||
self.object.is_active = False
|
||||
Event.set_EV_USR_DEACTIVATED_BY_ADMIN(self.object)
|
||||
else:
|
||||
self.object.is_active = True
|
||||
Event.set_EV_USR_ACTIVATED_BY_ADMIN(self.object)
|
||||
self.object.save()
|
||||
|
||||
return redirect('idhub:admin_people', self.object.id)
|
||||
|
@ -128,17 +138,27 @@ class PeopleDeleteView(PeopleView):
|
|||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
if self.object != self.request.user:
|
||||
Event.set_EV_USR_DELETED_BY_ADMIN(self.object)
|
||||
self.object.delete()
|
||||
else:
|
||||
messages.error(self.request, _('Is not possible delete your account!'))
|
||||
|
||||
return redirect('idhub:admin_people_list')
|
||||
|
||||
|
||||
class PeopleEditView(PeopleView, UpdateView):
|
||||
template_name = "idhub/admin/user_edit.html"
|
||||
fields = ('first_name', 'last_name', 'email')
|
||||
success_url = reverse_lazy('idhub:admin_people_list')
|
||||
|
||||
def form_valid(self, form):
|
||||
user = form.save()
|
||||
messages.success(self.request, _('The account is updated successfully'))
|
||||
Event.set_EV_USR_UPDATED_BY_ADMIN(user)
|
||||
Event.set_EV_USR_UPDATED(user)
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class PeopleRegisterView(NotifyActivateUserByEmail, People, CreateView):
|
||||
template_name = "idhub/admin/people_register.html"
|
||||
|
@ -158,6 +178,9 @@ class PeopleRegisterView(NotifyActivateUserByEmail, People, CreateView):
|
|||
def form_valid(self, form):
|
||||
user = form.save()
|
||||
messages.success(self.request, _('The account is created successfully'))
|
||||
Event.set_EV_USR_REGISTERED(user)
|
||||
Event.set_EV_USR_WELCOME(user)
|
||||
|
||||
if user.is_active:
|
||||
try:
|
||||
self.send_email(user)
|
||||
|
@ -327,6 +350,12 @@ class RolRegisterView(AccessControl, CreateView):
|
|||
success_url = reverse_lazy('idhub:admin_roles')
|
||||
object = None
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _('Rol created successfully'))
|
||||
Event.set_EV_ROLE_CREATED_BY_ADMIN()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class RolEditView(AccessControl, CreateView):
|
||||
template_name = "idhub/admin/rol_register.html"
|
||||
|
@ -343,6 +372,12 @@ class RolEditView(AccessControl, CreateView):
|
|||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _('Rol updated successfully'))
|
||||
Event.set_EV_ROLE_MODIFIED_BY_ADMIN()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class RolDeleteView(AccessControl):
|
||||
model = Rol
|
||||
|
@ -352,6 +387,8 @@ class RolDeleteView(AccessControl):
|
|||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
self.object.delete()
|
||||
messages.success(self.request, _('Rol deleted successfully'))
|
||||
Event.set_EV_ROLE_DELETED_BY_ADMIN()
|
||||
return redirect('idhub:admin_roles')
|
||||
|
||||
|
||||
|
@ -376,6 +413,12 @@ class ServiceRegisterView(AccessControl, CreateView):
|
|||
success_url = reverse_lazy('idhub:admin_services')
|
||||
object = None
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _('Service created successfully'))
|
||||
Event.set_EV_SERVICE_CREATED_BY_ADMIN()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ServiceEditView(AccessControl, CreateView):
|
||||
template_name = "idhub/admin/service_register.html"
|
||||
|
@ -392,6 +435,12 @@ class ServiceEditView(AccessControl, CreateView):
|
|||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _('Service updated successfully'))
|
||||
Event.set_EV_SERVICE_MODIFIED_BY_ADMIN()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ServiceDeleteView(AccessControl):
|
||||
model = Service
|
||||
|
@ -401,6 +450,8 @@ class ServiceDeleteView(AccessControl):
|
|||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
self.object.delete()
|
||||
messages.success(self.request, _('Service deleted successfully'))
|
||||
Event.set_EV_SERVICE_DELETED_BY_ADMIN()
|
||||
return redirect('idhub:admin_services')
|
||||
|
||||
|
||||
|
@ -462,6 +513,8 @@ class RevokeCredentialsView(Credentials):
|
|||
self.object.status = VerificableCredential.Status.REVOKED
|
||||
self.object.save()
|
||||
messages.success(self.request, _('Credential revoked successfully'))
|
||||
Event.set_EV_CREDENTIAL_REVOKED_BY_ADMIN(self.object)
|
||||
Event.set_EV_CREDENTIAL_REVOKED(self.object)
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
@ -482,6 +535,8 @@ class DeleteCredentialsView(Credentials):
|
|||
if self.object.status in status:
|
||||
self.object.delete()
|
||||
messages.success(self.request, _('Credential deleted successfully'))
|
||||
Event.set_EV_CREDENTIAL_DELETED(self.object)
|
||||
Event.set_EV_CREDENTIAL_DELETED_BY_ADMIN(self.object)
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
@ -514,6 +569,7 @@ class DidRegisterView(Credentials, CreateView):
|
|||
form.instance.did = iota.issue_did()
|
||||
form.save()
|
||||
messages.success(self.request, _('DID created successfully'))
|
||||
Event.set_EV_ORG_DID_CREATED_BY_ADMIN(form.instance)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
@ -547,9 +603,9 @@ class DidDeleteView(Credentials, DeleteView):
|
|||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
Event.set_EV_ORG_DID_DELETED_BY_ADMIN(self.object)
|
||||
self.object.delete()
|
||||
messages.success(self.request, _('DID delete successfully'))
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
||||
|
@ -738,9 +794,12 @@ class ImportAddView(ImportExport, FormView):
|
|||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
cred = form.save()
|
||||
if cred:
|
||||
creds = form.save()
|
||||
if creds:
|
||||
messages.success(self.request, _("The file import was successfully!"))
|
||||
for cred in creds:
|
||||
Event.set_EV_CREDENTIAL_ENABLED(cred)
|
||||
Event.set_EV_CREDENTIAL_CAN_BE_REQUESTED(cred)
|
||||
else:
|
||||
messages.error(self.request, _("Error importing the file!"))
|
||||
return super().form_valid(form)
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
# Generated by Django 4.2.5 on 2023-11-09 13:54
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('idhub', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Event',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name='ID',
|
||||
),
|
||||
),
|
||||
('created', models.DateTimeField(auto_now=True)),
|
||||
('message', models.CharField(max_length=350)),
|
||||
(
|
||||
'type',
|
||||
models.PositiveSmallIntegerField(
|
||||
choices=[
|
||||
(1, 'EV_USR_REGISTERED'),
|
||||
(2, 'EV_USR_WELCOME'),
|
||||
(3, 'EV_DATA_UPDATE_REQUESTED_BY_USER'),
|
||||
(4, 'EV_DATA_UPDATE_REQUESTED'),
|
||||
(5, 'EV_USR_UPDATED_BY_ADMIN'),
|
||||
(6, 'EV_USR_UPDATED'),
|
||||
(7, 'EV_USR_DELETED_BY_ADMIN'),
|
||||
(8, 'EV_DID_CREATED_BY_USER'),
|
||||
(9, 'EV_DID_CREATED'),
|
||||
(10, 'EV_DID_DELETED'),
|
||||
(11, 'EV_CREDENTIAL_DELETED_BY_ADMIN'),
|
||||
(12, 'EV_CREDENTIAL_DELETED'),
|
||||
(13, 'EV_CREDENTIAL_ISSUED_FOR_USER'),
|
||||
(14, 'EV_CREDENTIAL_ISSUED'),
|
||||
(15, 'EV_CREDENTIAL_PRESENTED_BY_USER'),
|
||||
(16, 'EV_CREDENTIAL_PRESENTED'),
|
||||
(17, 'EV_CREDENTIAL_ENABLED'),
|
||||
(18, 'EV_CREDENTIAL_CAN_BE_REQUESTED'),
|
||||
(19, 'EV_CREDENTIAL_REVOKED_BY_ADMIN'),
|
||||
(20, 'EV_CREDENTIAL_REVOKED'),
|
||||
(21, 'EV_ROLE_CREATED_BY_ADMIN'),
|
||||
(22, 'EV_ROLE_MODIFIED_BY_ADMIN'),
|
||||
(23, 'EV_ROLE_DELETED_BY_ADMIN'),
|
||||
(24, 'EV_SERVICE_CREATED_BY_ADMIN'),
|
||||
(25, 'EV_SERVICE_MODIFIED_BY_ADMIN'),
|
||||
(26, 'EV_SERVICE_DELETED_BY_ADMIN'),
|
||||
(27, 'EV_ORG_DID_CREATED_BY_ADMIN'),
|
||||
(28, 'EV_ORG_DID_DELETED_BY_ADMIN'),
|
||||
(29, 'EV_USR_DEACTIVATED_BY_ADMIN'),
|
||||
(30, 'EV_USR_ACTIVATED_BY_ADMIN'),
|
||||
]
|
||||
),
|
||||
),
|
||||
(
|
||||
'user',
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='events',
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
381
idhub/models.py
381
idhub/models.py
|
@ -5,11 +5,382 @@ from django.utils.translation import gettext_lazy as _
|
|||
from idhub_auth.models import User
|
||||
|
||||
|
||||
# class Event(models.Model):
|
||||
# Para los "audit logs" que se requieren en las pantallas.
|
||||
# timestamp = models.DateTimeField()
|
||||
# Los eventos no tienen relación con otros objetos a nivel de BBDD.
|
||||
# event_data = models.CharField(max_length=250)
|
||||
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"
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
def get_type(self):
|
||||
return self.Types(self.type).label
|
||||
|
||||
@classmethod
|
||||
def set_EV_USR_REGISTERED(cls, user):
|
||||
msg = "The user {} was registered: name: {}, last name: {}".format(
|
||||
user.username,
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_USR_REGISTERED,
|
||||
message=msg
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_USR_WELCOME(cls, user):
|
||||
msg = "Welcome. You has been registered: name: {}, last name: {}".format(
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
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):
|
||||
msg = "The user '{}' has request the update of the following information: "
|
||||
msg += "['field1':'value1', 'field2':'value2'>,...]".format(
|
||||
user.username,
|
||||
)
|
||||
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):
|
||||
msg = "You have requested the update of the following information: "
|
||||
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: "
|
||||
msg += "name: {}, last name: {}".format(
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
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: "
|
||||
msg += "name: {}, last name: {}".format(
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_USR_UPDATED,
|
||||
message=msg,
|
||||
user=user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_USR_DELETED_BY_ADMIN(cls, user):
|
||||
msg = "The admin has deleted the user: username: {}".format(
|
||||
user.username,
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_USR_DELETED_BY_ADMIN,
|
||||
message=msg
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_DID_CREATED_BY_USER(cls, did):
|
||||
msg = "New DID with DID-ID: '{}' created by user '{}'".format(
|
||||
did.did,
|
||||
did.user.username
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_DID_CREATED_BY_USER,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_DID_CREATED(cls, did):
|
||||
msg = "New DID with label: '{}' and DID-ID: '{}' was created'".format(
|
||||
did.label,
|
||||
did.did
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_DID_CREATED,
|
||||
message=msg,
|
||||
user=did.user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_DID_DELETED(cls, did):
|
||||
msg = "The DID with label '{}' and DID-ID: '{}' was deleted from your wallet".format(
|
||||
did.label,
|
||||
did.did
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_DID_DELETED,
|
||||
message=msg,
|
||||
user=did.user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_DELETED_BY_ADMIN(cls, cred):
|
||||
msg = "The credential of type '{}' and ID: '{}' was deleted".format(
|
||||
cred.type(),
|
||||
cred.id,
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_DELETED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_DELETED(cls, cred):
|
||||
msg = "The credential of type '{}' and ID: '{}' was deleted from your wallet".format(
|
||||
cred.type(),
|
||||
cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_DELETED,
|
||||
message=msg,
|
||||
user=cred.user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_ISSUED_FOR_USER(cls, cred):
|
||||
msg = "The credential of type '{}' and ID: '{}' was issued for user {}".format(
|
||||
cred.type(),
|
||||
cred.id,
|
||||
cred.user.username
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_ISSUED_FOR_USER,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_ISSUED(cls, cred):
|
||||
msg = "The credential of type '{}' and ID: '{}' was issued and stored in your wallet".format(
|
||||
cred.type(),
|
||||
cred.id
|
||||
)
|
||||
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):
|
||||
msg = "The credential of type '{}' and ID: '{}' was presented by user {} to verifier '{}".format(
|
||||
cred.type(),
|
||||
cred.id,
|
||||
cred.user.username,
|
||||
verifier
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_PRESENTED_BY_USER,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_PRESENTED(cls, cred, verifier):
|
||||
msg = "The credential of type '{}' and ID: '{}' was presented to verifier '{}'".format(
|
||||
cred.type(),
|
||||
cred.id,
|
||||
verifier
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_PRESENTED,
|
||||
message=msg,
|
||||
user=cred.user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_ENABLED(cls, cred):
|
||||
msg = "The credential of type '{}' was enabled for user {}".format(
|
||||
cred.type(),
|
||||
cred.user.username
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_ENABLED,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_CAN_BE_REQUESTED(cls, cred):
|
||||
msg = "You can request the '{}' credential".format(
|
||||
cred.type()
|
||||
)
|
||||
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):
|
||||
msg = "The credential of type '{}' and ID: '{}' was revoked for ".format(
|
||||
cred.type(),
|
||||
cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_REVOKED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_CREDENTIAL_REVOKED(cls, cred):
|
||||
msg = "The credential of type '{}' and ID: '{}' was revoked by admin".format(
|
||||
cred.type(),
|
||||
cred.id
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_CREDENTIAL_REVOKED,
|
||||
message=msg,
|
||||
user=cred.user
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_ROLE_CREATED_BY_ADMIN(cls):
|
||||
msg = 'A new role was created by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_ROLE_CREATED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_ROLE_MODIFIED_BY_ADMIN(cls):
|
||||
msg = 'The role was modified by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_ROLE_MODIFIED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_ROLE_DELETED_BY_ADMIN(cls):
|
||||
msg = 'The role was removed by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_ROLE_DELETED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_SERVICE_CREATED_BY_ADMIN(cls):
|
||||
msg = 'A new service was created by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_SERVICE_CREATED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_SERVICE_MODIFIED_BY_ADMIN(cls):
|
||||
msg = 'The service was modified by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_SERVICE_MODIFIED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_SERVICE_DELETED_BY_ADMIN(cls):
|
||||
msg = 'The service was removed by admin'
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_SERVICE_DELETED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_ORG_DID_CREATED_BY_ADMIN(cls, did):
|
||||
msg = "New Organisational DID with label: '{}' and DID-ID: '{}' was created".format(
|
||||
did.label,
|
||||
did.did
|
||||
)
|
||||
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):
|
||||
msg = "Organisational DID with label: '{}' and DID-ID: '{}' was removed".format(
|
||||
did.label,
|
||||
did.did
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_ORG_DID_DELETED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_USR_DEACTIVATED_BY_ADMIN(cls, user):
|
||||
msg = "The user '{}' was temporarily deactivated: [name:'{}', last name:'{}']".format(
|
||||
user.username,
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_USR_DEACTIVATED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_EV_USR_ACTIVATED_BY_ADMIN(cls, user):
|
||||
msg = "The user '{}' was activated: [name:'{}', last name:'{}']".format(
|
||||
user.username,
|
||||
user.first_name,
|
||||
user.last_name
|
||||
)
|
||||
cls.objects.create(
|
||||
type=cls.Types.EV_USR_ACTIVATED_BY_ADMIN,
|
||||
message=msg,
|
||||
)
|
||||
|
||||
|
||||
class DID(models.Model):
|
||||
|
|
|
@ -10,131 +10,20 @@
|
|||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col"><button type="button" class="btn btn-green-admin border border-dark">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-green-admin">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey ">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Type' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Date' %}</button></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ev in events %}
|
||||
<tr>
|
||||
<td>1,001</td>
|
||||
<td>random</td>
|
||||
<td>data</td>
|
||||
<td>placeholder</td>
|
||||
<td>text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,002</td>
|
||||
<td>placeholder</td>
|
||||
<td>irrelevant</td>
|
||||
<td>visual</td>
|
||||
<td>layout</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,003</td>
|
||||
<td>data</td>
|
||||
<td>rich</td>
|
||||
<td>dashboard</td>
|
||||
<td>tabular</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,003</td>
|
||||
<td>information</td>
|
||||
<td>placeholder</td>
|
||||
<td>illustrative</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,004</td>
|
||||
<td>text</td>
|
||||
<td>random</td>
|
||||
<td>layout</td>
|
||||
<td>dashboard</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,005</td>
|
||||
<td>dashboard</td>
|
||||
<td>irrelevant</td>
|
||||
<td>text</td>
|
||||
<td>placeholder</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,006</td>
|
||||
<td>dashboard</td>
|
||||
<td>illustrative</td>
|
||||
<td>rich</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,007</td>
|
||||
<td>placeholder</td>
|
||||
<td>tabular</td>
|
||||
<td>information</td>
|
||||
<td>irrelevant</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,008</td>
|
||||
<td>random</td>
|
||||
<td>data</td>
|
||||
<td>placeholder</td>
|
||||
<td>text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,009</td>
|
||||
<td>placeholder</td>
|
||||
<td>irrelevant</td>
|
||||
<td>visual</td>
|
||||
<td>layout</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,010</td>
|
||||
<td>data</td>
|
||||
<td>rich</td>
|
||||
<td>dashboard</td>
|
||||
<td>tabular</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,011</td>
|
||||
<td>information</td>
|
||||
<td>placeholder</td>
|
||||
<td>illustrative</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,012</td>
|
||||
<td>text</td>
|
||||
<td>placeholder</td>
|
||||
<td>layout</td>
|
||||
<td>dashboard</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,013</td>
|
||||
<td>dashboard</td>
|
||||
<td>irrelevant</td>
|
||||
<td>text</td>
|
||||
<td>visual</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,014</td>
|
||||
<td>dashboard</td>
|
||||
<td>illustrative</td>
|
||||
<td>rich</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,015</td>
|
||||
<td>random</td>
|
||||
<td>tabular</td>
|
||||
<td>information</td>
|
||||
<td>text</td>
|
||||
<td>{{ ev.get_type }}</td>
|
||||
<td>{{ ev.message }}</td>
|
||||
<td>{{ ev.created }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6"><button type="button" class="btn btn-grey rounded-pill">Cancel</button></div>
|
||||
<div class="col-6"><button type="button" class="btn btn-green-admin rounded-pill">Revoke</button></div>
|
||||
<div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -10,131 +10,20 @@
|
|||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col"><button type="button" class="btn btn-green-user border border-dark">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-green-user">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey">Header</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Type' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Date' %}</button></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ev in user.events.all %}
|
||||
<tr>
|
||||
<td>1,001</td>
|
||||
<td>random</td>
|
||||
<td>data</td>
|
||||
<td>placeholder</td>
|
||||
<td>text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,002</td>
|
||||
<td>placeholder</td>
|
||||
<td>irrelevant</td>
|
||||
<td>visual</td>
|
||||
<td>layout</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,003</td>
|
||||
<td>data</td>
|
||||
<td>rich</td>
|
||||
<td>dashboard</td>
|
||||
<td>tabular</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,003</td>
|
||||
<td>information</td>
|
||||
<td>placeholder</td>
|
||||
<td>illustrative</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,004</td>
|
||||
<td>text</td>
|
||||
<td>random</td>
|
||||
<td>layout</td>
|
||||
<td>dashboard</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,005</td>
|
||||
<td>dashboard</td>
|
||||
<td>irrelevant</td>
|
||||
<td>text</td>
|
||||
<td>placeholder</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,006</td>
|
||||
<td>dashboard</td>
|
||||
<td>illustrative</td>
|
||||
<td>rich</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,007</td>
|
||||
<td>placeholder</td>
|
||||
<td>tabular</td>
|
||||
<td>information</td>
|
||||
<td>irrelevant</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,008</td>
|
||||
<td>random</td>
|
||||
<td>data</td>
|
||||
<td>placeholder</td>
|
||||
<td>text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,009</td>
|
||||
<td>placeholder</td>
|
||||
<td>irrelevant</td>
|
||||
<td>visual</td>
|
||||
<td>layout</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,010</td>
|
||||
<td>data</td>
|
||||
<td>rich</td>
|
||||
<td>dashboard</td>
|
||||
<td>tabular</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,011</td>
|
||||
<td>information</td>
|
||||
<td>placeholder</td>
|
||||
<td>illustrative</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,012</td>
|
||||
<td>text</td>
|
||||
<td>placeholder</td>
|
||||
<td>layout</td>
|
||||
<td>dashboard</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,013</td>
|
||||
<td>dashboard</td>
|
||||
<td>irrelevant</td>
|
||||
<td>text</td>
|
||||
<td>visual</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,014</td>
|
||||
<td>dashboard</td>
|
||||
<td>illustrative</td>
|
||||
<td>rich</td>
|
||||
<td>data</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1,015</td>
|
||||
<td>random</td>
|
||||
<td>tabular</td>
|
||||
<td>information</td>
|
||||
<td>text</td>
|
||||
<td>{{ ev.get_type }}</td>
|
||||
<td>{{ ev.message }}</td>
|
||||
<td>{{ ev.created }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6"><button type="button" class="btn btn-yellow rounded-pill">Cancel</button></div>
|
||||
<div class="col-6"><button type="button" class="btn btn-green-user rounded-pill">Revoke</button></div>
|
||||
<div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -72,23 +72,23 @@ class CredentialPresentationForm(forms.Form):
|
|||
]
|
||||
|
||||
def save(self, commit=True):
|
||||
org = Organization.objects.filter(
|
||||
self.org = Organization.objects.filter(
|
||||
id=self.data['organization']
|
||||
)
|
||||
cred = VerificableCredential.objects.filter(
|
||||
self.cred = VerificableCredential.objects.filter(
|
||||
user=self.user,
|
||||
id=self.data['credential'],
|
||||
status=VerificableCredential.Status.ISSUED
|
||||
)
|
||||
if not all([org.exists(), cred.exists()]):
|
||||
if not all([self.org.exists(), self.cred.exists()]):
|
||||
return
|
||||
|
||||
org =org[0]
|
||||
cred = cred[0]
|
||||
self.org = self.org[0]
|
||||
self.cred = self.cred[0]
|
||||
|
||||
if commit:
|
||||
org.send(cred)
|
||||
return cred
|
||||
self.org.send(self.cred)
|
||||
return self.cred
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.contrib import messages
|
|||
from utils.apiregiter import iota
|
||||
from idhub.user.forms import ProfileForm, RequestCredentialForm, CredentialPresentationForm
|
||||
from idhub.mixins import UserView
|
||||
from idhub.models import DID, VerificableCredential
|
||||
from idhub.models import DID, VerificableCredential, Event
|
||||
|
||||
|
||||
class MyProfile(UserView):
|
||||
|
@ -125,6 +125,8 @@ class CredentialsRequestView(MyWallet, FormView):
|
|||
cred = form.save()
|
||||
if cred:
|
||||
messages.success(self.request, _("The credential was required successfully!"))
|
||||
Event.set_EV_CREDENTIAL_ISSUED_FOR_USER(cred)
|
||||
Event.set_EV_CREDENTIAL_ISSUED(cred)
|
||||
else:
|
||||
messages.error(self.request, _("Not exists the credential!"))
|
||||
return super().form_valid(form)
|
||||
|
@ -145,6 +147,8 @@ class CredentialsPresentationView(MyWallet, FormView):
|
|||
def form_valid(self, form):
|
||||
cred = form.save()
|
||||
if cred:
|
||||
Event.set_EV_CREDENTIAL_PRESENTED_BY_USER(cred, form.org)
|
||||
Event.set_EV_CREDENTIAL_PRESENTED(cred, form.org)
|
||||
messages.success(self.request, _("The credential was presented successfully!"))
|
||||
else:
|
||||
messages.error(self.request, _("Error sending credential!"))
|
||||
|
@ -174,18 +178,14 @@ class DidRegisterView(MyWallet, CreateView):
|
|||
success_url = reverse_lazy('idhub:user_dids')
|
||||
object = None
|
||||
|
||||
# def get_form_kwargs(self):
|
||||
# kwargs = super().get_form_kwargs()
|
||||
# kwargs['initial'] = {
|
||||
# 'user': self.request.user
|
||||
# }
|
||||
# return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.user = self.request.user
|
||||
form.instance.did = iota.issue_did()
|
||||
form.save()
|
||||
messages.success(self.request, _('DID created successfully'))
|
||||
|
||||
Event.set_EV_DID_CREATED(form.instance)
|
||||
Event.set_EV_DID_CREATED_BY_USER(form.instance)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
@ -219,7 +219,9 @@ class DidDeleteView(MyWallet, DeleteView):
|
|||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
Event.set_EV_DID_DELETED(self.object)
|
||||
self.object.delete()
|
||||
messages.success(self.request, _('DID delete successfully'))
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
|
Loading…
Reference in New Issue