예제 #1
0
 def test_list_reports(self):
     db_spam_report.create(self.revision_id, self.user2.id,
                           "This is a report")
     db_review.update(
         review_id=self.review["id"],
         drafted=self.review["is_draft"],
         text="Updated Review",
     )
     self.review = db_review.get_by_id(self.review["id"])
     db_spam_report.create(self.review["last_revision"]["id"],
                           self.user1.id,
                           "This is again a report on the updated review")
     # two reports on the old revision and one on the new revision.
     reports, count = db_spam_report.list_reports(
         review_id=self.review["id"])  # pylint: disable=unused-variable
     self.assertEqual(count, 3)
     # get all reports by a user.
     reports, count = db_spam_report.list_reports(user_id=self.user2.id)
     self.assertEqual(count, 1)
     # archive and include all archived reports.
     # there must be two reports including the archived one.
     db_spam_report.archive(self.user1.id,
                            self.review["last_revision"]["id"])
     reports, count = db_spam_report.list_reports(inc_archived=True)
     self.assertEqual(count, 3)
     # there must be one reports excluding the archived one.
     reports, count = db_spam_report.list_reports(inc_archived=False)
     self.assertEqual(count, 2)
예제 #2
0
def more():
    page = int(request.args.get('page', default=0))
    offset = page * RESULTS_LIMIT

    results, count = db_spam_report.list_reports(offset=offset, limit=RESULTS_LIMIT, inc_archived=False)
    template = render_template('reports/reports_results.html', results=results)
    return jsonify(results=template, more=(count-offset-RESULTS_LIMIT) > 0)
예제 #3
0
def index():
    results, count = db_spam_report.list_reports(limit=RESULTS_LIMIT,
                                                 inc_archived=False)
    return render_template('reports/reports.html',
                           count=count,
                           results=results,
                           limit=RESULTS_LIMIT)
예제 #4
0
 def test_list_reports(self):
     report1 = db_spam_report.create(self.revision_id, self.user2.id, "This is a report")
     self.review.update(text="Updated Review")
     report2 = db_spam_report.create(self.review.last_revision.id, self.user1.id, "This is again a report on the updated review")
     # two reports on the old revision and one on the new revision.
     reports, count = db_spam_report.list_reports(review_id=self.review.id)
     self.assertEqual(count, 3)
     # get all reports by a user.
     reports, count = db_spam_report.list_reports(user_id=self.user2.id)
     self.assertEqual(count, 1)
     # archive and include all archived reports.
     # there must be two reports including the archived one.
     db_spam_report.archive(self.user1.id, self.review.last_revision.id)
     reports, count = db_spam_report.list_reports(inc_archived=True)
     self.assertEqual(count, 3)
     # there must be one reports excluding the archived one.
     reports, count = db_spam_report.list_reports(inc_archived=False)
     self.assertEqual(count, 2)
예제 #5
0
    def test_delete(self):
        user1_id = self.user1.id
        db_users.delete(self.user1.id)
        # Votes should be deleted as well
        votes = db_users.get_votes(self.user1.id)
        self.assertEqual(len(votes), 0)
        # Spam Reports to be deleted as well
        spam_reports, count = db_spam_report.list_reports(user_id=user1_id)  # pylint: disable=unused-variable
        self.assertEqual(count, 0)

        db_users.delete(self.author.id)
        # Review should not exist
        reviews = db_users.get_reviews(self.author.id)
        self.assertEqual(len(reviews), 0)
예제 #6
0
 def test_list_reports(self):
     db_spam_report.create(self.revision_id, self.user2.id, "This is a report")
     db_review.update(
         review_id=self.review["id"],
         drafted=self.review["is_draft"],
         text="Updated Review",
     )
     self.review = db_review.get_by_id(self.review["id"])
     db_spam_report.create(self.review["last_revision"]["id"], self.user1.id, "This is again a report on the updated review")
     # two reports on the old revision and one on the new revision.
     reports, count = db_spam_report.list_reports(review_id=self.review["id"])  # pylint: disable=unused-variable
     self.assertEqual(count, 3)
     # get all reports by a user.
     reports, count = db_spam_report.list_reports(user_id=self.user2.id)
     self.assertEqual(count, 1)
     # archive and include all archived reports.
     # there must be two reports including the archived one.
     db_spam_report.archive(self.user1.id, self.review["last_revision"]["id"])
     reports, count = db_spam_report.list_reports(inc_archived=True)
     self.assertEqual(count, 3)
     # there must be one reports excluding the archived one.
     reports, count = db_spam_report.list_reports(inc_archived=False)
     self.assertEqual(count, 2)
예제 #7
0
    def test_delete(self):

        user1_id = self.user1.id
        db_users.delete(self.user1.id)
        # Votes should be deleted as well
        votes = db_users.get_votes(self.user1.id)
        self.assertEqual(len(votes), 0)
        # Spam Reports to be deleted as well
        spam_reports, count = db_spam_report.list_reports(user_id=user1_id)  # pylint: disable=unused-variable
        self.assertEqual(count, 0)

        db_users.delete(self.author.id)
        # Review should not exist
        reviews = db_users.get_reviews(self.author.id)
        self.assertEqual(len(reviews), 0)
예제 #8
0
def hide(id):
    review = get_review_or_404(id)
    if review["is_hidden"]:
        flash.info(gettext("Review is already hidden."))
        return redirect(url_for('.entity', id=review["id"]))

    form = AdminActionForm()
    if form.validate_on_submit():
        db_review.set_hidden_state(review["id"], is_hidden=True)
        db_moderation_log.create(admin_id=current_user.id, action=ACTION_HIDE_REVIEW,
                                 reason=form.reason.data, review_id=review["id"])
        review_reports, count = db_spam_report.list_reports(review_id=review["id"])  # pylint: disable=unused-variable
        for report in review_reports:
            db_spam_report.archive(report["user_id"], report["revision_id"])
        flash.success(gettext("Review has been hidden."))
        return redirect(url_for('.entity', id=review["id"]))

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

    if review.is_hidden:
        flash.info(gettext("Review is already hidden."))
        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 db_spam_report.list_reports(review_id=review.id):
            db_spam_report.archive(report["user_id"], report["revision_id"])
        flash.success(gettext("Review has been hidden."))
        return redirect(url_for('.entity', id=review.id))

    return render_template('log/action.html',
                           review=review,
                           form=form,
                           action=ACTION_HIDE_REVIEW)
예제 #10
0
def more():
    page = int(request.args.get('page', default=0))
    offset = page * RESULTS_LIMIT
    results, count = db_spam_report.list_reports(offset=offset, limit=RESULTS_LIMIT, inc_archived=False)
    template = render_template('reports/reports_results.html', results=results)
    return jsonify(results=template, more=(count - offset - RESULTS_LIMIT) > 0)
예제 #11
0
def index():
    results, count = db_spam_report.list_reports(limit=RESULTS_LIMIT, inc_archived=False)
    return render_template('reports/reports.html', count=count, results=results, limit=RESULTS_LIMIT)