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

Ajout d'une relation inverse vers le propriétaire pour les notifications #236

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
ikarius marked this conversation as resolved.
Show resolved Hide resolved
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
36 changes: 36 additions & 0 deletions dora/notifications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ def test_notification_str(notification, status):
assert notification.task_type in str(notification)


def test_related_objects():
structure = make_structure()

assert not structure.notifications.count()

notification = Notification(
owner_structure=structure, task_type=TaskType.GENERIC_TASK
)
notification.save()

assert notification == structure.notifications.first()

user = make_user()

assert not user.notifications.count()

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()

assert not putative_membership.notifications.count()

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