summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-07-14 13:48:47 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-07-14 13:48:47 -0300
commit498f968b9962a6c3476d02e4563008c2257f18cf (patch)
tree03602eb91c311b38dd44426c38bc6b53a75dcd05
parent2f068799aa50fad58e1f827ea4f9ca7ef5d6574f (diff)
downloadaskbot-498f968b9962a6c3476d02e4563008c2257f18cf.tar.gz
askbot-498f968b9962a6c3476d02e4563008c2257f18cf.tar.bz2
askbot-498f968b9962a6c3476d02e4563008c2257f18cf.zip
premoderation fully works
-rw-r--r--askbot/const/message_keys.py1
-rw-r--r--askbot/media/style/style.css15
-rw-r--r--askbot/media/style/style.less19
-rw-r--r--askbot/models/__init__.py36
-rw-r--r--askbot/models/post.py44
-rw-r--r--askbot/models/question.py19
-rw-r--r--askbot/templates/macros.html18
-rw-r--r--askbot/templates/question/answer_card.html3
-rw-r--r--askbot/templates/question/question_card.html3
-rw-r--r--askbot/templates/widgets/system_messages.html2
-rw-r--r--askbot/views/readers.py2
11 files changed, 119 insertions, 43 deletions
diff --git a/askbot/const/message_keys.py b/askbot/const/message_keys.py
index bb990d5e..315c2400 100644
--- a/askbot/const/message_keys.py
+++ b/askbot/const/message_keys.py
@@ -45,3 +45,4 @@ CANNOT_PERFORM_ACTION_UNTIL = _('Sorry, you will be able to %(perform_action)s a
MODERATORS_OR_AUTHOR_CAN_PEFROM_ACTION = _(
'Sorry, only moderators or the %(post_author)s %(perform_action)s'
)
+PUNISHED_USER_INFO = _('Your account might be blocked in error - please contact the site administrators, if you think so.')
diff --git a/askbot/media/style/style.css b/askbot/media/style/style.css
index b08a76cd..ab5e12a6 100644
--- a/askbot/media/style/style.css
+++ b/askbot/media/style/style.css
@@ -231,7 +231,6 @@ body.user-messages {
.notify .notification {
color: #424242;
font-size: 16px;
- height: 34px;
line-height: 34px;
margin: 0 !important;
}
@@ -2051,6 +2050,20 @@ ul#related-tags li {
margin-bottom: 10px;
}
/* ----- Question template ----- */
+.answer .moderated,
+.question .moderated {
+ background: url(../images/dialog-warning.png) 2px 0 no-repeat;
+ font-weight: bold;
+ line-height: 16px !important;
+ margin-bottom: -2px !important;
+ padding-left: 24px !important;
+}
+.answer .comment .moderated,
+.question .comment .moderated {
+ background-position: 4px 0;
+ margin-bottom: -5px !important;
+ padding-left: 24px !important;
+}
.question-page h1 {
padding-top: 0px;
font-family: 'Open Sans Condensed', Arial, sans-serif;
diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less
index f9bdccbc..8c69e6e8 100644
--- a/askbot/media/style/style.less
+++ b/askbot/media/style/style.less
@@ -237,7 +237,6 @@ body.user-messages {
.notification {
color: #424242;
font-size: 16px;
- height: 34px;
line-height: 34px;
margin: 0 !important;
}
@@ -2161,6 +2160,24 @@ ul#related-tags li {
/* ----- Question template ----- */
+.moderated {
+}
+
+.answer, .question {
+ .moderated {
+ background: url(../images/dialog-warning.png) 2px 0 no-repeat;
+ font-weight: bold;
+ line-height: 16px !important;
+ margin-bottom: -2px !important;
+ padding-left: 24px !important;
+ }
+ .comment .moderated {
+ background-position: 4px 0;
+ margin-bottom: -5px !important;
+ padding-left: 24px !important;
+ }
+}
+
.question-page {
h1 {
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 8b85e42d..7d91216e 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -24,6 +24,7 @@ from django.db.models import signals as django_signals
from django.template import Context
from django.template.loader import get_template
from django.utils.translation import get_language
+from django.utils.translation import string_concat
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.utils.safestring import mark_safe
@@ -628,6 +629,7 @@ def _assert_user_can(
'perform_action': action_display,
'your_account_is': _('your account is blocked')
}
+ error_message = string_concat(error_message, '.</br> ', message_keys.PUNISHED_USER_INFO)
elif post and owner_can and user == post.get_owner():
if user.is_suspended() and suspended_owner_cannot:
error_message = _(message_keys.ACCOUNT_CANNOT_PERFORM_ACTION) % {
@@ -1283,20 +1285,10 @@ def user_post_anonymous_askbot_content(user, session_key):
aa.save()
#maybe add pending posts message?
else:
- if user.is_blocked() or user.is_suspended():
- if user.is_blocked():
- account_status = _('your account is blocked')
- elif user.is_suspended():
- account_status = _('your account is suspended')
- user.message_set.create(message = _(message_keys.ACCOUNT_CANNOT_PERFORM_ACTION) % {
- 'perform_action': _('make posts'),
- 'your_account_is': account_status
- })
- else:
- for aq in aq_list:
- aq.publish(user)
- for aa in aa_list:
- aa.publish(user)
+ for aq in aq_list:
+ aq.publish(user)
+ for aa in aa_list:
+ aa.publish(user)
def user_mark_tags(
@@ -3745,6 +3737,16 @@ def add_missing_tag_subscriptions(sender, instance, created, **kwargs):
instance.mark_tags(tagnames = tag_list,
reason='subscribed', action='add')
+def notify_punished_users(user, **kwargs):
+ try:
+ _assert_user_can(
+ user=user,
+ blocked_user_cannot=True,
+ suspended_user_cannot=True
+ )
+ except django_exceptions.PermissionDenied, e:
+ user.message_set.create(message = unicode(e))
+
def post_anonymous_askbot_content(
sender,
request,
@@ -3756,7 +3758,10 @@ def post_anonymous_askbot_content(
"""signal handler, unfortunately extra parameters
are necessary for the signal machinery, even though
they are not used in this function"""
- user.post_anonymous_askbot_content(session_key)
+ if user.is_blocked() or user.is_suspended():
+ pass
+ else:
+ user.post_anonymous_askbot_content(session_key)
def set_user_avatar_type_flag(instance, created, **kwargs):
instance.user.update_avatar_type()
@@ -3834,6 +3839,7 @@ signals.user_registered.connect(greet_new_user)
signals.user_registered.connect(make_admin_if_first_user)
signals.user_updated.connect(record_user_full_updated, sender=User)
signals.user_logged_in.connect(complete_pending_tag_subscriptions)#todo: add this to fake onlogin middleware
+signals.user_logged_in.connect(notify_punished_users)
signals.user_logged_in.connect(post_anonymous_askbot_content)
signals.post_updated.connect(record_post_update_activity)
signals.new_answer_posted.connect(tweet_new_post)
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 95e33083..07cadd19 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -778,7 +778,7 @@ class Post(models.Model):
self.remove_from_groups((Group.objects.get_global_group(),))
if len(groups) == 0:
- message = 'Sharing did not work, because group is unknown'
+ message = _('Sharing did not work, because group is unknown')
user.message_set.create(message=message)
def make_public(self):
@@ -795,10 +795,18 @@ class Post(models.Model):
return not self.groups.filter(id=group.id).exists()
return False
+ def set_runtime_needs_moderation(self):
+ """Used at runtime only, the value is not
+ stored in the database"""
+ self._is_approved = False
+
def is_approved(self):
"""``False`` only when moderation is ``True`` and post
``self.approved is False``
"""
+ if getattr(self, '_is_approved', True) == False:
+ return False
+
if askbot_settings.CONTENT_MODERATION_MODE == 'premoderation':
if self.approved:
return True
@@ -1642,7 +1650,8 @@ class Post(models.Model):
def _question__assert_is_visible_to(self, user):
"""raises QuestionHidden"""
if self.is_approved() is False:
- raise exceptions.QuestionHidden()
+ if user != self.author:
+ raise exceptions.QuestionHidden(_('Sorry, this content is not available'))
if self.deleted:
message = _('Sorry, this content is no longer available')
if user.is_anonymous():
@@ -1763,8 +1772,11 @@ class Post(models.Model):
suppress_email=False,
ip_addr=None,
):
+
+ latest_rev = self.get_latest_revision()
+
if text is None:
- text = self.get_latest_revision().text
+ text = latest_rev.text
if edited_at is None:
edited_at = datetime.datetime.now()
if edited_by is None:
@@ -1780,15 +1792,23 @@ class Post(models.Model):
if self.wiki == False and wiki == True:
self.wiki = True
- #must add revision before saving the answer
- self.add_revision(
- author=edited_by,
- revised_at=edited_at,
- text=text,
- comment=comment,
- by_email=by_email,
- ip_addr=ip_addr,
- )
+ #must add or update revision before saving the answer
+ if latest_rev.revision == 0:
+ #if post has only 0 revision, we just update the
+ #latest revision data
+ latest_rev.text = text
+ latest_rev.revised_at = edited_at
+ latest_rev.save()
+ else:
+ #otherwise we create a new revision
+ self.add_revision(
+ author=edited_by,
+ revised_at=edited_at,
+ text=text,
+ comment=comment,
+ by_email=by_email,
+ ip_addr=ip_addr,
+ )
parse_results = self.parse_and_save(author=edited_by, is_private=is_private)
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 82a3e192..399066b3 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -917,12 +917,16 @@ class Thread(models.Model):
post__id__in=post_ids,
revision__gt=0
).order_by('-id')
- rev = revs[0]
- return rev.revised_at, rev.author
+ try:
+ rev = revs[0]
+ return rev.revised_at, rev.author
+ except IndexError:
+ return None, None
def update_last_activity_info(self):
timestamp, user = self.get_last_activity_info()
- self.set_last_activity_info(timestamp, user)
+ if timestamp:
+ self.set_last_activity_info(timestamp, user)
def get_tag_names(self):
"Creates a list of Tag names from the ``tagnames`` attribute."
@@ -1057,6 +1061,7 @@ class Thread(models.Model):
if askbot_settings.CONTENT_MODERATION_MODE == 'premoderation' and user.is_watched():
#in this branch we patch post_data with the edits suggested by the
#watched user
+ post_data = list(post_data)
post_ids = self.posts.filter(author=user).values_list('id', flat=True)
from askbot.models import PostRevision
suggested_revs = PostRevision.objects.filter(
@@ -1089,7 +1094,8 @@ class Thread(models.Model):
post_id_set = set(suggested_post_ids)
all_posts = copy(answers)
- all_posts.append(question)
+ if question:
+ all_posts.append(question)
posts = find_posts(all_posts, post_id_set)
rev_map = dict(zip(suggested_post_ids, suggested_revs))
@@ -1099,6 +1105,8 @@ class Thread(models.Model):
#patching work
post.text = rev.text
post.html = post.parse_post_text()['html']
+ post_to_author[post_id] = rev.author_id
+ post.set_runtime_needs_moderation()
if len(post_id_set):
#brand new suggested posts
@@ -1109,6 +1117,7 @@ class Thread(models.Model):
rev = rev_map[post.id]
post.text = rev.text
post.html = post.parse_post_text()['html']
+ post_to_author[post.id] = rev.author_id
if post.is_comment():
parents = find_posts(all_posts, set([post.parent_id]))
parent = parents.values()[0]
@@ -1439,7 +1448,7 @@ class Thread(models.Model):
self._question_post().make_private(user, group_id)
if len(groups) == 0:
- message = 'Sharing did not work, because group is unknown'
+ message = _('Sharing did not work, because group is unknown')
user.message_set.create(message=message)
def is_private(self):
diff --git a/askbot/templates/macros.html b/askbot/templates/macros.html
index d6845c08..8b657ec1 100644
--- a/askbot/templates/macros.html
+++ b/askbot/templates/macros.html
@@ -393,18 +393,19 @@ for the purposes of the AJAX comment editor #}
)
-%}
{% spaceless %}
- {% if post.comment_count > 0 %}
+ {% if show_post == post and show_comment and show_comment_position > max_comments %}
+ {% set comments = post.get_cached_comments()[:show_comment_position] %}
+ {% else %}
+ {% set comments = post.get_cached_comments()[:max_comments] %}
+ {% endif %}
+ {% set comments_count = comments|length %}
+ {% if comments_count > 0 %}
<h2 class="comment-title">{% trans %}Comments{% endtrans %}</h2>
<div class="clean"></div>
{% endif %}
{% set widget_id = 'comments-for-' + post.post_type + '-' + post.id|string %}
- <div class="comments{% if post.comment_count == 0 %} empty{% endif %}" id="{{ widget_id }}">
+ <div class="comments{% if comments_count == 0 %} empty{% endif %}" id="{{ widget_id }}">
<div class="content">
- {% if show_post == post and show_comment and show_comment_position > max_comments %}
- {% set comments = post.get_cached_comments()[:show_comment_position] %}
- {% else %}
- {% set comments = post.get_cached_comments()[:max_comments] %}
- {% endif %}
{% for comment in comments %}
{# Warning! Any changes to the comment markup IN THIS `FOR` LOOP must be duplicated in post.js
for the purposes of the AJAX comment editor #}
@@ -435,6 +436,9 @@ for the purposes of the AJAX comment editor #}
title="{% trans %}delete this comment{% endtrans %}"
></span>
</div>
+ {% if comment.needs_moderation() %}
+ <p class="moderated">{% trans %}This post is awaiting moderation{% endtrans %}</p>
+ {% endif %}
<div class="comment-body">
{{ comment.summary }}
<a
diff --git a/askbot/templates/question/answer_card.html b/askbot/templates/question/answer_card.html
index 9a833a35..b7ec2435 100644
--- a/askbot/templates/question/answer_card.html
+++ b/askbot/templates/question/answer_card.html
@@ -20,6 +20,9 @@
{% if answer.id in published_answer_ids %}
<p><strong>{% trans %}This response is published{% endtrans %}</strong></p>
{% endif %}
+ {% if answer.needs_moderation() %}
+ <p class="moderated">{% trans %}This post is awaiting moderation{% endtrans %}</p>
+ {% endif %}
{{ answer.summary }}
</div>
<div class="answer-controls post-controls">
diff --git a/askbot/templates/question/question_card.html b/askbot/templates/question/question_card.html
index d6c37260..12260f12 100644
--- a/askbot/templates/question/question_card.html
+++ b/askbot/templates/question/question_card.html
@@ -13,6 +13,9 @@
<div class="post-update-info-container">
{% include "question/question_author_info.html" %}
</div>
+ {% if question.needs_moderation() %}
+ <p class="moderated">{% trans %}This post awaiting moderation{% endtrans %}</p>
+ {% endif %}
{{ question.summary }}
</div>
<div id="question-controls" class="post-controls">
diff --git a/askbot/templates/widgets/system_messages.html b/askbot/templates/widgets/system_messages.html
index 69f6672f..48170857 100644
--- a/askbot/templates/widgets/system_messages.html
+++ b/askbot/templates/widgets/system_messages.html
@@ -2,7 +2,7 @@
<div class="content-wrapper">
{% if user_messages %}
{% for message in user_messages %}
- <p class="notification">{{ message }}</p>
+ {% if message %}<p class="notification">{{ message }}</p>{% endif %}
{% endfor %}
{% endif %}
<a id="closeNotify" onclick="notify.close(true)"></a>
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index e90b7e97..79db9a12 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -530,7 +530,7 @@ def question(request, id):#refactor - long subroutine. display question body, an
#we can avoid making this query by iterating through
#already loaded posts
user_post_id_list = [
- id for id in post_to_author if post_to_author[id] == request.user.id
+ post_id for post_id in post_to_author if post_to_author[post_id] == request.user.id
]
#resolve page number and comment number for permalinks