Exemple #1
0
def _manage_report(details: ManagePostDetails, moderator: ModeratorModel, post: PostModel):
    action_authorizer.authorize_post_action(moderator, PostAction.POST_REPORT, post, details)

    report_service.report_post(post)

    message = 'post {} reported'.format(post.id)
    mod_log(message, ip4_str=ip4_to_str(details.ip4), moderator=moderator)
Exemple #2
0
def _manage_locked_toggle(thread: ThreadModel, details: ManagePostDetails, moderator: ModeratorModel):
    action_authorizer.authorize_post_action(moderator, PostAction.THREAD_LOCKED_TOGGLE, board=thread.board)

    posts.update_thread_locked(thread, not thread.locked)

    message = 'lock on /{}/{} {}'.format(thread.board.name, thread.id, 'disabled' if thread.locked else 'enabled')
    mod_log(message, ip4_str=ip4_to_str(details.ip4), moderator=moderator)
Exemple #3
0
def handle_manage_report(manage_report_details):
    report = reports.find_by_id(manage_report_details.report_id)
    if not report:
        raise ArgumentError(MESSAGE_REPORT_NOT_FOUND)

    moderator = moderator_service.find_moderator_id(manage_report_details.mod_id)
    if not moderator:
        raise ArgumentError(MESSAGE_MODERATOR_NOT_FOUND)

    post = report.post
    board = post.thread.board

    if manage_report_details.mode == ManageReportDetails.CLEAR:
        action_authorizer.authorize_report_action(moderator, board, report, ReportAction.REPORT_CLEAR)
        delete_report(report)

        message = 'Cleared report id {}'.format(report.id)
        moderator_service.log(ModeratorLogType.REPORT_CLEAR, moderator, board, message)
    elif manage_report_details.mode == ManageReportDetails.DELETE_POST:
        action_authorizer.authorize_post_action(moderator, PostAction.POST_DELETE, post)
        # Report gets deleted with a cascade
        posts_service.delete_post(post)

        message = 'Post id {}'.format(post.id)
        moderator_service.log(ModeratorLogType.REPORT_POST_DELETE, moderator, board, message)
    elif manage_report_details.mode == ManageReportDetails.DELETE_FILE:
        action_authorizer.authorize_post_action(moderator, PostAction.POST_DELETE_FILE, post)
        posts_service.delete_file(post)

        message = 'Post id {}'.format(post.id)
        moderator_service.log(ModeratorLogType.REPORT_POST_DELETE_FILE, moderator, board, message)
Exemple #4
0
def _manage_delete(details: ManagePostDetails, moderator: ModeratorModel, post: PostModel):
    try:
        action_authorizer.authorize_post_action(moderator, PostAction.POST_DELETE, post, details)

        message = 'post {} delete'.format(details.post_id)
        mod_log(message, ip4_str=ip4_to_str(details.ip4), moderator=moderator)

        posts.delete_post(post)
    except NoPermissionError as e:
        message = 'post {} delete failed, {}'.format(details.post_id, str(e))
        mod_log(message, ip4_str=ip4_to_str(details.ip4), moderator=moderator)

        raise BadRequestError(MESSAGE_DELETE_NO_PERMISSION)
Exemple #5
0
def _check_post_details(post_details: PostDetails, thread: ThreadModel,
                        board: BoardModel):
    plugin_manager.execute_hook('on_handle_post_check', post_details)

    # Get moderator if mod_id was set
    moderator = None
    if post_details.mod_id is not None:
        moderator = moderator_service.find_moderator_id(post_details.mod_id)
        if moderator is None:
            raise Exception(MESSAGE_MODERATOR_NOT_FOUND)

    if thread and thread.locked:
        raise ArgumentError(MESSAGE_THREAD_LOCKED)

    action_authorizer.authorize_post_action(moderator,
                                            PostAction.POST_CREATE,
                                            post_details=post_details,
                                            board=board,
                                            thread=thread)

    if post_details.has_file and not board.config.file_posting:
        raise ArgumentError(MESSAGE_FILE_POSTING_DISABLED)

    # Allow no text when an image is attached
    if (not post_details.text
            or not post_details.text.strip()) and not post_details.has_file:
        raise ArgumentError(MESSAGE_POST_NO_TEXT)

    if post_details.text is not None:
        if len(post_details.text) > MAX_TEXT_LENGTH:
            raise ArgumentError(MESSAGE_POST_TEXT_TOO_LONG)

        if len(post_details.text.splitlines()) > MAX_TEXT_LINES:
            raise ArgumentError(MESSAGE_POST_TEXT_TOO_MANY_LINES)

    if post_details.name is not None and len(
            post_details.name) > MAX_NAME_LENGTH:
        raise ArgumentError(MESSAGE_POST_NAME_TOO_LONG)

    if post_details.password is not None:
        if len(post_details.password) < MIN_PASSWORD_LENGTH:
            raise ArgumentError(
                MESSAGE_PASSWORD_TOO_SHORT.format(MIN_PASSWORD_LENGTH))

        if len(post_details.password) > MAX_PASSWORD_LENGTH:
            raise ArgumentError(
                MESSAGE_PASSWORD_TOO_LONG.format(MAX_PASSWORD_LENGTH))
