in Allura/allura/controllers/discuss.py [0:0]
def save_moderation(self, post=[], delete=None, spam=None, approve=None, **kw):
count = 0
for p in post:
posted = None
if isinstance(p, dict):
# regular form submit
if 'checked' in p:
posted = self.PostModel.query.get(
_id=p['_id'],
# make sure nobody hacks the HTML form to moderate other
# posts
discussion_id=self.discussion._id,
)
elif isinstance(p, self.PostModel):
# called from save_moderation_bulk_user with models already
posted = p
else:
raise TypeError('post list should be form fields, or Post models')
if posted:
if delete:
count += 1
# full, for real, delete since this is post was never visible and denied by admin.
posted.delete()
# If we just deleted the last post in the
# thread, delete the thread.
if posted.thread and posted.thread.num_replies == 0:
posted.thread.delete()
elif spam and posted.status != 'spam':
count += 1
posted.spam()
elif approve and posted.status != 'ok':
count += 1
posted.approve()
g.spam_checker.submit_ham(posted.text, artifact=posted, user=posted.author())
posted.thread.post_to_feed(posted)
flash('{} {}'.format(h.text.plural(count, 'post', 'posts'),
'deleted' if delete else 'marked as spam' if spam else 'approved'))
redirect(six.ensure_text(request.referer or '/'))