diff --git a/idhub/migrations/0005_alter_file_datas_created_at_and_more.py b/idhub/migrations/0005_alter_file_datas_created_at_and_more.py new file mode 100644 index 0000000..42ba9f8 --- /dev/null +++ b/idhub/migrations/0005_alter_file_datas_created_at_and_more.py @@ -0,0 +1,84 @@ +# Generated by Django 4.2.5 on 2024-06-13 08:08 + +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', '0004_alter_event_type'), + ] + + operations = [ + migrations.AlterField( + model_name='file_datas', + name='created_at', + field=models.DateTimeField(auto_now=True, verbose_name='Date'), + ), + migrations.AlterField( + model_name='file_datas', + name='file_name', + field=models.CharField(max_length=250, verbose_name='File'), + ), + migrations.AlterField( + model_name='file_datas', + name='success', + field=models.BooleanField(default=True, verbose_name='Success'), + ), + migrations.AlterField( + model_name='schemas', + name='_description', + field=models.CharField( + db_column='description', + max_length=250, + null=True, + verbose_name='Description', + ), + ), + migrations.AlterField( + model_name='schemas', + name='_name', + field=models.TextField(db_column='name', null=True, verbose_name='Name'), + ), + migrations.AlterField( + model_name='schemas', + name='created_at', + field=models.DateTimeField(auto_now=True, verbose_name='Date'), + ), + migrations.AlterField( + model_name='schemas', + name='file_schema', + field=models.CharField(max_length=250, verbose_name='Schema'), + ), + migrations.AlterField( + model_name='verificablecredential', + name='issued_on', + field=models.DateTimeField(null=True, verbose_name='Issued on'), + ), + migrations.AlterField( + model_name='verificablecredential', + name='status', + field=models.PositiveSmallIntegerField( + choices=[(1, 'Enabled'), (2, 'Issued'), (3, 'Revoked'), (4, 'Expired')], + default=1, + verbose_name='Status', + ), + ), + migrations.AlterField( + model_name='verificablecredential', + name='type', + field=models.CharField(max_length=250, verbose_name='Type'), + ), + migrations.AlterField( + model_name='verificablecredential', + name='user', + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='vcredentials', + to=settings.AUTH_USER_MODEL, + verbose_name='User', + ), + ), + ] diff --git a/idhub_auth/migrations/0002_alter_user_is_active_alter_user_is_admin.py b/idhub_auth/migrations/0002_alter_user_is_active_alter_user_is_admin.py new file mode 100644 index 0000000..3d50023 --- /dev/null +++ b/idhub_auth/migrations/0002_alter_user_is_active_alter_user_is_admin.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.5 on 2024-06-13 08:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('idhub_auth', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='is_active', + field=models.BooleanField(default=True, verbose_name='is active'), + ), + migrations.AlterField( + model_name='user', + name='is_admin', + field=models.BooleanField(default=False, verbose_name='is admin'), + ), + ] diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index 18b9a4d..473fa24 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -82,7 +82,8 @@ INSTALLED_APPS = [ 'idhub_auth', 'oidc4vp', 'idhub', - 'promotion' + 'promotion', + 'webhook' ] MIDDLEWARE = [ diff --git a/trustchain_idhub/urls.py b/trustchain_idhub/urls.py index e8468a3..a4bc0b1 100644 --- a/trustchain_idhub/urls.py +++ b/trustchain_idhub/urls.py @@ -26,4 +26,5 @@ urlpatterns = [ path('', include('idhub.urls')), path('oidc4vp/', include('oidc4vp.urls')), path('promotion/', include('promotion.urls')), + path('webhook/', include('webhook.urls')), ] diff --git a/webhook/__init__.py b/webhook/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webhook/admin.py b/webhook/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/webhook/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/webhook/apps.py b/webhook/apps.py new file mode 100644 index 0000000..60ee235 --- /dev/null +++ b/webhook/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WebhookConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'webhook' diff --git a/webhook/forms.py b/webhook/forms.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/webhook/forms.py @@ -0,0 +1 @@ + diff --git a/webhook/migrations/0001_initial.py b/webhook/migrations/0001_initial.py new file mode 100644 index 0000000..7bad033 --- /dev/null +++ b/webhook/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.5 on 2024-06-13 08:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name='Token', + fields=[ + ( + 'id', + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('token', models.UUIDField()), + ], + ), + ] diff --git a/webhook/migrations/__init__.py b/webhook/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webhook/models.py b/webhook/models.py new file mode 100644 index 0000000..54218c2 --- /dev/null +++ b/webhook/models.py @@ -0,0 +1,7 @@ +from django.db import models + +# Create your models here. + + +class Token(models.Model): + token = models.UUIDField() diff --git a/webhook/tables.py b/webhook/tables.py new file mode 100644 index 0000000..498a38e --- /dev/null +++ b/webhook/tables.py @@ -0,0 +1,67 @@ +import django_tables2 as tables +from django.utils.html import format_html +from django.utils.translation import gettext_lazy as _ + +from webhook.models import Token + + +class ButtonColumn(tables.Column): + attrs = { + "a": { + "type": "button", + "class": "text-danger", + "title": "Remove", + } + } + # it makes no sense to order a column of buttons + orderable = False + # django_tables will only call the render function if it doesn't find + # any empty values in the data, so we stop it from matching the data + # to any value considered empty + empty_values = () + + def render(self): + return format_html('') + + +class TokensTable(tables.Table): + delete = ButtonColumn( + verbose_name=_("Delete"), + linkify={ + "viewname": "webhook:delete_token", + "args": [tables.A("pk")] + }, + orderable=False + ) + + token = tables.Column(verbose_name=_("Token"), empty_values=()) + + def render_view_user(self): + return format_html('') + + # def render_token(self, record): + # return record.get_memberships() + + # def order_membership(self, queryset, is_descending): + # # TODO: Test that this doesn't return more rows than it should + # queryset = queryset.order_by( + # ("-" if is_descending else "") + "memberships__type" + # ) + + # return (queryset, True) + + # def render_role(self, record): + # return record.get_roles() + + # def order_role(self, queryset, is_descending): + # queryset = queryset.order_by( + # ("-" if is_descending else "") + "roles" + # ) + + # return (queryset, True) + + class Meta: + model = Token + template_name = "idhub/custom_table.html" + fields = ("token", "view_user") + diff --git a/webhook/templates/token.html b/webhook/templates/token.html new file mode 100644 index 0000000..7ab829b --- /dev/null +++ b/webhook/templates/token.html @@ -0,0 +1,14 @@ +{% extends "idhub/base_admin.html" %} +{% load i18n %} +{% load render_table from django_tables2 %} + +{% block content %} +