From d0ac9137223810e09c7b7552e3c1400285c64874 Mon Sep 17 00:00:00 2001 From: Felix Rindt Date: Tue, 7 Nov 2023 16:20:02 +0100 Subject: [PATCH] add federation models to logging --- .../oauth2_provider/application_list.html | 2 +- ephios/plugins/federation/models.py | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ephios/api/templates/oauth2_provider/application_list.html b/ephios/api/templates/oauth2_provider/application_list.html index 616be4b89..39780926d 100644 --- a/ephios/api/templates/oauth2_provider/application_list.html +++ b/ephios/api/templates/oauth2_provider/application_list.html @@ -28,7 +28,7 @@

{% translate "OAuth2 applications" %}

{{ application.name }} - {{ application.user }} + {{ application.user|default_if_none:"-" }} {{ application.created }} diff --git a/ephios/plugins/federation/models.py b/ephios/plugins/federation/models.py index 588f44bd4..fe99746a8 100644 --- a/ephios/plugins/federation/models.py +++ b/ephios/plugins/federation/models.py @@ -13,7 +13,9 @@ from ephios.api.models import AccessToken, Application from ephios.core.models import AbstractParticipation, Event, Qualification +from ephios.core.models.events import PARTICIPATION_LOG_CONFIG from ephios.core.signup.participants import AbstractParticipant +from ephios.modellogging.log import ModelFieldsLogConfig, register_model_for_logging class FederatedGuest(models.Model): @@ -35,6 +37,18 @@ class Meta: verbose_name_plural = _("federated guests") +register_model_for_logging( + FederatedGuest, + ModelFieldsLogConfig( + unlogged_fields=[ + "id", + "access_token", + "client_secret", + ], + ), +) + + class FederatedHost(models.Model): name = models.CharField(max_length=255) url = models.URLField(verbose_name=_("URL")) @@ -53,6 +67,17 @@ class Meta: verbose_name_plural = _("federated hosts") +register_model_for_logging( + FederatedHost, + ModelFieldsLogConfig( + unlogged_fields=[ + "id", + "access_token", + ], + ), +) + + class InviteCode(models.Model): code = models.CharField(max_length=255, default=token_hex) url = models.URLField(verbose_name=_("URL")) @@ -77,6 +102,18 @@ class Meta: verbose_name_plural = _("invite codes") +register_model_for_logging( + InviteCode, + ModelFieldsLogConfig( + unlogged_fields=[ + "id", + "code", + "created_at", + ], + ), +) + + class FederatedEventShare(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE) shared_with = models.ManyToManyField(FederatedGuest) @@ -89,6 +126,12 @@ class Meta: verbose_name_plural = _("federated event shares") +register_model_for_logging( + FederatedEventShare, + ModelFieldsLogConfig(), +) + + class FederatedUser(models.Model): email = models.EmailField(_("email address")) display_name = models.CharField(_("name"), max_length=254) @@ -115,6 +158,12 @@ class Meta: verbose_name_plural = _("federated users") +register_model_for_logging( + FederatedUser, + ModelFieldsLogConfig(), +) + + @dataclasses.dataclass(frozen=True) class FederatedParticipant(AbstractParticipant): federated_user: FederatedUser @@ -166,3 +215,9 @@ def participant(self) -> "AbstractParticipant": class Meta: verbose_name = _("federated participation") verbose_name_plural = _("federated participations") + + +register_model_for_logging( + FederatedParticipation, + PARTICIPATION_LOG_CONFIG, +)