-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): u#2899 notifications scaffolding + notify when a…
… story is [un]assigned
- Loading branch information
Showing
28 changed files
with
599 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from typing import Any | ||
|
||
from taiga.base.db import admin | ||
from taiga.base.db.admin.http import HttpRequest | ||
from taiga.notifications.models import Notification | ||
|
||
|
||
@admin.register(Notification) | ||
class NotificationAdmin(admin.ModelAdmin[Notification]): | ||
list_display = ("id", "type", "owner", "created_at", "read_at") | ||
|
||
def has_change_permission(self, request: HttpRequest, obj: Any = None) -> bool: | ||
return False | ||
|
||
def has_add_permission(self, request: HttpRequest, obj: Any = None) -> bool: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from taiga.base.api import AuthRequest | ||
from taiga.base.api.permissions import check_permissions | ||
from taiga.exceptions.api.errors import ERROR_403 | ||
from taiga.notifications import services as notifications_services | ||
from taiga.notifications.models import Notification | ||
from taiga.notifications.serializers import NotificationCountersSerializer, NotificationSerializer | ||
from taiga.permissions import IsAuthenticated | ||
from taiga.routers import routes | ||
|
||
LIST_MY_NOTIFICATIONS = IsAuthenticated() | ||
COUNT_MY_NOTIFICATIONS = IsAuthenticated() | ||
|
||
########################################################## | ||
# list notifications | ||
########################################################## | ||
|
||
|
||
@routes.notifications.get( | ||
"/my/notifications", | ||
name="my.notifications.list", | ||
summary="List all the user notifications", | ||
responses=ERROR_403, | ||
response_model=list[NotificationSerializer], | ||
) | ||
async def list_my_notifications(request: AuthRequest, is_read: bool | None = None) -> list[Notification]: | ||
""" | ||
List the notifications of the logged user. | ||
""" | ||
await check_permissions(permissions=LIST_MY_NOTIFICATIONS, user=request.user, obj=None) | ||
return await notifications_services.list_user_notifications(user=request.user, is_read=is_read) | ||
|
||
|
||
########################################################## | ||
# count notifications | ||
########################################################## | ||
|
||
|
||
@routes.notifications.get( | ||
"/my/notifications/count", | ||
name="my.notifications.count", | ||
summary="Get user notifications counters", | ||
responses=ERROR_403, | ||
response_model=NotificationCountersSerializer, | ||
) | ||
async def count_my_notifications(request: AuthRequest) -> dict[str, int]: | ||
""" | ||
List the notifications of the logged user. | ||
""" | ||
await check_permissions(permissions=COUNT_MY_NOTIFICATIONS, user=request.user, obj=None) | ||
return await notifications_services.count_user_notifications(user=request.user) |
25 changes: 25 additions & 0 deletions
25
python/apps/taiga/src/taiga/notifications/events/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from taiga.events import events_manager | ||
from taiga.notifications.events.content import CreateNotificationContent | ||
from taiga.notifications.models import Notification | ||
|
||
CREATE_NOTIFICATION = "notifications.create" | ||
|
||
|
||
async def emit_event_when_notifications_are_created( | ||
notifications: list[Notification], | ||
) -> None: | ||
for notification in notifications: | ||
await events_manager.publish_on_user_channel( | ||
user=notification.owner, | ||
type=CREATE_NOTIFICATION, | ||
content=CreateNotificationContent( | ||
notification=notification, | ||
), | ||
) |
13 changes: 13 additions & 0 deletions
13
python/apps/taiga/src/taiga/notifications/events/content.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from taiga.base.serializers import BaseModel | ||
from taiga.notifications.serializers import NotificationSerializer | ||
|
||
|
||
class CreateNotificationContent(BaseModel): | ||
notification: NotificationSerializer |
89 changes: 89 additions & 0 deletions
89
python/apps/taiga/src/taiga/notifications/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
# Generated by Django 4.2.3 on 2023-10-04 18:15 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
import django.db.models.deletion | ||
import taiga.base.db.models | ||
import taiga.base.utils.datetime | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Notification", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
blank=True, | ||
default=taiga.base.db.models.uuid_generator, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"created_at", | ||
models.DateTimeField( | ||
default=taiga.base.utils.datetime.aware_utcnow, | ||
verbose_name="created at", | ||
), | ||
), | ||
("type", models.CharField(max_length=500, verbose_name="type")), | ||
( | ||
"read_at", | ||
models.DateTimeField(blank=True, null=True, verbose_name="read at"), | ||
), | ||
( | ||
"content", | ||
django.contrib.postgres.fields.jsonb.JSONField(default=dict, verbose_name="content"), | ||
), | ||
( | ||
"created_by", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to=settings.AUTH_USER_MODEL, | ||
verbose_name="created by", | ||
), | ||
), | ||
( | ||
"owner", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="notifications", | ||
to=settings.AUTH_USER_MODEL, | ||
verbose_name="owner", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "notification", | ||
"verbose_name_plural": "notifications", | ||
"ordering": ["-created_at"], | ||
"indexes": [ | ||
models.Index(fields=["owner"], name="notificatio_owner_i_2bc47d_idx"), | ||
models.Index( | ||
fields=["owner", "read_at"], | ||
name="notificatio_owner_i_37308f_idx", | ||
), | ||
], | ||
}, | ||
), | ||
] |
6 changes: 6 additions & 0 deletions
6
python/apps/taiga/src/taiga/notifications/migrations/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC |
Oops, something went wrong.