diff --git a/taiga/projects/history/mixins.py b/taiga/projects/history/mixins.py index 9e379f77..45a7c97e 100644 --- a/taiga/projects/history/mixins.py +++ b/taiga/projects/history/mixins.py @@ -17,7 +17,7 @@ import warnings from .services import take_snapshot - +from taiga.projects.notifications import services as notifications_services class HistoryResourceMixin(object): """ @@ -63,6 +63,8 @@ class HistoryResourceMixin(object): if sobj != obj and delete: delete = False + notifications_services.analize_object_for_watchers(obj, comment, user) + self.__last_history = take_snapshot(sobj, comment=comment, user=user, delete=delete) self.__object_saved = True diff --git a/taiga/projects/notifications/mixins.py b/taiga/projects/notifications/mixins.py index bf42a9ed..ee41fd55 100644 --- a/taiga/projects/notifications/mixins.py +++ b/taiga/projects/notifications/mixins.py @@ -91,7 +91,7 @@ class WatchedResourceMixin: # some text fields for extract mentions and add them # to watchers before obtain a complete list of # notifiable users. - services.analize_object_for_watchers(obj, history) + services.analize_object_for_watchers(obj, history.comment, history.owner) # Get a complete list of notifiable users for current # object and send the change notification to them. diff --git a/taiga/projects/notifications/services.py b/taiga/projects/notifications/services.py index 5d191d32..1cc99dc6 100644 --- a/taiga/projects/notifications/services.py +++ b/taiga/projects/notifications/services.py @@ -90,16 +90,23 @@ def get_notify_policy(project, user): return instance -def analize_object_for_watchers(obj:object, history:object): +def analize_object_for_watchers(obj:object, comment:str, user:object): """ Generic implementation for analize model objects and extract mentions from it and add it to watchers. """ + + if not hasattr(obj, "get_project"): + return + + if not hasattr(obj, "add_watcher"): + return + from taiga import mdrender as mdr texts = (getattr(obj, "description", ""), getattr(obj, "content", ""), - getattr(history, "comment", ""),) + comment,) _, data = mdr.render_and_extract(obj.get_project(), "\n".join(texts)) @@ -108,8 +115,9 @@ def analize_object_for_watchers(obj:object, history:object): obj.add_watcher(user) # Adding the person who edited the object to the watchers - if history.comment and not history.owner.is_system: - obj.add_watcher(history.owner) + if comment and not user.is_system: + obj.add_watcher(user) + def _filter_by_permissions(obj, user): UserStory = apps.get_model("userstories", "UserStory") diff --git a/tests/integration/test_notifications.py b/tests/integration/test_notifications.py index 4442ad92..d183a9ef 100644 --- a/tests/integration/test_notifications.py +++ b/tests/integration/test_notifications.py @@ -104,7 +104,7 @@ def test_analize_object_for_watchers(): history = MagicMock() history.comment = "" - services.analize_object_for_watchers(issue, history) + services.analize_object_for_watchers(issue, history.comment, history.owner) assert issue.add_watcher.call_count == 2 @@ -119,7 +119,7 @@ def test_analize_object_for_watchers_adding_owner_non_empty_comment(): history.comment = "Comment" history.owner = user1 - services.analize_object_for_watchers(issue, history) + services.analize_object_for_watchers(issue, history.comment, history.owner) assert issue.add_watcher.call_count == 1 @@ -134,7 +134,7 @@ def test_analize_object_for_watchers_no_adding_owner_empty_comment(): history.comment = "" history.owner = user1 - services.analize_object_for_watchers(issue, history) + services.analize_object_for_watchers(issue, history.comment, history.owner) assert issue.add_watcher.call_count == 0