Merge pull request #461 from taigaio/issue-2991-when-a-new-comment-is-added-the-update-of-watchers-list-applies-in-the-next-future-change

Issue 2991 - When a new comment is added the update of watchers list …
remotes/origin/logger
David Barragán Merino 2015-09-15 17:11:50 +02:00
commit faf7621a0b
4 changed files with 19 additions and 9 deletions

View File

@ -17,7 +17,7 @@
import warnings import warnings
from .services import take_snapshot from .services import take_snapshot
from taiga.projects.notifications import services as notifications_services
class HistoryResourceMixin(object): class HistoryResourceMixin(object):
""" """
@ -63,6 +63,8 @@ class HistoryResourceMixin(object):
if sobj != obj and delete: if sobj != obj and delete:
delete = False delete = False
notifications_services.analize_object_for_watchers(obj, comment, user)
self.__last_history = take_snapshot(sobj, comment=comment, user=user, delete=delete) self.__last_history = take_snapshot(sobj, comment=comment, user=user, delete=delete)
self.__object_saved = True self.__object_saved = True

View File

@ -91,7 +91,7 @@ class WatchedResourceMixin:
# some text fields for extract mentions and add them # some text fields for extract mentions and add them
# to watchers before obtain a complete list of # to watchers before obtain a complete list of
# notifiable users. # 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 # Get a complete list of notifiable users for current
# object and send the change notification to them. # object and send the change notification to them.

View File

@ -90,16 +90,23 @@ def get_notify_policy(project, user):
return instance 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 Generic implementation for analize model objects and
extract mentions from it and add it to watchers. 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 from taiga import mdrender as mdr
texts = (getattr(obj, "description", ""), texts = (getattr(obj, "description", ""),
getattr(obj, "content", ""), getattr(obj, "content", ""),
getattr(history, "comment", ""),) comment,)
_, data = mdr.render_and_extract(obj.get_project(), "\n".join(texts)) _, 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) obj.add_watcher(user)
# Adding the person who edited the object to the watchers # Adding the person who edited the object to the watchers
if history.comment and not history.owner.is_system: if comment and not user.is_system:
obj.add_watcher(history.owner) obj.add_watcher(user)
def _filter_by_permissions(obj, user): def _filter_by_permissions(obj, user):
UserStory = apps.get_model("userstories", "UserStory") UserStory = apps.get_model("userstories", "UserStory")

View File

@ -104,7 +104,7 @@ def test_analize_object_for_watchers():
history = MagicMock() history = MagicMock()
history.comment = "" 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 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.comment = "Comment"
history.owner = user1 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 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.comment = ""
history.owner = user1 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 assert issue.add_watcher.call_count == 0