summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/conf/spam_and_moderation.py1
-rw-r--r--askbot/conf/vote_rules.py10
-rw-r--r--askbot/models/__init__.py15
-rw-r--r--askbot/skins/common/media/js/post.js10
-rw-r--r--askbot/skins/common/templates/question/answer_vote_buttons.html2
-rw-r--r--askbot/tests/permission_assertion_tests.py38
6 files changed, 59 insertions, 17 deletions
diff --git a/askbot/conf/spam_and_moderation.py b/askbot/conf/spam_and_moderation.py
index e841ebf7..23cb9596 100644
--- a/askbot/conf/spam_and_moderation.py
+++ b/askbot/conf/spam_and_moderation.py
@@ -31,4 +31,3 @@ settings.register(
description=_('Akismet key for spam detection')
)
)
-
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 e1677d9f..5d1cd95d 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_FOR_STAFF_TO_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/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js
index 52772cc0..5cf9cb4f 100644
--- a/askbot/skins/common/media/js/post.js
+++ b/askbot/skins/common/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/common/templates/question/answer_vote_buttons.html b/askbot/skins/common/templates/question/answer_vote_buttons.html
index bef26b75..836eb7fe 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 %}
+{% if request.user == question.author or request.user.is_moderator or request.user.is_superuser %}
<img id="answer-img-accept-{{ answer.id }}" class="answer-img-accept"
{% if answer.accepted %}
src="{{'/images/vote-accepted-on.png'|media}}"
diff --git a/askbot/tests/permission_assertion_tests.py b/askbot/tests/permission_assertion_tests.py
index 83476c79..fc1fbcb7 100644
--- a/askbot/tests/permission_assertion_tests.py
+++ b/askbot/tests/permission_assertion_tests.py
@@ -1368,23 +1368,27 @@ 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):
- 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_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_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_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_cannot(user = self.third_user)
+ self.assert_user_can(user = self.third_user)
def test_admin_cannot_accept_own_answer(self):
self.other_post_answer()
@@ -1392,6 +1396,24 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase):
self.other_user.save()
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')
+ 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_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
"""