Exemplo n.º 1
0
    def handle_create(self, instance, **kwargs):
        if not (isinstance(instance.parent, ObjectPermissionsModel)
                and not instance.parent.require_auth):
            return

        activity = self.get_activity(instance)
        author = instance.created_by
        for feeds, recipients in self.get_feeds_and_recipients(instance):
            self.manager.add_activity(
                activity, [recipient.pk for recipient in recipients], feeds)
            if NotificationFeed in feeds:
                for recipient in recipients:
                    notification = CommentNotification(
                        user=recipient,
                        target=instance.content_object,
                        author=author,
                        text=instance.text)
                    notification.notify()

        if instance.parent and instance.parent.created_by != author:
            parent_author = instance.parent.created_by
            reply_activity = self.get_activity(instance, reply=True)
            self.manager.add_activity(reply_activity, [parent_author.pk],
                                      [NotificationFeed])
            reply_notification = CommentReplyNotification(
                user=parent_author,
                target=instance.content_object,
                author=author)
            reply_notification.notify()
Exemplo n.º 2
0
    def handle_create(self, comment):
        activity = self.get_activity(comment)
        author = comment.created_by
        for feeds, recipients in self.get_feeds_and_recipients(comment):
            self.manager.add_activity(
                activity, [recipient.pk for recipient in recipients], feeds)
            if NotificationFeed in feeds:
                for recipient in recipients:
                    notification = CommentNotification(
                        user=recipient,
                        target=comment.content_object,
                        author=author,
                        text=comment.text)
                    notification.notify()

        if comment.parent and comment.parent.created_by != author:
            parent_author = comment.parent.created_by
            reply_activity = self.get_activity(comment, reply=True)
            self.manager.add_activity(reply_activity, [parent_author.pk],
                                      [NotificationFeed])
            reply_notification = CommentReplyNotification(
                user=parent_author,
                target=comment.content_object,
                author=author)
            reply_notification.notify()
Exemplo n.º 3
0
 def setUp(self):
     self.author = User.objects.all().first()
     self.recipient = User.objects.all()[1]
     self.article = Article.objects.all().first()
     self.comment = Comment.objects.all().first()
     self.comment.created_by = self.author
     self.comment.object_id = self.article.pk
     self.comment.save()
     self.notifier = CommentReplyNotification(
         user=self.recipient,
         author=self.author,
         text=self.comment.text,
         target=self.article,
     )
Exemplo n.º 4
0
class CommentReplyNotificationTestCase(BaseTestCase):
    fixtures = [
        "test_abakus_groups.yaml",
        "test_comments.yaml",
        "test_users.yaml",
        "test_articles.yaml",
        "initial_files.yaml",
    ]

    def setUp(self):
        self.author = User.objects.all().first()
        self.recipient = User.objects.all()[1]
        self.article = Article.objects.all().first()
        self.comment = Comment.objects.all().first()
        self.comment.created_by = self.author
        self.comment.object_id = self.article.pk
        self.comment.save()
        self.notifier = CommentReplyNotification(
            user=self.recipient,
            author=self.author,
            text=self.comment.text,
            target=self.article,
        )

    def assertEmailContains(self, send_mail_mock, content):
        self.notifier.generate_mail()
        email_args = send_mail_mock.call_args[1]
        self.assertIn(content, email_args["message"])
        self.assertIn(content, email_args["html_message"])

    def test_generate_email_comment(self, send_mail_mock):
        comment = self.comment.text
        self.assertEmailContains(send_mail_mock, comment)

    def test_generate_email_content(self, send_mail_mock):
        content = (self.author.first_name + " " + self.author.last_name +
                   " har svart på din kommentar på " + self.article.title +
                   ":")
        self.assertEmailContains(send_mail_mock, content)

    def test_generate_email_name(self, send_mail_mock):
        opening = ("Hei, " + self.recipient.first_name + " " +
                   self.recipient.last_name + "!")
        self.assertEmailContains(send_mail_mock, opening)

    def test_generate_email_url(self, send_mail_mock):
        url = self.article.get_absolute_url()
        self.assertEmailContains(send_mail_mock, url)