Skip to content

Commit d44cedc

Browse files
committed
Merge branch 'feat/project-notif-counts' of https://github.com/etchegom/recommandations-collaboratives into feat/notif-navigation-project#805
2 parents 3fdaa56 + 16e7526 commit d44cedc

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

recoco/apps/home/static/home/css/dsfr/custom-dsfr.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@
5353
\* ˍˍˍˍ */
5454

5555
a {
56-
text-decoration: none !important;
56+
text-decoration: none;
5757

5858
&.btn,
5959
&.button,
6060
&.nav-link,
6161
&.link-secondary {
62-
text-decoration: none !important;
62+
text-decoration: none;
6363
}
6464
}
6565

6666
p a {
6767
text-decoration: underline;
68+
color: #0000EE;
6869
}
6970

7071
p {

recoco/apps/projects/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def for_user(self, user):
154154

155155
class ProjectQuerySet(models.QuerySet):
156156
def with_unread_notifications(self, user_id: int):
157-
158157
notification_query = Notification.objects.filter(
159158
recipient_id=user_id,
160159
target_object_id=Cast(OuterRef("pk"), output_field=models.CharField()),
@@ -185,7 +184,7 @@ def with_unread_notifications(self, user_id: int):
185184
conversation_notifications_count=Subquery(
186185
notification_query.filter(
187186
action_object_content_type=ContentType.objects.get_for_model(Note),
188-
# action_object__public=True,
187+
action_notes__public=True,
189188
)
190189
.unread()
191190
.order_by()
@@ -195,7 +194,7 @@ def with_unread_notifications(self, user_id: int):
195194
private_conversation_notifications_count=Subquery(
196195
notification_query.filter(
197196
action_object_content_type=ContentType.objects.get_for_model(Note),
198-
# action_object__public=False,
197+
action_notes__public=False,
199198
)
200199
.unread()
201200
.order_by()

recoco/apps/projects/tests/test_models.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
import pytest
1111
from django.conf import settings
12+
from django.contrib.contenttypes.models import ContentType
1213
from django.contrib.sites import models as sites
1314
from django.utils import timezone
1415
from model_bakery import baker
16+
from notifications.models import Notification
1517

18+
from recoco.apps.projects.models import Note
1619
from recoco.apps.tasks import models as task_models
20+
from recoco.apps.tasks.models import Task, TaskFollowup
1721

1822
from .. import models
1923

@@ -111,4 +115,60 @@ def test_projectsite_queryset():
111115
assert project.project_sites.current().site == site
112116

113117

118+
@pytest.mark.django_db
119+
def test_project_queryset_unread_notifications():
120+
project = baker.make(models.Project)
121+
user = baker.make(settings.AUTH_USER_MODEL)
122+
public_note = baker.make(Note, project=project, public=True)
123+
private_note = baker.make(Note, project=project, public=False)
124+
125+
project_ct = ContentType.objects.get_for_model(models.Project)
126+
task_ct = ContentType.objects.get_for_model(Task)
127+
task_followup_ct = ContentType.objects.get_for_model(TaskFollowup)
128+
note_ct = ContentType.objects.get_for_model(Note)
129+
130+
baker.make(
131+
Notification,
132+
recipient=user,
133+
target_object_id=project.id,
134+
target_content_type=project_ct,
135+
unread=True,
136+
action_object_content_type=task_ct,
137+
)
138+
baker.make(
139+
Notification,
140+
recipient=user,
141+
target_object_id=project.id,
142+
target_content_type=project_ct,
143+
unread=True,
144+
action_object_content_type=task_followup_ct,
145+
)
146+
baker.make(
147+
Notification,
148+
recipient=user,
149+
target_object_id=project.id,
150+
target_content_type=project_ct,
151+
unread=True,
152+
action_object_content_type=note_ct,
153+
action_object_object_id=public_note.id,
154+
)
155+
baker.make(
156+
Notification,
157+
recipient=user,
158+
target_object_id=project.id,
159+
target_content_type=project_ct,
160+
unread=True,
161+
action_object_content_type=note_ct,
162+
action_object_object_id=private_note.id,
163+
)
164+
165+
annotated_project = models.Project.objects.with_unread_notifications(
166+
user.id
167+
).first()
168+
assert annotated_project.action_notifications_count == 2
169+
assert annotated_project.conversation_notifications_count == 1
170+
assert annotated_project.private_conversation_notifications_count == 1
171+
assert annotated_project.document_notifications_count == 0
172+
173+
114174
# eof

0 commit comments

Comments
 (0)