diff --git a/idhub/admin/views.py b/idhub/admin/views.py index ab5b0fa..9b40faa 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -291,7 +291,6 @@ class PeopleMembershipEditView(People, FormView): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['instance'] = self.object - # import pdb; pdb.set_trace() return kwargs def form_valid(self, form): @@ -475,7 +474,7 @@ class ServicesView(AccessControl): }) return context -class ServiceRegisterView(AccessControl, UpdateView): +class ServiceRegisterView(AccessControl, CreateView): template_name = "idhub/admin/service_register.html" subtitle = _('Add service') icon = '' @@ -484,6 +483,11 @@ class ServiceRegisterView(AccessControl, UpdateView): success_url = reverse_lazy('idhub:admin_services') object = None + def get_form(self): + form = super().get_form() + form.fields['rol'].required = False + return form + def form_valid(self, form): form.save() messages.success(self.request, _('Service created successfully')) @@ -506,6 +510,11 @@ class ServiceEditView(AccessControl, UpdateView): kwargs = super().get_form_kwargs() return kwargs + def get_form(self): + form = super().get_form() + form.fields['rol'].required = False + return form + def form_valid(self, form): form.save() messages.success(self.request, _('Service updated successfully')) diff --git a/idhub/migrations/0001_initial.py b/idhub/migrations/0001_initial.py index fe6fc19..bbd5d49 100644 --- a/idhub/migrations/0001_initial.py +++ b/idhub/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.5 on 2023-11-02 15:08 +# Generated by Django 4.2.5 on 2023-11-14 16:32 from django.conf import settings from django.db import migrations, models @@ -63,7 +63,13 @@ class Migration(migrations.Migration): verbose_name='ID', ), ), - ('name', models.CharField(max_length=250)), + ('name', models.CharField(max_length=250, verbose_name='name')), + ( + 'description', + models.CharField( + max_length=250, null=True, verbose_name='Description' + ), + ), ], ), migrations.CreateModel( @@ -95,8 +101,11 @@ class Migration(migrations.Migration): verbose_name='ID', ), ), - ('domain', models.CharField(max_length=250)), - ('description', models.CharField(max_length=250)), + ('domain', models.CharField(max_length=250, verbose_name='Domain')), + ( + 'description', + models.CharField(max_length=250, verbose_name='Description'), + ), ('rol', models.ManyToManyField(to='idhub.rol')), ], ), @@ -131,7 +140,7 @@ class Migration(migrations.Migration): ('id_string', models.CharField(max_length=250)), ('verified', models.BooleanField()), ('created_on', models.DateTimeField(auto_now=True)), - ('issuer_on', models.DateTimeField(null=True)), + ('issued_on', models.DateTimeField(null=True)), ('did_issuer', models.CharField(max_length=250)), ('did_subject', models.CharField(max_length=250)), ('data', models.TextField()), @@ -157,6 +166,141 @@ class Migration(migrations.Migration): ), ], ), + migrations.CreateModel( + name='Membership', + fields=[ + ( + 'id', + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ( + 'type', + models.PositiveSmallIntegerField( + choices=[(1, 'Beneficiary'), (2, 'Employee'), (3, 'Member')], + verbose_name='Type of membership', + ), + ), + ( + 'start_date', + models.DateField( + blank=True, + help_text='What date did the membership start?', + null=True, + verbose_name='Start date', + ), + ), + ( + 'end_date', + models.DateField( + blank=True, + help_text='What date will the membership end?', + null=True, + verbose_name='End date', + ), + ), + ( + 'user', + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='memberships', + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + 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, + ), + ), + ], + ), + migrations.CreateModel( + name='DID', + fields=[ + ( + 'id', + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('created_at', models.DateTimeField(auto_now=True)), + ('did', models.CharField(max_length=250, unique=True)), + ('label', models.CharField(max_length=50)), + ( + 'user', + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name='dids', + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), migrations.CreateModel( name='UserRol', fields=[ @@ -186,78 +330,8 @@ class Migration(migrations.Migration): ), ), ], - ), - migrations.CreateModel( - name='Membership', - fields=[ - ( - 'id', - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name='ID', - ), - ), - ( - 'type', - models.PositiveSmallIntegerField( - choices=[(1, 'Beneficiary'), (2, 'Employee'), (3, 'Partner')], - verbose_name='Type of membership', - ), - ), - ( - 'start_date', - models.DateField( - blank=True, - help_text='What date did the membership start?', - null=True, - verbose_name='Start date', - ), - ), - ( - 'end_date', - models.DateField( - blank=True, - help_text='What date did the membership end?', - null=True, - verbose_name='End date', - ), - ), - ( - 'user', - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name='memberships', - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - migrations.CreateModel( - name='DID', - fields=[ - ( - 'id', - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name='ID', - ), - ), - ('created_at', models.DateTimeField(auto_now=True)), - ('did', models.CharField(max_length=250, unique=True)), - ('label', models.CharField(max_length=50)), - ( - 'user', - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name='dids', - to=settings.AUTH_USER_MODEL, - ), - ), - ], + options={ + 'unique_together': {('user', 'service')}, + }, ), ] diff --git a/idhub/migrations/0002_event.py b/idhub/migrations/0002_event.py deleted file mode 100644 index d79ffd1..0000000 --- a/idhub/migrations/0002_event.py +++ /dev/null @@ -1,77 +0,0 @@ -# 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, - ), - ), - ], - ), - ] diff --git a/idhub/migrations/0003_rol_description_alter_membership_end_date_and_more.py b/idhub/migrations/0003_rol_description_alter_membership_end_date_and_more.py deleted file mode 100644 index 8985e6d..0000000 --- a/idhub/migrations/0003_rol_description_alter_membership_end_date_and_more.py +++ /dev/null @@ -1,52 +0,0 @@ -# Generated by Django 4.2.5 on 2023-11-14 09:19 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ('idhub', '0002_event'), - ] - - operations = [ - migrations.AddField( - model_name='rol', - name='description', - field=models.CharField( - max_length=250, null=True, verbose_name='Description' - ), - ), - migrations.AlterField( - model_name='membership', - name='end_date', - field=models.DateField( - blank=True, - help_text='What date will the membership end?', - null=True, - verbose_name='End date', - ), - ), - migrations.AlterField( - model_name='membership', - name='type', - field=models.PositiveSmallIntegerField( - choices=[(1, 'Beneficiary'), (2, 'Employee'), (3, 'Member')], - verbose_name='Type of membership', - ), - ), - migrations.AlterField( - model_name='rol', - name='name', - field=models.CharField(max_length=250, verbose_name='name'), - ), - migrations.AlterField( - model_name='service', - name='description', - field=models.CharField(max_length=250, verbose_name='Description'), - ), - migrations.AlterField( - model_name='service', - name='domain', - field=models.CharField(max_length=250, verbose_name='Domain'), - ), - ] diff --git a/idhub/migrations/0004_alter_userrol_unique_together.py b/idhub/migrations/0004_alter_userrol_unique_together.py deleted file mode 100644 index 4466e94..0000000 --- a/idhub/migrations/0004_alter_userrol_unique_together.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.5 on 2023-11-14 09:49 - -from django.conf import settings -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('idhub', '0003_rol_description_alter_membership_end_date_and_more'), - ] - - operations = [ - migrations.AlterUniqueTogether( - name='userrol', - unique_together={('user', 'service')}, - ), - ] diff --git a/idhub/models.py b/idhub/models.py index bf6fd8b..19c42c6 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -1,5 +1,6 @@ import json import requests +import datetime from django.db import models from django.utils.translation import gettext_lazy as _ from idhub_auth.models import User @@ -443,7 +444,7 @@ class VerificableCredential(models.Model): id_string = models.CharField(max_length=250) verified = models.BooleanField() created_on = models.DateTimeField(auto_now=True) - issuer_on = models.DateTimeField(null=True) + issued_on = models.DateTimeField(null=True) did_issuer = models.CharField(max_length=250) did_subject = models.CharField(max_length=250) data = models.TextField() @@ -476,9 +477,13 @@ class VerificableCredential(models.Model): data = json.loads(self.data).get('instance').items() return data - def get_issued(self, did): + def issue(self, did): self.status = self.Status.ISSUED self.did_subject = did + self.issued_on = datetime.datetime.now() + + def get_issued_on(self): + return self.issued_on.strftime("%m/%d/%Y") class VCTemplate(models.Model): wkit_template_id = models.CharField(max_length=250) @@ -540,7 +545,9 @@ class Service(models.Model): ) def get_roles(self): - return ", ".join([x.name for x in self.rol.all()]) + if self.rol.exists(): + return ", ".join([x.name for x in self.rol.all()]) + return _("None") def __str__(self): return "{} -> {}".format(self.domain, self.get_roles()) diff --git a/idhub/templates/idhub/admin/credentials.html b/idhub/templates/idhub/admin/credentials.html index 819535e..06cd110 100644 --- a/idhub/templates/idhub/admin/credentials.html +++ b/idhub/templates/idhub/admin/credentials.html @@ -15,7 +15,7 @@