-
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#2900 notify when the status of a story has cha…
…nged
- Loading branch information
Showing
5 changed files
with
113 additions
and
27 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
35 changes: 35 additions & 0 deletions
35
python/apps/taiga/src/taiga/stories/stories/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,35 @@ | ||
# -*- 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.notifications import services as notifications_services | ||
from taiga.stories.stories.models import Story | ||
from taiga.stories.stories.notifications.content import StoryStatusChangeNotificationContent | ||
from taiga.users.models import User | ||
|
||
STORIES_STATUS_CHANGE = "stories.status_change" | ||
|
||
|
||
async def notify_when_story_status_change(story: Story, status: str, emitted_by: User) -> None: | ||
""" | ||
Emit notification when a story status changes | ||
""" | ||
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=STORIES_STATUS_CHANGE, | ||
emitted_by=emitted_by, | ||
notified_users=notified_users, | ||
content=StoryStatusChangeNotificationContent( | ||
projects=story.project, | ||
story=story, | ||
changed_by=emitted_by, | ||
status=status, | ||
), | ||
) |
21 changes: 21 additions & 0 deletions
21
python/apps/taiga/src/taiga/stories/stories/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,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 taiga.base.serializers import BaseModel | ||
from taiga.projects.projects.serializers.nested import ProjectLinkNestedSerializer | ||
from taiga.stories.stories.serializers.nested import StoryNestedSerializer | ||
from taiga.users.serializers.nested import UserNestedSerializer | ||
|
||
|
||
class StoryStatusChangeNotificationContent(BaseModel): | ||
projects: ProjectLinkNestedSerializer | ||
story: StoryNestedSerializer | ||
changed_by: UserNestedSerializer | ||
status: str | ||
|
||
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
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