From 47c729e81a96a20fdf6c2d8b5938aea27c4400de Mon Sep 17 00:00:00 2001 From: Vlad Bokov Date: Fri, 21 Oct 2011 12:07:27 +0700 Subject: Feature #116: allow-admins-moderators-accept-answers (+tests) --- askbot/conf/spam_and_moderation.py | 15 +++++++++++ askbot/models/__init__.py | 15 ++++++++++- askbot/tests/permission_assertion_tests.py | 43 ++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/askbot/conf/spam_and_moderation.py b/askbot/conf/spam_and_moderation.py index e841ebf7..6ad79130 100644 --- a/askbot/conf/spam_and_moderation.py +++ b/askbot/conf/spam_and_moderation.py @@ -11,6 +11,11 @@ SPAM_AND_MODERATION = livesettings.ConfigurationGroup( super_group = EXTERNAL_SERVICES ) +MIN_DAYS_TO_STAFF_ACCEPT_ANSWER = livesettings.ConfigurationGroup( + 'MIN_DAYS_TO_STAFF_ACCEPT_ANSWER', + _('Answer content moderation') + ) + settings.register( livesettings.BooleanValue( SPAM_AND_MODERATION, @@ -32,3 +37,13 @@ settings.register( ) ) +settings.register( + livesettings.IntegerValue( + SPAM_AND_MODERATION, + 'MIN_DAYS_TO_STAFF_ACCEPT_ANSWER', + default=7, + description=_('Minimum days to accept an answer, ' + 'if it has not been accepted by the question poster') + ) +) + diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index e1677d9f..04d43c5d 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -342,9 +342,22 @@ def user_assert_can_unaccept_best_answer(self, answer = None): low_rep_error_message = low_rep_error_message ) return # success + + elif self.is_administrator() or self.is_moderator(): + will_be_able_at = (answer.added_at + + datetime.timedelta(days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER)) + + if datetime.datetime.now() < will_be_able_at: + error_message = _( + 'Sorry, you will be able to accept this answer ' + 'only after %(will_be_able_at)s' + ) % {'will_be_able_at': will_be_able_at.strftime('%d/%m/%Y')} + else: + return + else: error_message = _( - 'Sorry, only original author of the question ' + 'Sorry, only moderators or original author of the question ' ' - %(username)s - can accept or unaccept the best answer' ) % {'username': answer.get_owner().username} diff --git a/askbot/tests/permission_assertion_tests.py b/askbot/tests/permission_assertion_tests.py index 83476c79..12877b7f 100644 --- a/askbot/tests/permission_assertion_tests.py +++ b/askbot/tests/permission_assertion_tests.py @@ -1368,24 +1368,63 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): self.third_user.reputation = 1000000 self.assert_user_cannot(user = self.third_user) - def test_moderator_cannot_accept_others_answer(self): + def test_moderator_cannot_accept_others_answer_today(self): self.other_post_answer() self.create_user(username = 'third_user') self.third_user.set_status('m') self.assert_user_cannot(user = self.third_user) + def test_moderator_can_accept_others_old_answer(self): + self.other_post_answer() + self.answer.added_at -= datetime.timedelta( + days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER+1) + self.answer.save() + self.create_user(username = 'third_user') + self.third_user.set_admin_status() + self.third_user.save() + self.assert_user_can(user = self.third_user) + + def test_admin_cannot_accept_own_answer(self): + self.other_post_answer() + self.other_user.set_admin_status() + self.other_user.save() + self.assert_user_cannot(user = self.other_user) + +class VotePermissionAssertionTests(PermissionAssertionTestCase): + """Tests permission for voting + """ + def extraSetUp(self): + self.min_rep_up = askbot_settings.MIN_REP_TO_VOTE_UP + self.min_rep_down = askbot_settings.MIN_REP_TO_VOTE_DOWN + self.other_user = self.create_other_user() + + def assert_cannot_vote(self, user = None, dir = None): + self.create_user(username = 'third_user') + self.third_user.set_status('m') + self.assert_user_can(user = self.third_user) + def test_moderator_cannot_accept_own_answer(self): self.other_post_answer() self.other_user.set_status('m') self.assert_user_cannot(user = self.other_user) - def test_admin_cannot_accept_others_answer(self): + def test_admin_cannot_accept_others_answer_today(self): self.other_post_answer() self.create_user(username = 'third_user') self.third_user.set_admin_status() self.third_user.save() self.assert_user_cannot(user = self.third_user) + def test_admin_can_accept_others_old_answer(self): + self.other_post_answer() + self.answer.added_at -= datetime.timedelta( + days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER+1) + self.answer.save() + self.create_user(username = 'third_user') + self.third_user.set_admin_status() + self.third_user.save() + self.assert_user_can(user = self.third_user) + def test_admin_cannot_accept_own_answer(self): self.other_post_answer() self.other_user.set_admin_status() -- cgit v1.2.3-1-g7c22 From 0ae572a6df6d79924f5e19b1c06707261091db74 Mon Sep 17 00:00:00 2001 From: Vlad Bokov Date: Fri, 21 Oct 2011 12:23:00 +0700 Subject: Feature #116: some misplacing corrected --- askbot/tests/permission_assertion_tests.py | 40 +++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/askbot/tests/permission_assertion_tests.py b/askbot/tests/permission_assertion_tests.py index 12877b7f..5d01767f 100644 --- a/askbot/tests/permission_assertion_tests.py +++ b/askbot/tests/permission_assertion_tests.py @@ -1368,6 +1368,11 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): self.third_user.reputation = 1000000 self.assert_user_cannot(user = self.third_user) + def test_moderator_cannot_accept_own_answer(self): + self.other_post_answer() + self.other_user.set_status('m') + self.assert_user_cannot(user = self.other_user) + def test_moderator_cannot_accept_others_answer_today(self): self.other_post_answer() self.create_user(username = 'third_user') @@ -1390,24 +1395,6 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): self.other_user.save() self.assert_user_cannot(user = self.other_user) -class VotePermissionAssertionTests(PermissionAssertionTestCase): - """Tests permission for voting - """ - def extraSetUp(self): - self.min_rep_up = askbot_settings.MIN_REP_TO_VOTE_UP - self.min_rep_down = askbot_settings.MIN_REP_TO_VOTE_DOWN - self.other_user = self.create_other_user() - - def assert_cannot_vote(self, user = None, dir = None): - self.create_user(username = 'third_user') - self.third_user.set_status('m') - self.assert_user_can(user = self.third_user) - - def test_moderator_cannot_accept_own_answer(self): - self.other_post_answer() - self.other_user.set_status('m') - self.assert_user_cannot(user = self.other_user) - def test_admin_cannot_accept_others_answer_today(self): self.other_post_answer() self.create_user(username = 'third_user') @@ -1425,11 +1412,18 @@ class VotePermissionAssertionTests(PermissionAssertionTestCase): self.third_user.save() self.assert_user_can(user = self.third_user) - def test_admin_cannot_accept_own_answer(self): - self.other_post_answer() - self.other_user.set_admin_status() - self.other_user.save() - self.assert_user_cannot(user = self.other_user) +class VotePermissionAssertionTests(PermissionAssertionTestCase): + """Tests permission for voting + """ + def extraSetUp(self): + self.min_rep_up = askbot_settings.MIN_REP_TO_VOTE_UP + self.min_rep_down = askbot_settings.MIN_REP_TO_VOTE_DOWN + self.other_user = self.create_other_user() + + def assert_cannot_vote(self, user = None, dir = None): + self.create_user(username = 'third_user') + self.third_user.set_status('m') + self.assert_user_can(user = self.third_user) class VotePermissionAssertionTests(PermissionAssertionTestCase): """Tests permission for voting -- cgit v1.2.3-1-g7c22 From efaf388bbb2bfde35f69341291d3d7f15e2bbfa5 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 23 Oct 2011 01:56:14 -0300 Subject: a small change, moved setting to another chapter and renamed the setting --- askbot/conf/spam_and_moderation.py | 16 ---------------- askbot/conf/vote_rules.py | 10 ++++++++++ askbot/models/__init__.py | 2 +- askbot/tests/permission_assertion_tests.py | 19 ++++--------------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/askbot/conf/spam_and_moderation.py b/askbot/conf/spam_and_moderation.py index 6ad79130..23cb9596 100644 --- a/askbot/conf/spam_and_moderation.py +++ b/askbot/conf/spam_and_moderation.py @@ -11,11 +11,6 @@ SPAM_AND_MODERATION = livesettings.ConfigurationGroup( super_group = EXTERNAL_SERVICES ) -MIN_DAYS_TO_STAFF_ACCEPT_ANSWER = livesettings.ConfigurationGroup( - 'MIN_DAYS_TO_STAFF_ACCEPT_ANSWER', - _('Answer content moderation') - ) - settings.register( livesettings.BooleanValue( SPAM_AND_MODERATION, @@ -36,14 +31,3 @@ settings.register( description=_('Akismet key for spam detection') ) ) - -settings.register( - livesettings.IntegerValue( - SPAM_AND_MODERATION, - 'MIN_DAYS_TO_STAFF_ACCEPT_ANSWER', - default=7, - description=_('Minimum days to accept an answer, ' - 'if it has not been accepted by the question poster') - ) -) - diff --git a/askbot/conf/vote_rules.py b/askbot/conf/vote_rules.py index 5d275708..82c9b758 100644 --- a/askbot/conf/vote_rules.py +++ b/askbot/conf/vote_rules.py @@ -78,3 +78,13 @@ settings.register( description=_('Number of flags required to automatically delete posts') ) ) + +settings.register( + IntegerValue( + VOTE_RULES, + 'MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER', + default=7, + description=_('Minimum days to accept an answer, ' + 'if it has not been accepted by the question poster') + ) +) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 04d43c5d..5d1cd95d 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -345,7 +345,7 @@ def user_assert_can_unaccept_best_answer(self, answer = None): elif self.is_administrator() or self.is_moderator(): will_be_able_at = (answer.added_at + - datetime.timedelta(days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER)) + datetime.timedelta(days=askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER)) if datetime.datetime.now() < will_be_able_at: error_message = _( diff --git a/askbot/tests/permission_assertion_tests.py b/askbot/tests/permission_assertion_tests.py index 5d01767f..fc1fbcb7 100644 --- a/askbot/tests/permission_assertion_tests.py +++ b/askbot/tests/permission_assertion_tests.py @@ -1382,7 +1382,8 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): def test_moderator_can_accept_others_old_answer(self): self.other_post_answer() self.answer.added_at -= datetime.timedelta( - days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER+1) + days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1 + ) self.answer.save() self.create_user(username = 'third_user') self.third_user.set_admin_status() @@ -1405,26 +1406,14 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): def test_admin_can_accept_others_old_answer(self): self.other_post_answer() self.answer.added_at -= datetime.timedelta( - days=askbot_settings.MIN_DAYS_TO_STAFF_ACCEPT_ANSWER+1) + days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1 + ) self.answer.save() self.create_user(username = 'third_user') self.third_user.set_admin_status() self.third_user.save() self.assert_user_can(user = self.third_user) -class VotePermissionAssertionTests(PermissionAssertionTestCase): - """Tests permission for voting - """ - def extraSetUp(self): - self.min_rep_up = askbot_settings.MIN_REP_TO_VOTE_UP - self.min_rep_down = askbot_settings.MIN_REP_TO_VOTE_DOWN - self.other_user = self.create_other_user() - - def assert_cannot_vote(self, user = None, dir = None): - self.create_user(username = 'third_user') - self.third_user.set_status('m') - self.assert_user_can(user = self.third_user) - class VotePermissionAssertionTests(PermissionAssertionTestCase): """Tests permission for voting """ -- cgit v1.2.3-1-g7c22 From 9bda8898825233886c3bcd9b116be3956d6de84e Mon Sep 17 00:00:00 2001 From: Vlad Bokov Date: Tue, 25 Oct 2011 14:16:33 +0700 Subject: Feature #116: fix template for stuff --- askbot/skins/default/media/js/post.js | 10 ++++------ askbot/skins/default/templates/question.html | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/askbot/skins/default/media/js/post.js b/askbot/skins/default/media/js/post.js index 52772cc0..5cf9cb4f 100644 --- a/askbot/skins/default/media/js/post.js +++ b/askbot/skins/default/media/js/post.js @@ -398,12 +398,10 @@ var Vote = function(){ var bindEvents = function(){ // accept answers - if(questionAuthorId == currentUserId){ - var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']'; - $(acceptedButtons).unbind('click').click(function(event){ - Vote.accept($(event.target)); - }); - } + var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']'; + $(acceptedButtons).unbind('click').click(function(event){ + Vote.accept($(event.target)); + }); // set favorite question var favoriteButton = getFavoriteButton(); favoriteButton.unbind('click').click(function(event){ diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index 282b47b4..5414fd18 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -194,7 +194,7 @@ {% endif %} alt="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" title="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" /> - {% if request.user == question.author %} + {% if request.user == question.author or request.user.is_moderator or request.user.is_superuser %} Date: Sun, 30 Oct 2011 00:53:59 +0700 Subject: Feature #116: fix jinja template calls --- askbot/skins/common/templates/question/answer_vote_buttons.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/askbot/skins/common/templates/question/answer_vote_buttons.html b/askbot/skins/common/templates/question/answer_vote_buttons.html index 836eb7fe..807f3ab8 100644 --- a/askbot/skins/common/templates/question/answer_vote_buttons.html +++ b/askbot/skins/common/templates/question/answer_vote_buttons.html @@ -17,7 +17,7 @@ {% endif %} alt="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" title="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" /> -{% if request.user == question.author or request.user.is_moderator or request.user.is_superuser %} +{% if request.user == question.author or request.user.is_moderator() or request.user.is_superuser() %} Date: Sat, 5 Nov 2011 06:45:46 +0700 Subject: Feature #134: time-based cache for anonymous only & tests --- askbot/setup_templates/settings.py | 1 + .../templates/question/answer_vote_buttons.html | 2 +- askbot/tests/db_api_tests.py | 35 ++++++++++++++++++++++ askbot/views/readers.py | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index a97402aa..3aead40f 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -176,6 +176,7 @@ CACHE_BACKEND = 'locmem://' #needed for django-keyedcache CACHE_TIMEOUT = 6000 CACHE_PREFIX = 'askbot' #make this unique +CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True #If you use memcache you may want to uncomment the following line to enable memcached based sessions #SESSION_ENGINE = 'django.contrib.sessions.backends.cache_db' diff --git a/askbot/skins/common/templates/question/answer_vote_buttons.html b/askbot/skins/common/templates/question/answer_vote_buttons.html index 807f3ab8..1cdd5188 100644 --- a/askbot/skins/common/templates/question/answer_vote_buttons.html +++ b/askbot/skins/common/templates/question/answer_vote_buttons.html @@ -17,7 +17,7 @@ {% endif %} alt="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" title="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" /> -{% if request.user == question.author or request.user.is_moderator() or request.user.is_superuser() %} +{% if request.user == question.author or request.user.is_authenticated() and (request.user.is_moderator() or request.user.is_superuser()) %} len(connection.queries)) + self.assertEqual(3, len(connection.queries)) # session-related only + settings.DEBUG = False + + def test_authentificated_no_question_cache(self): + question = self.post_question() + settings.DEBUG = True # because it's forsed to False + url = reverse('question', kwargs={'id': question.id}) + + password = '123' + client = Client() + self.other_user.set_password(password) + client.login(username=self.other_user.username, password=password) + + client.get(url, follow=True) + counter = len(connection.queries) + client.get(url, follow=True) + + self.assertEqual(counter, len(connection.queries)) + settings.DEBUG = False + def test_flag_question(self): self.user.set_status('m') self.user.flag_post(self.question) diff --git a/askbot/views/readers.py b/askbot/views/readers.py index eabef3c8..8d06c2be 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -23,6 +23,7 @@ from django.views.decorators import csrf from django.core.urlresolvers import reverse from django.core import exceptions as django_exceptions from django.contrib.humanize.templatetags import humanize +from django.views.decorators.cache import cache_page import askbot from askbot import exceptions @@ -349,6 +350,7 @@ def tags(request):#view showing a listing of available tags - plain list return render_into_skin('tags.html', data, request) @csrf.csrf_protect +@cache_page(60 * 5) def question(request, id):#refactor - long subroutine. display question body, answers and comments """view that displays body of the question and all answers to it -- cgit v1.2.3-1-g7c22 From ab5cd18f5a694f127a7f6fae566ca86c7097fd0b Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 6 Nov 2011 10:31:52 -0300 Subject: Added Vlad Bokov to the list of contribs --- askbot/doc/source/changelog.rst | 1 + askbot/doc/source/contributors.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index b22839e0..0c05deb2 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -5,6 +5,7 @@ Development version (not yet published) --------------------------------------- * Show unused vote count (Tomasz Zielinski) * Categorized live settings (Evgeny) +* Anonymous caching of the question page (Vlad Bokov) 0.7.26 (Current Version) ------------------------ diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst index ac807193..3e62af26 100644 --- a/askbot/doc/source/contributors.rst +++ b/askbot/doc/source/contributors.rst @@ -19,6 +19,7 @@ Programming and documentation * `Hrishi `_ * Andrei Mamoutkine * `Ramiro Morales `_ (with Machinalis) +* Vladimir Bokov * `NoahY `_ * `Gael Pasgrimaud `_ (bearstech) * `Arun SAG `_ -- cgit v1.2.3-1-g7c22