Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Ajout d'une relation inverse vers le propriétaire pour les notifications
Browse files Browse the repository at this point in the history
Utile d'une manière générale, obligatoire pour certaines notifications à venir
  • Loading branch information
ikarius committed Feb 23, 2024
1 parent dcbcd4b commit 5946327
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated by Django 4.2.10 on 2024-02-23 14:27

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("structures", "0063_structure_is_obsolete"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("notifications", "0002_remove_notification_check_structure_and_more"),
]

operations = [
migrations.AlterField(
model_name="notification",
name="owner_structure",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="notifications",
to="structures.structure",
verbose_name="Structure propriétaire",
),
),
migrations.AlterField(
model_name="notification",
name="owner_structureputativemember",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="notifications",
to="structures.structureputativemember",
verbose_name="Invitation propriétaire",
),
),
migrations.AlterField(
model_name="notification",
name="owner_user",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="notifications",
to=settings.AUTH_USER_MODEL,
verbose_name="Utilisateur propriétaire",
),
),
migrations.AlterField(
model_name="notification",
name="task_type",
field=models.CharField(
choices=[
("orphan_structures", "Orphan Structures"),
("service_activation", "Service Activation"),
("invited_users", "Invited Users"),
("self_invited_users", "Self Invited Users"),
("generic_task", "Generic Task"),
],
verbose_name="Type de tâche",
),
),
]
3 changes: 3 additions & 0 deletions dora/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,23 @@ class Notification(models.Model):
blank=True,
on_delete=models.CASCADE,
verbose_name="Structure propriétaire",
related_name="notifications",
)
owner_user = models.ForeignKey(
User,
null=True,
blank=True,
on_delete=models.CASCADE,
verbose_name="Utilisateur propriétaire",
related_name="notifications",
)
owner_structureputativemember = models.ForeignKey(
StructurePutativeMember,
null=True,
blank=True,
on_delete=models.CASCADE,
verbose_name="Invitation propriétaire",
related_name="notifications",
)
...

Expand Down
27 changes: 27 additions & 0 deletions dora/notifications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ def test_notification_str(notification, status):
assert notification.task_type in str(notification)


def test_related_objects():
structure = make_structure()
notification = Notification(
owner_structure=structure, task_type=TaskType.GENERIC_TASK
)
notification.save()

assert notification == structure.notifications.first()

user = make_user()
notification = Notification(owner_user=user, task_type=TaskType.GENERIC_TASK)
notification.save()

assert notification == user.notifications.first()

putative_membership = make_structure(
putative_member=make_user()
).putative_membership.first()
notification = Notification(
owner_structureputativemember=putative_membership,
task_type=TaskType.GENERIC_TASK,
)
notification.save()

assert notification == putative_membership.notifications.first()


def test_constraints(notification):
notification.owner_structure = None

Expand Down

0 comments on commit 5946327

Please sign in to comment.