summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Bokov <razum2um@mail.ru>2011-10-21 12:07:27 +0700
committerVlad Bokov <razum2um@mail.ru>2011-10-21 13:07:32 +0700
commit47c729e81a96a20fdf6c2d8b5938aea27c4400de (patch)
tree1584fea4d4cf1c062af971a7aaa7d344b03901ca
parenta08fc54db880b20e37c126c70427d8b94af91e78 (diff)
downloadaskbot-47c729e81a96a20fdf6c2d8b5938aea27c4400de.tar.gz
askbot-47c729e81a96a20fdf6c2d8b5938aea27c4400de.tar.bz2
askbot-47c729e81a96a20fdf6c2d8b5938aea27c4400de.zip
Feature #116: allow-admins-moderators-accept-answers (+tests)
-rw-r--r--askbot/conf/spam_and_moderation.py15
-rw-r--r--askbot/models/__init__.py15
-rw-r--r--askbot/tests/permission_assertion_tests.py43
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()