Repository: readthedocs/readthedocs.org

Issue:
Notifications: ability to dismiss a notification
We are currently showing all the `read` and `unread` notifications, but we are not allowing users to dismiss them. So, we are always accumulating them.

We should recover the small `X` next to the notification to call the APIv3 and dismiss the notification.


Discussion:

Resolving patch:
diff --git a/readthedocs/api/v3/serializers.py b/readthedocs/api/v3/serializers.py
--- a/readthedocs/api/v3/serializers.py
+++ b/readthedocs/api/v3/serializers.py
@@ -66,50 +66,7 @@ class NotificationLinksSerializer(BaseLinksSerializer):
     _self = serializers.SerializerMethodField()
 
     def get__self(self, obj):
-        content_type_name = obj.attached_to_content_type.name
-        if content_type_name == "user":
-            url = "users-notifications-detail"
-            path = reverse(
-                url,
-                kwargs={
-                    "notification_pk": obj.pk,
-                    "parent_lookup_user__username": obj.attached_to.username,
-                },
-            )
-
-        elif content_type_name == "build":
-            url = "projects-builds-notifications-detail"
-            project_slug = obj.attached_to.project.slug
-            path = reverse(
-                url,
-                kwargs={
-                    "notification_pk": obj.pk,
-                    "parent_lookup_project__slug": project_slug,
-                    "parent_lookup_build__id": obj.attached_to_id,
-                },
-            )
-
-        elif content_type_name == "project":
-            url = "projects-notifications-detail"
-            project_slug = obj.attached_to.slug
-            path = reverse(
-                url,
-                kwargs={
-                    "notification_pk": obj.pk,
-                    "parent_lookup_project__slug": project_slug,
-                },
-            )
-
-        elif content_type_name == "organization":
-            url = "organizations-notifications-detail"
-            path = reverse(
-                url,
-                kwargs={
-                    "notification_pk": obj.pk,
-                    "parent_lookup_organization__slug": obj.attached_to.slug,
-                },
-            )
-
+        path = obj.get_absolute_url()
         return self._absolute_url(path)
 
 
diff --git a/readthedocs/notifications/models.py b/readthedocs/notifications/models.py
--- a/readthedocs/notifications/models.py
+++ b/readthedocs/notifications/models.py
@@ -4,10 +4,10 @@
 from django.contrib.contenttypes.fields import GenericForeignKey
 from django.contrib.contenttypes.models import ContentType
 from django.db import models
+from django.urls import reverse
 from django.utils.translation import gettext_noop as _
 from django_extensions.db.models import TimeStampedModel
 
-
 from .constants import CANCELLED, DISMISSED, READ, UNREAD, WARNING
 from .messages import Message, registry
 from .querysets import NotificationQuerySet
@@ -93,3 +93,49 @@ def get_message(self):
             )
 
         return message
+
+    def get_absolute_url(self):
+        content_type_name = self.attached_to_content_type.name
+        if content_type_name == "user":
+            url = "users-notifications-detail"
+            path = reverse(
+                url,
+                kwargs={
+                    "notification_pk": self.pk,
+                    "parent_lookup_user__username": self.attached_to.username,
+                },
+            )
+
+        elif content_type_name == "build":
+            url = "projects-builds-notifications-detail"
+            project_slug = self.attached_to.project.slug
+            path = reverse(
+                url,
+                kwargs={
+                    "notification_pk": self.pk,
+                    "parent_lookup_project__slug": project_slug,
+                    "parent_lookup_build__id": self.attached_to_id,
+                },
+            )
+
+        elif content_type_name == "project":
+            url = "projects-notifications-detail"
+            project_slug = self.attached_to.slug
+            path = reverse(
+                url,
+                kwargs={
+                    "notification_pk": self.pk,
+                    "parent_lookup_project__slug": project_slug,
+                },
+            )
+
+        elif content_type_name == "organization":
+            url = "organizations-notifications-detail"
+            path = reverse(
+                url,
+                kwargs={
+                    "notification_pk": self.pk,
+                    "parent_lookup_organization__slug": self.attached_to.slug,
+                },
+            )
+        return path


Test patch: