Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): u#3985 notify when a story has changed workflow (and status) #550

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from taiga.stories.stories.notifications.content import (
StoryDeleteNotificationContent,
StoryStatusChangeNotificationContent,
StoryWorkflowChangeNotificationContent,
)
from taiga.users.models import User

STORIES_STATUS_CHANGE = "stories.status_change"
STORIES_WORKFLOW_CHANGE = "stories.workflow_change"
STORIES_DELETE = "stories.delete"


Expand All @@ -39,6 +41,29 @@ async def notify_when_story_status_change(story: Story, status: str, emitted_by:
)


async def notify_when_story_workflow_change(story: Story, workflow: str, status: str, emitted_by: User) -> None:
"""
Emit notification when a story workflow changes
"""
notified_users = {u async for u in story.assignees.all()}
daniel-herrero marked this conversation as resolved.
Show resolved Hide resolved
if story.created_by:
notified_users.add(story.created_by)
notified_users.discard(emitted_by)

await notifications_services.notify_users(
type=STORIES_WORKFLOW_CHANGE,
emitted_by=emitted_by,
notified_users=notified_users,
content=StoryWorkflowChangeNotificationContent(
project=story.project,
story=story,
changed_by=emitted_by,
workflow=workflow,
status=status,
),
)


async def notify_when_story_is_deleted(story: Story, emitted_by: User) -> None:
"""
Emit notification when a story is deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ class StoryStatusChangeNotificationContent(BaseModel):

class Config:
orm_mode = True


class StoryWorkflowChangeNotificationContent(BaseModel):
project: ProjectLinkNestedSerializer
story: StoryNestedSerializer
changed_by: UserNestedSerializer
status: str
workflow: str

class Config:
orm_mode = True
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ async def update_story(
)

# Emit notifications
if "status" in update_values:
if "workflow" in update_values:
await stories_notifications.notify_when_story_workflow_change(
story=story,
workflow=update_values["workflow"].name,
status=update_values["status"].name,
emitted_by=updated_by,
)
elif "status" in update_values:
await stories_notifications.notify_when_story_status_change(
story=story,
status=update_values["status"].name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async def test_update_story_ok():
updates_attrs=[*values],
)
fake_notifications.notify_when_story_status_change.assert_not_awaited()
fake_notifications.notify_when_story_workflow_change.assert_not_awaited()

assert updated_story == detailed_story

Expand Down Expand Up @@ -324,7 +325,8 @@ async def test_update_story_workflow_ok():
updates_attrs=[*values],
)

fake_notifications.notify_when_story_status_change.assert_awaited_once()
fake_notifications.notify_when_story_status_change.assert_not_awaited()
fake_notifications.notify_when_story_workflow_change.assert_awaited_once()


async def test_update_story_error_wrong_version():
Expand Down Expand Up @@ -365,6 +367,7 @@ async def test_update_story_error_wrong_version():
fake_get_story_detail.assert_not_awaited()
fake_stories_events.emit_event_when_story_is_updated.assert_not_awaited()
fake_notifications.notify_when_story_status_change.assert_not_awaited()
fake_notifications.notify_when_story_workflow_change.assert_not_awaited()


#######################################################
Expand Down
Loading