-
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#4007 notify when a new comment has been created
- Loading branch information
Showing
11 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
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,16 @@ | ||
# -*- 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 Awaitable, Protocol | ||
|
||
from taiga.comments.models import Comment | ||
from taiga.users.models import User | ||
|
||
|
||
class NotificationOnCreateCallable(Protocol): | ||
def __call__(self, comment: Comment, emitted_by: User) -> Awaitable[None]: | ||
... |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
python/apps/taiga/src/taiga/comments/serializers/nested.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,21 @@ | ||
# -*- 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 datetime import datetime | ||
|
||
from taiga.base.serializers import UUIDB64, BaseModel | ||
from taiga.users.serializers.nested import UserNestedSerializer | ||
|
||
|
||
class CommentNestedSerializer(BaseModel): | ||
id: UUIDB64 | ||
text: str | ||
created_at: datetime | ||
created_by: UserNestedSerializer | None | ||
|
||
class Config: | ||
orm_mode = True |
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
30 changes: 30 additions & 0 deletions
30
python/apps/taiga/src/taiga/notifications/migrations/0002_alter_notification_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,30 @@ | ||
# -*- 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-23 11:16 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
import taiga.base.utils.json | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notifications", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="notification", | ||
name="content", | ||
field=django.contrib.postgres.fields.jsonb.JSONField( | ||
default=dict, | ||
encoder=taiga.base.utils.json.JSONEncoder, | ||
verbose_name="content", | ||
), | ||
), | ||
] |
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
33 changes: 33 additions & 0 deletions
33
python/apps/taiga/src/taiga/stories/comments/notifications/__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,33 @@ | ||
# -*- 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.comments.models import Comment | ||
from taiga.notifications import services as notifications_services | ||
from taiga.stories.comments.notifications.content import StoryCommentCreateNotificationContent | ||
from taiga.stories.stories.models import Story | ||
from taiga.users.models import User | ||
|
||
STORY_COMMENT_CREATE = "story_comment.create" | ||
|
||
|
||
async def notify_when_story_comment_is_created(story: Story, comment: Comment, emitted_by: User) -> None: | ||
notified_users = {u async for u in story.assignees.all()} | ||
if story.created_by: | ||
notified_users.add(story.created_by) | ||
notified_users.discard(emitted_by) | ||
|
||
await notifications_services.notify_users( | ||
type=STORY_COMMENT_CREATE, | ||
emitted_by=emitted_by, | ||
notified_users=notified_users, | ||
content=StoryCommentCreateNotificationContent( | ||
project=story.project, | ||
story=story, | ||
commented_by=emitted_by, | ||
comment=comment, | ||
), | ||
) |
19 changes: 19 additions & 0 deletions
19
python/apps/taiga/src/taiga/stories/comments/notifications/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,19 @@ | ||
# -*- 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.comments.serializers.nested import CommentNestedSerializer | ||
from taiga.projects.projects.serializers.nested import ProjectLinkNestedSerializer | ||
from taiga.stories.stories.serializers.nested import StoryNestedSerializer | ||
from taiga.users.serializers.nested import UserNestedSerializer | ||
|
||
|
||
class StoryCommentCreateNotificationContent(BaseModel): | ||
project: ProjectLinkNestedSerializer | ||
story: StoryNestedSerializer | ||
commented_by: UserNestedSerializer | ||
comment: CommentNestedSerializer |
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