Exemple #6
0
def handle_manage_report(manage_report_details):
    report = reports.find_by_id(manage_report_details.report_id)
    if not report:
        raise ArgumentError(MESSAGE_REPORT_NOT_FOUND)

    moderator = moderator_service.find_moderator_id(
        manage_report_details.mod_id)
    if not moderator:
        raise ArgumentError(MESSAGE_MODERATOR_NOT_FOUND)

    post = report.post
    board = post.thread.board

    if manage_report_details.mode == ManageReportDetails.CLEAR:
        action_authorizer.authorize_report_action(moderator, board, report,
                                                  ReportAction.REPORT_CLEAR)
        delete_report(report)

        message = 'Cleared report id {}'.format(report.id)
        moderator_service.log(ModeratorLogType.REPORT_CLEAR, moderator, board,
                              message)
    elif manage_report_details.mode == ManageReportDetails.DELETE_POST:
        action_authorizer.authorize_post_action(moderator,
                                                PostAction.POST_DELETE, post)
        # Report gets deleted with a cascade
        posts_service.delete_post(post)

        message = 'Post id {}'.format(post.id)
        moderator_service.log(ModeratorLogType.REPORT_POST_DELETE, moderator,
                              board, message)
    elif manage_report_details.mode == ManageReportDetails.DELETE_FILE:
        action_authorizer.authorize_post_action(moderator,
                                                PostAction.POST_DELETE_FILE,
                                                post)
        posts_service.delete_file(post)

        message = 'Post id {}'.format(post.id)
        moderator_service.log(ModeratorLogType.REPORT_POST_DELETE_FILE,
                              moderator, board, message)
Exemple #7
0
def _check_post_details(post_details: PostDetails, thread: ThreadModel, board: BoardModel):
    plugin_manager.execute_hook('on_handle_post_check', post_details)

    # Get moderator if mod_id was set
    moderator = None
    if post_details.mod_id is not None:
        moderator = moderator_service.find_moderator_id(post_details.mod_id)
        if moderator is None:
            raise Exception(MESSAGE_MODERATOR_NOT_FOUND)

    if thread and thread.locked:
        raise ArgumentError(MESSAGE_THREAD_LOCKED)

    action_authorizer.authorize_post_action(moderator, PostAction.POST_CREATE, post_details=post_details,
                                            board=board, thread=thread)

    if post_details.has_file and not board.config.file_posting:
        raise ArgumentError(MESSAGE_FILE_POSTING_DISABLED)

    # Allow no text when an image is attached
    if (not post_details.text or not post_details.text.strip()) and not post_details.has_file:
        raise ArgumentError(MESSAGE_POST_NO_TEXT)

    if post_details.text is not None:
        if len(post_details.text) > MAX_TEXT_LENGTH:
            raise ArgumentError(MESSAGE_POST_TEXT_TOO_LONG)

        if len(post_details.text.splitlines()) > MAX_TEXT_LINES:
            raise ArgumentError(MESSAGE_POST_TEXT_TOO_MANY_LINES)

    if post_details.name is not None and len(post_details.name) > MAX_NAME_LENGTH:
        raise ArgumentError(MESSAGE_POST_NAME_TOO_LONG)

    if post_details.password is not None:
        if len(post_details.password) < MIN_PASSWORD_LENGTH:
            raise ArgumentError(MESSAGE_PASSWORD_TOO_SHORT.format(MIN_PASSWORD_LENGTH))

        if len(post_details.password) > MAX_PASSWORD_LENGTH:
            raise ArgumentError(MESSAGE_PASSWORD_TOO_LONG.format(MAX_PASSWORD_LENGTH))