Issue 2991 - When a new comment is added the update of watchers list applies in the next future change
parent
445d20092e
commit
fd2037f456
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue