def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=comment.content, target_user=target.user if is_reply(target) else None, parent_comment=target.content if is_reply(target) else "", url=node.absolute_url ) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify( event="comments", user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.user and target.user not in sent_subscribers: notify( event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context )
def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=comment.content, page_type='file' if comment.page == Comment.FILES else node.project_or_component, page_title=comment.root_target.name if comment.page == Comment.FILES else '', provider=PROVIDERS[comment.root_target.provider] if comment.page == Comment.FILES else '', target_user=target.user if is_reply(target) else None, parent_comment=target.content if is_reply(target) else "", url=comment.get_comment_page_url() ) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify( event="comments", user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.user and target.user not in sent_subscribers: notify( event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context )
def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=markdown.markdown(comment.content, [ 'del_ins', 'markdown.extensions.tables', 'markdown.extensions.fenced_code' ]), page_type='file' if comment.page == Comment.FILES else node.project_or_component, page_title=comment.root_target.referent.name if comment.page == Comment.FILES else '', provider=PROVIDERS[comment.root_target.referent.provider] if comment.page == Comment.FILES else '', target_user=target.referent.user if is_reply(target) else None, parent_comment=target.referent.content if is_reply(target) else "", url=comment.get_comment_page_url()) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify(event="comments", user=auth.user, node=node, timestamp=time_now, **context) if is_reply(target): if target.referent.user and target.referent.user not in sent_subscribers: notify(event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context)
def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=markdown.markdown(comment.content, ['del_ins', 'markdown.extensions.tables', 'markdown.extensions.fenced_code']), page_type=comment.get_comment_page_type(), page_title=comment.get_comment_page_title(), provider=PROVIDERS[comment.root_target.referent.provider] if comment.page == Comment.FILES else '', target_user=target.referent.user if is_reply(target) else None, parent_comment=target.referent.content if is_reply(target) else '', url=comment.get_comment_page_url() ) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify( event='comments', user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.referent.user and target.referent.user not in sent_subscribers: notify( event='global_comment_replies', user=auth.user, node=node, timestamp=time_now, **context )
def send_comment_added_notification(comment, auth, new_mentions=None): if not new_mentions: new_mentions = [] node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=render_email_markdown(comment.content), page_type=comment.get_comment_page_type(), page_title=comment.get_comment_page_title(), provider=PROVIDERS[comment.root_target.referent.provider] if comment.page == Comment.FILES else '', target_user=target.referent.user if is_reply(target) else None, parent_comment=target.referent.content if is_reply(target) else '', url=comment.get_comment_page_url(), exclude=new_mentions, ) time_now = timezone.now() sent_subscribers = notify( event='comments', user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.referent.user and target.referent.user._id not in sent_subscribers: notify( event='global_comment_replies', user=auth.user, node=node, timestamp=time_now, **context )
def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict( gravatar_url=auth.user.profile_image_url(), content=render_email_markdown(comment.content), page_type=comment.get_comment_page_type(), page_title=comment.get_comment_page_title(), provider=PROVIDERS[comment.root_target.referent.provider] if comment.page == Comment.FILES else '', target_user=target.referent.user if is_reply(target) else None, parent_comment=target.referent.content if is_reply(target) else '', url=comment.get_comment_page_url()) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify(event='comments', user=auth.user, node=node, timestamp=time_now, **context) if is_reply(target): if target.referent.user and target.referent.user not in sent_subscribers: notify(event='global_comment_replies', user=auth.user, node=node, timestamp=time_now, **context)
def add_comment(auth, node, **kwargs): if not node.comment_level: raise HTTPError(http.BAD_REQUEST) if not node.can_comment(auth): raise HTTPError(http.FORBIDDEN) guid = request.json.get('target') target = resolve_target(node, guid) content = request.json.get('content').strip() content = sanitize(content) if not content: raise HTTPError(http.BAD_REQUEST) if len(content) > settings.COMMENT_MAXLENGTH: raise HTTPError(http.BAD_REQUEST) comment = Comment.create( auth=auth, node=node, target=target, user=auth.user, content=content, ) comment.save() context = dict( gravatar_url=auth.user.gravatar_url, content=content, target_user=target.user if is_reply(target) else None, parent_comment=target.content if is_reply(target) else "", url=node.absolute_url ) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify( uid=node._id, event="comments", user=auth.user, node=node, timestamp=time_now, **context ) if is_reply(target): if target.user and target.user not in sent_subscribers: notify( uid=target.user._id, event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context ) return { 'comment': serialize_comment(comment, auth) }, http.CREATED
def perform(self): """Call emails.notify to notify users of an action""" emails.notify(event=self.event_type, user=self.user, node=self.node, timestamp=self.timestamp, message=self.html_message, gravatar_url=self.gravatar_url, url=self.url)
def test_notify_no_subscribers(self, send): node = factories.NodeFactory() node_subscription = factories.NotificationSubscriptionFactory( _id=node._id + '_comments', owner=node, event_name='comments' ) node_subscription.save() emails.notify(node._id, 'comments') assert_false(send.called)
def perform(self): """Call emails.notify to notify users of an action""" emails.notify( event=self.event_type, user=self.user, node=self.node, timestamp=self.timestamp, message=self.html_message, profile_image_url=self.profile_image_url, url=self.url )
def test_notify_does_not_send_to_users_subscribed_to_none(self, send): node = factories.NodeFactory() user = factories.UserFactory() node_subscription = factories.NotificationSubscriptionFactory( _id=node._id + '_comments', owner=node, event_name='comments' ) node_subscription.save() node_subscription.none.append(user) node_subscription.save() emails.notify(node._id, 'comments') assert_false(send.called)
def send_comment_added_notification(comment, auth): node = comment.node target = comment.target context = dict(gravatar_url=auth.user.profile_image_url(), content=comment.content, target_user=target.user if is_reply(target) else None, parent_comment=target.content if is_reply(target) else "", url=node.absolute_url) time_now = datetime.utcnow().replace(tzinfo=pytz.utc) sent_subscribers = notify(event="comments", user=auth.user, node=node, timestamp=time_now, **context) if is_reply(target): if target.user and target.user not in sent_subscribers: notify(event='comment_replies', user=auth.user, node=node, timestamp=time_now, **context)
def test_notify_sends_comment_reply_event_if_comment_is_reply(self, mock_send): user = factories.UserFactory() sent_subscribers = emails.notify(self.project._id, 'comments', target_user=user) mock_send.assert_called_with([self.project.creator._id], 'email_transactional', self.project._id, 'comment_replies', target_user=user)
def test_notify_sends_with_correct_args(self, send): subscribed_users = getattr(self.project_subscription, 'email_transactional') emails.notify(self.project._id, 'comments') assert_true(send.called) send.assert_called_with(subscribed_users, 'email_transactional', self.project._id, 'comments')
def test_notify_no_subscription(self, send): node = factories.NodeFactory() emails.notify(node._id, 'comments') assert_false(send.called)