summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-12-06 09:17:10 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-12-06 09:17:10 -0600
commit11a8154f88c7cd0d2dcc589ceaf6b734d442414e (patch)
tree18ef761abc6782a14d2cf040cf900614567f4952
parent0979c1881dbbbbe01f88b3841bdd5546e6848443 (diff)
parent2011383985288497db3322a2d05c8aa6f8f5e8d6 (diff)
downloadaskbot-11a8154f88c7cd0d2dcc589ceaf6b734d442414e.tar.gz
askbot-11a8154f88c7cd0d2dcc589ceaf6b734d442414e.tar.bz2
askbot-11a8154f88c7cd0d2dcc589ceaf6b734d442414e.zip
Merge branch 'master' of github.com:ASKBOT/askbot-devel
-rw-r--r--askbot/conf/__init__.py10
-rw-r--r--askbot/const/__init__.py16
-rw-r--r--askbot/forms.py2
-rw-r--r--askbot/media/style/style.less1
-rw-r--r--askbot/models/__init__.py4
-rw-r--r--askbot/models/post.py21
-rw-r--r--askbot/templates/meta/bottom_scripts.html2
-rw-r--r--askbot/tests/email_alert_tests.py47
-rw-r--r--askbot/tests/page_load_tests.py68
-rw-r--r--askbot/views/commands.py14
-rw-r--r--askbot/views/readers.py2
-rw-r--r--askbot/views/users.py6
12 files changed, 170 insertions, 23 deletions
diff --git a/askbot/conf/__init__.py b/askbot/conf/__init__.py
index 3e80877c..fd62bc88 100644
--- a/askbot/conf/__init__.py
+++ b/askbot/conf/__init__.py
@@ -1,4 +1,5 @@
#import these to compile code and install values
+from askbot import const
import askbot
import askbot.conf.minimum_reputation
import askbot.conf.vote_rules
@@ -38,9 +39,16 @@ def should_show_sort_by_relevance():
return ('postgresql_psycopg2' in askbot.get_database_engine_name())
def get_tag_display_filter_strategy_choices():
- from askbot import const
from askbot.conf import settings as askbot_settings
if askbot_settings.SUBSCRIBED_TAG_SELECTOR_ENABLED:
return const.TAG_DISPLAY_FILTER_STRATEGY_CHOICES
else:
return const.TAG_DISPLAY_FILTER_STRATEGY_MINIMAL_CHOICES
+
+def get_tag_email_filter_strategy_choices():
+ """returns the set of choices appropriate for the configuration"""
+ from askbot.conf import settings as askbot_settings
+ if askbot_settings.SUBSCRIBED_TAG_SELECTOR_ENABLED:
+ return const.TAG_EMAIL_FILTER_ADVANCED_STRATEGY_CHOICES
+ else:
+ return const.TAG_EMAIL_FILTER_SIMPLE_STRATEGY_CHOICES
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index 977cf0c5..9ec48b87 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -316,11 +316,23 @@ TAG_DISPLAY_FILTER_STRATEGY_CHOICES = \
TAG_DISPLAY_FILTER_STRATEGY_MINIMAL_CHOICES + \
((INCLUDE_SUBSCRIBED, _('only subscribed tags')),)
+TAG_EMAIL_FILTER_SIMPLE_STRATEGY_CHOICES = (
+ (INCLUDE_ALL, _('email for all tags')),
+ (EXCLUDE_IGNORED, _('exclude ignored tags')),
+ (INCLUDE_INTERESTING, _('only interesting tags')),
+)
+
+TAG_EMAIL_FILTER_ADVANCED_STRATEGY_CHOICES = (
+ (INCLUDE_ALL, _('email for all tags')),
+ (EXCLUDE_IGNORED, _('exclude ignored tags')),
+ (INCLUDE_SUBSCRIBED, _('only subscribed tags')),
+)
-TAG_EMAIL_FILTER_STRATEGY_CHOICES = (
+TAG_EMAIL_FILTER_FULL_STRATEGY_CHOICES = (
(INCLUDE_ALL, _('email for all tags')),
(EXCLUDE_IGNORED, _('exclude ignored tags')),
- (INCLUDE_INTERESTING, _('only subscribed tags')),
+ (INCLUDE_INTERESTING, _('only interesting tags')),
+ (INCLUDE_SUBSCRIBED, _('only subscribed tags')),
)
NOTIFICATION_DELIVERY_SCHEDULE_CHOICES = (
diff --git a/askbot/forms.py b/askbot/forms.py
index 50f17580..ba52a891 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -1330,7 +1330,7 @@ class EditTagWikiForm(forms.Form):
class EditUserForm(forms.Form):
email = forms.EmailField(
label=u'Email',
- required=True,
+ required=False,
max_length=255,
widget=forms.TextInput(attrs={'size': 35})
)
diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less
index 69f4daf7..2ad46f23 100644
--- a/askbot/media/style/style.less
+++ b/askbot/media/style/style.less
@@ -1879,6 +1879,7 @@ ul#related-tags li {
margin-top:10px;
font-family:@body-font;
color:#4b4b4b;
+ word-wrap: break-word;
p{
margin-bottom:14px;
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index ae295813..63259c53 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -212,14 +212,14 @@ User.add_to_class('show_marked_tags', models.BooleanField(default = True))
User.add_to_class(
'email_tag_filter_strategy',
models.SmallIntegerField(
- choices=const.TAG_DISPLAY_FILTER_STRATEGY_CHOICES,
+ choices=const.TAG_EMAIL_FILTER_FULL_STRATEGY_CHOICES,
default=const.EXCLUDE_IGNORED
)
)
User.add_to_class(
'display_tag_filter_strategy',
models.SmallIntegerField(
- choices=const.TAG_EMAIL_FILTER_STRATEGY_CHOICES,
+ choices=const.TAG_DISPLAY_FILTER_STRATEGY_CHOICES,
default=const.INCLUDE_ALL
)
)
diff --git a/askbot/models/post.py b/askbot/models/post.py
index bde6acaf..deb7726b 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -972,6 +972,9 @@ class Post(models.Model):
elif tag_mark_reason == 'bad':
email_tag_filter_strategy = const.EXCLUDE_IGNORED
user_set_getter = User.objects.exclude
+ elif tag_mark_reason == 'subscribed':
+ email_tag_filter_strategy = const.INCLUDE_SUBSCRIBED
+ user_set_getter = User.objects.filter
else:
raise ValueError('Uknown value of tag mark reason %s' % tag_mark_reason)
@@ -1005,6 +1008,10 @@ class Post(models.Model):
empty_wildcard_filter = {'ignored_tags__exact': ''}
wildcard_tags_attribute = 'ignored_tags'
update_subscribers = lambda the_set, item: the_set.discard(item)
+ elif tag_mark_reason == 'subscribed':
+ empty_wildcard_filter = {'subscribed_tags__exact': ''}
+ wildcard_tags_attribute = 'subscribed_tags'
+ update_subscribers = lambda the_set, item: the_set.add(item)
potential_wildcard_subscribers = User.objects.filter(
notification_subscriptions__in = subscription_records
@@ -1043,15 +1050,23 @@ class Post(models.Model):
#segment of users who have tag filter turned off
global_subscribers = User.objects.filter(
- email_tag_filter_strategy = const.INCLUDE_ALL
+ models.Q(email_tag_filter_strategy=const.INCLUDE_ALL)
+ & models.Q(
+ notification_subscriptions__feed_type='q_all',
+ notification_subscriptions__frequency='i'
+ )
)
subscriber_set.update(global_subscribers)
#segment of users who want emails on selected questions only
+ if askbot_settings.SUBSCRIBED_TAG_SELECTOR_ENABLED:
+ good_mark_reason = 'subscribed'
+ else:
+ good_mark_reason = 'good'
subscriber_set.update(
self.get_global_tag_based_subscribers(
subscription_records = global_subscriptions,
- tag_mark_reason = 'good'
+ tag_mark_reason = good_mark_reason
)
)
@@ -1256,7 +1271,7 @@ class Post(models.Model):
return self.filter_authorized_users(subscribers)
def get_notify_sets(self, mentioned_users=None, exclude_list=None):
- """returns three lists in a dictionary with keys:
+ """returns three lists of users in a dictionary with keys:
* 'for_inbox' - users for which to add inbox items
* 'for_mentions' - for whom mentions are added
* 'for_email' - to whom email notifications should be sent
diff --git a/askbot/templates/meta/bottom_scripts.html b/askbot/templates/meta/bottom_scripts.html
index b3fcd815..9b754caa 100644
--- a/askbot/templates/meta/bottom_scripts.html
+++ b/askbot/templates/meta/bottom_scripts.html
@@ -32,7 +32,7 @@
{% if settings.DEBUG %}
src="{{"/js/jquery-1.7.2.min.js"|media}}"
{% else %}
- src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
+ src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
{% endif %}
></script>
<script type="text/javascript" src='{{"/bootstrap/js/bootstrap.js"|media}}'></script>
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index bdb361e5..d11890a8 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -576,6 +576,16 @@ class InstantWholeForumEmailAlertTests(EmailAlertTests):
self.expected_results['q_ans'] = {'message_count': 1, }
self.expected_results['q_ans_new_answer'] = {'message_count': 2, }
+ def test_global_subscriber_with_zero_frequency_gets_no_email(self):
+ user = self.target_user
+ user.notification_subscriptions.update(frequency='n')
+ user.email_tag_filter_strategy = const.INCLUDE_ALL
+ user.save()
+ self.post_question(author=self.other_user)
+ outbox = django.core.mail.outbox
+ self.assertEqual(len(outbox), 0)
+
+
class BlankWeeklySelectedQuestionsEmailAlertTests(EmailAlertTests):
"""blank means that this is testing for the absence of email
because questions are not followed as set by default in the
@@ -739,12 +749,12 @@ class FeedbackTests(utils.AskbotTestCase):
class TagFollowedInstantWholeForumEmailAlertTests(utils.AskbotTestCase):
def setUp(self):
- self.create_user(
+ self.user1 = self.create_user(
username = 'user1',
notification_schedule = {'q_all': 'i'},
status = 'm'
)
- self.create_user(
+ self.user2 = self.create_user(
username = 'user2',
status = 'm'
)
@@ -773,7 +783,8 @@ class TagFollowedInstantWholeForumEmailAlertTests(utils.AskbotTestCase):
self.user1.email in outbox[0].recipients()
)
- def test_tag_based_subscription_on_new_question_works(self):
+ @with_settings(SUBSCRIBED_TAG_SELECTOR_ENABLED=False)
+ def test_tag_based_subscription_on_new_question_works1(self):
"""someone subscribes for an pre-existing tag
then another user asks a question with that tag
and the subcriber receives an alert
@@ -802,6 +813,36 @@ class TagFollowedInstantWholeForumEmailAlertTests(utils.AskbotTestCase):
self.user1.email in outbox[0].recipients()
)
+ @with_settings(SUBSCRIBED_TAG_SELECTOR_ENABLED=True)
+ def test_tag_based_subscription_on_new_question_works1(self):
+ """someone subscribes for an pre-existing tag
+ then another user asks a question with that tag
+ and the subcriber receives an alert
+ """
+ models.Tag(
+ name = 'something',
+ created_by = self.user1
+ ).save()
+
+ self.user1.email_tag_filter_strategy = const.INCLUDE_SUBSCRIBED
+ self.user1.save()
+ self.user1.mark_tags(
+ tagnames = ('something',),
+ reason = 'subscribed',
+ action = 'add'
+ )
+ self.user2.post_question(
+ title = 'some title',
+ body_text = 'some text for the question',
+ tags = 'something'
+ )
+ outbox = django.core.mail.outbox
+ self.assertEqual(len(outbox), 1)
+ self.assertEqual(len(outbox[0].recipients()), 1)
+ self.assertTrue(
+ self.user1.email in outbox[0].recipients()
+ )
+
class EmailReminderTestCase(utils.AskbotTestCase):
#subclass must define these (example below)
#enable_setting_name = 'ENABLE_UNANSWERED_REMINDERS'
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index 6c820fef..1e5ce903 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -720,3 +720,71 @@ class CommandViewTests(AskbotTestCase):
def test_load_object_description_fails(self):
response = self.client.get(reverse('load_object_description'))
self.assertEqual(response.status_code, 404)#bad request
+
+ def test_set_tag_filter_strategy(self):
+ user = self.create_user('someuser')
+
+ def run_test_for_setting(self, filter_type, value):
+ response = self.client.post(
+ reverse('set_tag_filter_strategy'),
+ data={
+ 'filter_type': filter_type,
+ 'filter_value': value
+ },
+ HTTP_X_REQUESTED_WITH='XMLHttpRequest'
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.content, '')
+
+ self.client.login(user_id=user.id, method='force')
+
+ from askbot import conf
+ values = dict(conf.get_tag_email_filter_strategy_choices()).keys()
+ for value in values:
+ run_test_for_setting(self, 'email', value)
+ user = self.reload_object(user)
+ self.assertEqual(user.email_tag_filter_strategy, value)
+
+ values = dict(conf.get_tag_display_filter_strategy_choices()).keys()
+ for value in values:
+ run_test_for_setting(self, 'display', value)
+ user = self.reload_object(user)
+ self.assertEqual(user.display_tag_filter_strategy, value)
+
+
+class UserProfilePageTests(AskbotTestCase):
+ def setUp(self):
+ self.user = self.create_user('user')
+
+ @with_settings(EDITABLE_EMAIL=False)
+ def test_user_cannot_change_email(self):
+ #log in
+ self.client.login(user_id=self.user.id, method='force')
+ email_before = self.user.email
+ response = self.client.post(
+ reverse('edit_user', kwargs={'id': self.user.id}),
+ data={
+ 'username': 'edited',
+ 'email': 'fake@example.com'
+ }
+ )
+ self.assertEqual(response.status_code, 302)
+ user = self.reload_object(self.user)
+ self.assertEqual(user.username, 'edited')
+ self.assertEqual(user.email, email_before)
+
+ @with_settings(EDITABLE_EMAIL=True)
+ def test_user_can_change_email(self):
+ self.client.login(user_id=self.user.id, method='force')
+ email_before = self.user.email
+ response = self.client.post(
+ reverse('edit_user', kwargs={'id': self.user.id}),
+ data={
+ 'username': 'edited',
+ 'email': 'new@example.com'
+ }
+ )
+ self.assertEqual(response.status_code, 302)
+ user = self.reload_object(self.user)
+ self.assertEqual(user.username, 'edited')
+ self.assertEqual(user.email, 'new@example.com')
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index de5bb12b..2f60c88b 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -30,17 +30,17 @@ from django.utils.translation import string_concat
from askbot.utils.slug import slugify
from askbot import models
from askbot import forms
-from askbot.conf import should_show_sort_by_relevance
+from askbot import conf
+from askbot import const
+from askbot import mail
from askbot.conf import settings as askbot_settings
from askbot.utils import category_tree
from askbot.utils import decorators
from askbot.utils import url_utils
from askbot.utils.forms import get_db_object_or_404
-from askbot import mail
from django.template import RequestContext
from askbot.skins.loaders import render_into_skin_as_string
from askbot.skins.loaders import render_text_into_skin
-from askbot import const
@csrf.csrf_exempt
@@ -712,7 +712,7 @@ def api_get_questions(request):
qs=threads
)
- if should_show_sort_by_relevance():
+ if conf.should_show_sort_by_relevance():
threads = threads.extra(order_by = ['-relevance'])
#todo: filter out deleted threads, for now there is no way
threads = threads.distinct()[:30]
@@ -736,10 +736,12 @@ def set_tag_filter_strategy(request):
filter_value = int(request.POST['filter_value'])
assert(filter_type in ('display', 'email'))
if filter_type == 'display':
- assert(filter_value in dict(const.TAG_DISPLAY_FILTER_STRATEGY_CHOICES))
+ allowed_values_dict = dict(conf.get_tag_display_filter_strategy_choices())
+ assert(filter_value in allowed_values_dict)
request.user.display_tag_filter_strategy = filter_value
else:
- assert(filter_value in dict(const.TAG_EMAIL_FILTER_STRATEGY_CHOICES))
+ allowed_values_dict = dict(conf.get_tag_email_filter_strategy_choices())
+ assert(filter_value in allowed_values_dict)
request.user.email_tag_filter_strategy = filter_value
request.user.save()
return HttpResponse('', mimetype = "application/json")
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index f1b31b32..d2c9df49 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -228,7 +228,7 @@ def questions(request, **kwargs):
'tag_list_type' : tag_list_type,
'font_size' : extra_tags.get_tag_font_size(related_tags),
'display_tag_filter_strategy_choices': conf.get_tag_display_filter_strategy_choices(),
- 'email_tag_filter_strategy_choices': const.TAG_EMAIL_FILTER_STRATEGY_CHOICES,
+ 'email_tag_filter_strategy_choices': conf.get_tag_email_filter_strategy_choices(),
'update_avatar_data': schedules.should_update_avatar_data(request),
'query_string': search_state.query_string(),
'search_state': search_state,
diff --git a/askbot/views/users.py b/askbot/views/users.py
index 414ac8b0..5524ebd8 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -317,9 +317,9 @@ def edit_user(request, id):
if request.method == "POST":
form = forms.EditUserForm(user, request.POST)
if form.is_valid():
- new_email = sanitize_html(form.cleaned_data['email'])
-
- set_new_email(user, new_email)
+ if 'email' in form.cleaned_data and askbot_settings.EDITABLE_EMAIL:
+ new_email = sanitize_html(form.cleaned_data['email'])
+ set_new_email(user, new_email)
if askbot_settings.EDITABLE_SCREEN_NAME:
new_username = sanitize_html(form.cleaned_data['username'])