def test_log_deletion(self):
        log = ModerationLog.create(admin_id=self.admin.id, reason=self.reason,
                                   action=ACTION_HIDE_REVIEW, review_id=self.review.id)
        self.assertEqual(ModerationLog.query.count(), 1)

        log.delete()
        self.assertEqual(ModerationLog.query.count(), 0)
예제 #2
0
def block(user_id):
    user = User.query.get_or_404(str(user_id))

    if user.is_blocked:
        flash(gettext("This account is already blocked."), 'info')
        return redirect(url_for('user.reviews', user_id=user.id))

    form = AdminActionForm()
    if form.validate_on_submit():
        user.block()
        ModerationLog.create(admin_id=current_user.id, action=ACTION_BLOCK_USER,
                             reason=form.reason.data, user_id=user.id)
        flash(gettext("This user account has been blocked."), 'success')
        return redirect(url_for('user.reviews', user_id=user.id))

    return render_template('log/action.html', user=user, form=form, action=ACTION_BLOCK_USER)
예제 #3
0
    def test_log_deletion(self):
        log = ModerationLog.create(admin_id=self.admin.id, reason=self.reason,
                                   action=ACTION_HIDE_REVIEW, review_id=self.review.id)
        self.assertEqual(ModerationLog.query.count(), 1)

        log.delete()
        self.assertEqual(ModerationLog.query.count(), 0)
예제 #4
0
def more():
    page = int(request.args.get('page', default=0))
    offset = page * RESULTS_LIMIT

    results, count = ModerationLog.list(offset=offset, limit=RESULTS_LIMIT)
    results = groupby(results, lambda log: log.timestamp.strftime('%d %b, %G'))

    template = render_template('log/log_results.html', results=results)
    return jsonify(results=template, more=(count-offset-RESULTS_LIMIT) > 0)
예제 #5
0
def browse():
    results, count = ModerationLog.list(limit=RESULTS_LIMIT)

    if not results:
        flash(gettext("No logs to display."), "warning")

    results = groupby(results, lambda log: log.timestamp.strftime('%d %b, %G'))

    return render_template('log/browse.html', count=count, results=results, limit=RESULTS_LIMIT)
예제 #6
0
def hide(id):
    review = Review.query.get_or_404(str(id))

    if review.is_hidden:
        flash(gettext("Review is already hidden."), 'info')
        return redirect(url_for('.entity', id=review.id))

    form = AdminActionForm()
    if form.validate_on_submit():
        review.hide()
        ModerationLog.create(admin_id=current_user.id, action=ACTION_HIDE_REVIEW,
                             reason=form.reason.data, review_id=review.id)
        for report in SpamReport.list(review_id=review.id)[0]:
            report.archive()
        flash(gettext("Review has been hidden."), 'success')
        return redirect(url_for('.entity', id=review.id))

    return render_template('log/action.html', review=review, form=form, action=ACTION_HIDE_REVIEW)
예제 #7
0
def hide(id):
    review = Review.query.get_or_404(str(id))

    if review.is_hidden:
        flash(gettext("Review is already hidden."), 'info')
        return redirect(url_for('.entity', id=review.id))

    form = AdminActionForm()
    if form.validate_on_submit():
        review.hide()
        ModerationLog.create(admin_id=current_user.id, action=ACTION_HIDE_REVIEW,
                             reason=form.reason.data, review_id=review.id)
        for report in SpamReport.list(review_id=review.id)[0]:
            report.archive()
        flash(gettext("Review has been hidden."), 'success')
        return redirect(url_for('.entity', id=review.id))

    return render_template('log/action.html', review=review, form=form, action=ACTION_HIDE_REVIEW)
예제 #8
0
def more():
    page = int(request.args.get('page', default=0))
    offset = page * RESULTS_LIMIT

    results, count = ModerationLog.list(offset=offset, limit=RESULTS_LIMIT)
    results = groupby(results, lambda log: log.timestamp.strftime('%d %b, %G'))

    template = render_template('log/log_results.html', results=results)
    return jsonify(results=template, more=(count - offset - RESULTS_LIMIT) > 0)
    def test_log_creation(self):
        self.assertEqual(ModerationLog.query.count(), 0)

        log = ModerationLog.create(admin_id=self.admin.id, reason=self.reason,
                                   action=ACTION_BLOCK_USER, user_id=self.user.id)

        all_logs = ModerationLog.query.all()
        self.assertEqual(len(all_logs), 1)
        self.assertEqual(all_logs[0].user_id, log.user_id)
        self.assertEqual(all_logs[0].reason, log.reason)
예제 #10
0
    def test_log_creation(self):
        self.assertEqual(ModerationLog.query.count(), 0)

        log = ModerationLog.create(admin_id=self.admin.id, reason=self.reason,
                                   action=ACTION_BLOCK_USER, user_id=self.user.id)

        all_logs = ModerationLog.query.all()
        self.assertEqual(len(all_logs), 1)
        self.assertEqual(all_logs[0].user_id, log.user_id)
        self.assertEqual(all_logs[0].reason, log.reason)
예제 #11
0
def browse():
    results, count = ModerationLog.list(limit=RESULTS_LIMIT)

    if not results:
        flash(gettext("No logs to display."), "warning")

    results = groupby(results, lambda log: log.timestamp.strftime('%d %b, %G'))

    return render_template('log/browse.html',
                           count=count,
                           results=results,
                           limit=RESULTS_LIMIT)
예제 #12
0
def block(user_id):
    user = db_users.get_by_id(user_id)
    if not user:
        abort(404)

    if user['is_blocked']:
        flash.info(gettext("This account is already blocked."))
        return redirect(url_for('user.reviews', user_id=user['id']))

    form = AdminActionForm()
    if form.validate_on_submit():
        db_users.block(user['id'])
        ModerationLog.create(admin_id=current_user.id,
                             action=ACTION_BLOCK_USER,
                             reason=form.reason.data,
                             user_id=user['id'])
        flash.success(gettext("This user account has been blocked."))
        return redirect(url_for('user.reviews', user_id=user['id']))

    return render_template('log/action.html',
                           user=user,
                           form=form,
                           action=ACTION_BLOCK_USER)