summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-24 16:14:40 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-24 16:14:40 -0400
commit3a19c0a2d5e6229cd86201bf7370c8700b215297 (patch)
tree806020f03a34cbb616eb6a9cc029dca20d8430c1
parent142840d6eadd1257ea5517f2c51cffb2b64c819e (diff)
downloadaskbot-3a19c0a2d5e6229cd86201bf7370c8700b215297.tar.gz
askbot-3a19c0a2d5e6229cd86201bf7370c8700b215297.tar.bz2
askbot-3a19c0a2d5e6229cd86201bf7370c8700b215297.zip
fixed a missing notifications bug with enabled groups
-rw-r--r--askbot/models/__init__.py2
-rw-r--r--askbot/models/post.py42
-rw-r--r--askbot/models/question.py17
-rw-r--r--askbot/models/user.py7
-rw-r--r--askbot/tests/email_alert_tests.py24
5 files changed, 74 insertions, 18 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 6b571c92..d8f30503 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -1754,7 +1754,7 @@ def user_create_post_reject_reason(
added_at = timestamp,
text = details
)
- details.parse_and_save(author = self)
+ details.parse_and_save(author=self)
details.add_revision(
author = self,
revised_at = timestamp,
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 72b1b680..57847088 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -225,7 +225,18 @@ class PostManager(BaseQuerySetManager):
is_private = is_private or \
(thread and thread.requires_response_moderation(author))
- post.parse_and_save(author=author, is_private=is_private)
+ parse_results = post.parse_and_save(author=author, is_private=is_private)
+
+ from askbot.models import signals
+ signals.post_updated.send(
+ post=post,
+ updated_by=author,
+ newly_mentioned_users=parse_results['newly_mentioned_users'],
+ timestamp=added_at,
+ created=True,
+ diff=parse_results['diff'],
+ sender=post.__class__
+ )
post.add_revision(
author = author,
@@ -529,19 +540,6 @@ class Post(models.Model):
timestamp = self.get_time_of_last_edit()
- #todo: this is handled in signal because models for posts
- #are too spread out
- from askbot.models import signals
- signals.post_updated.send(
- post = self,
- updated_by = author,
- newly_mentioned_users = newly_mentioned_users,
- timestamp = timestamp,
- created = created,
- diff = diff,
- sender = self.__class__
- )
-
try:
from askbot.conf import settings as askbot_settings
if askbot_settings.GOOGLE_SITEMAP_CODE != '':
@@ -549,6 +547,8 @@ class Post(models.Model):
except Exception:
logging.debug('cannot ping google - did you register with them?')
+ return {'diff': diff, 'newly_mentioned_users': newly_mentioned_users}
+
def is_question(self):
return self.post_type == 'question'
@@ -1626,7 +1626,19 @@ class Post(models.Model):
by_email = by_email
)
- self.parse_and_save(author=edited_by, is_private=is_private)
+ parse_results = self.parse_and_save(author=edited_by, is_private=is_private)
+
+ from askbot.models import signals
+ signals.post_updated.send(
+ post=self,
+ updated_by=edited_by,
+ newly_mentioned_users=parse_results['newly_mentioned_users'],
+ timestamp=edited_at,
+ created=False,
+ diff=parse_results['diff'],
+ sender=self.__class__
+ )
+
def _answer__apply_edit(
self,
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 0b389bfa..6b233188 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -133,7 +133,8 @@ class ThreadManager(BaseQuerySetManager):
question.wikified_at = added_at
#this is kind of bad, but we save assign privacy groups to posts and thread
- question.parse_and_save(author = author, is_private = is_private)
+ #this call is rather heavy, we should split into several functions
+ parse_results = question.parse_and_save(author=author, is_private=is_private)
revision = question.add_revision(
author=author,
@@ -155,7 +156,19 @@ class ThreadManager(BaseQuerySetManager):
thread.make_public()
# INFO: Question has to be saved before update_tags() is called
- thread.update_tags(tagnames = tagnames, user = author, timestamp = added_at)
+ thread.update_tags(tagnames=tagnames, user=author, timestamp=added_at)
+
+ #todo: this is handled in signal because models for posts
+ #are too spread out
+ signals.post_updated.send(
+ post=question,
+ updated_by=author,
+ newly_mentioned_users=parse_results['newly_mentioned_users'],
+ timestamp=added_at,
+ created=True,
+ diff=parse_results['diff'],
+ sender=question.__class__
+ )
return thread
diff --git a/askbot/models/user.py b/askbot/models/user.py
index bdb94100..39bb8ea9 100644
--- a/askbot/models/user.py
+++ b/askbot/models/user.py
@@ -271,6 +271,13 @@ class EmailFeedSetting(models.Model):
'q_sel': 'n',
'm_and_c': 'n'
}
+ MAX_EMAIL_SCHEDULE = {
+ 'q_ask': 'i',
+ 'q_ans': 'i',
+ 'q_all': 'i',
+ 'q_sel': 'i',
+ 'm_and_c': 'i'
+ }
FEED_TYPE_CHOICES = (
('q_all',_('Entire forum')),
('q_ask',_('Questions that I asked')),
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index 1937da6f..f5b5e43b 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -10,6 +10,7 @@ from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from askbot.tests import utils
+from askbot.tests.utils import with_settings
from askbot import models
from askbot import mail
from askbot.conf import settings as askbot_settings
@@ -954,6 +955,29 @@ class EmailFeedSettingTests(utils.AskbotTestCase):
data_after = TO_JSON(self.get_user_feeds())
self.assertEquals(data_before, data_after)
+
+class EmailAlertTestsWithGroupsEnabled(utils.AskbotTestCase):
+
+ def setUp(self):
+ self.backup = askbot_settings.GROUPS_ENABLED
+ askbot_settings.update('GROUPS_ENABLED', True)
+
+ def tearDown(self):
+ askbot_settings.update('GROUPS_ENABLED', self.backup)
+
+ @with_settings({'MIN_REP_TO_TRIGGER_EMAIL': 1})
+ def test_notification_for_global_group_works(self):
+ sender = self.create_user('sender')
+ recipient = self.create_user(
+ 'recipient',
+ notification_schedule=models.EmailFeedSetting.MAX_EMAIL_SCHEDULE
+ )
+ self.post_question(user=sender)
+ outbox = django.core.mail.outbox
+ self.assertEqual(len(outbox), 1)
+ self.assertEqual(outbox[0].recipients(), [recipient.email])
+
+
class PostApprovalTests(utils.AskbotTestCase):
"""test notifications sent to authors when their posts
are approved or published"""