<commit_before>import string
import time

import bcrypt
from sqlalchemy import desc
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

from unichan.database import get_db
from unichan.lib import ArgumentError
from unichan.lib import roles
from unichan.lib.models import Moderator, Report, Post, Thread, Board
from unichan.lib.models.board import board_moderator_table


def now():
    return int(time.time() * 1000)


class ModeratorService:
    USERNAME_MAX_LENGTH = 50
    USERNAME_ALLOWED_CHARS = string.ascii_letters + string.digits + '_'
    PASSWORD_MAX_LENGTH = 50
    PASSWORD_ALLOWED_CHARS = string.ascii_letters + string.digits + string.punctuation + '_'

    def __init__(self, cache):
        self.cache = cache

    def add_report(self, report):
        db = get_db()

        exiting_report = None
        try:
            exiting_report = db.query(Report).filter_by(post_id=report.post_id).one()
        except NoResultFound:
            pass

        if exiting_report is not None:
            exiting_report.count += 1
        else:
            report.count = 1
            db.add(report)

        report.date = now()

        db.commit()

    def get_reports(self, moderator):
        db = get_db()

        # Query that gets all reports for the moderator id and sorts by date desc
        reports = db.query(Report).filter(Report.post_id == Post.id, Post.thread_id == Thread.id,
                                          Thread.board_id == Board.id, Board.id == board_moderator_table.c.board_id,
                                          board_moderator_table.c.moderator_id == moderator.id) \
            .order_by(desc(Report.date)).all()

        return reports

    def can_delete(self, moderator, post):
        return self.moderates_board(moderator, post.thread.board)

    def check_username_validity(self, username):<commit_msg>Show all reports for admins<commit_after>import string
import time

import bcrypt
from sqlalchemy import desc
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

from unichan.database import get_db
from unichan.lib import ArgumentError
from unichan.lib import roles
from unichan.lib.models import Moderator, Report, Post, Thread, Board
from unichan.lib.models.board import board_moderator_table


def now():
    return int(time.time() * 1000)


class ModeratorService:
    USERNAME_MAX_LENGTH = 50
    USERNAME_ALLOWED_CHARS = string.ascii_letters + string.digits + '_'
    PASSWORD_MAX_LENGTH = 50
    PASSWORD_ALLOWED_CHARS = string.ascii_letters + string.digits + string.punctuation + '_'

    def __init__(self, cache):
        self.cache = cache

    def add_report(self, report):
        db = get_db()

        exiting_report = None
        try:
            exiting_report = db.query(Report).filter_by(post_id=report.post_id).one()
        except NoResultFound:
            pass

        if exiting_report is not None:
            exiting_report.count += 1
        else:
            report.count = 1
            db.add(report)

        report.date = now()

        db.commit()

    def get_reports(self, moderator):
        db = get_db()

        reports_query = db.query(Report)
        # Show all reports when the moderator has the admin role
        if not self.has_role(moderator, roles.ROLE_ADMIN):
            # Filter that gets all reports for the moderator id
            reports_query = reports_query.filter(Report.post_id == Post.id, Post.thread_id == Thread.id,
                                                 Thread.board_id == Board.id, Board.id == board_moderator_table.c.board_id,
                                                 board_moderator_table.c.moderator_id == moderator.id)

        reports_query = reports_query.order_by(desc(Report.date))
        reports = reports_query.all()

        return reports

    def can_delete(self, moderator, post):
        return self.moderates_board(moderator, post.thread.board)

    def check_username_validity(self, username):
{'fraction_non_alphanumeric': 0.08030830432620586, 'fraction_numerical': 0.004972650422675286, 'mean_word_length': 2.5166083916083917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236552', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1155, 'n_words': 287}