Example #1
0
def admin_add(uid):
    board = request.args.get('board', '')
    level = request.args.get('level', '1')
    try:
        validate_board(_('Board Name'), board)
        validate_uint(_('Administrator Level'), level)
    except ValidationError as err:
        return validation_err_response(err)

    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')))

    if level == '0':
        check = forum.admin_check(operator)
        if check[0] != 0:
            return json_response(check)
        if check[2]['admin']:
            return json_response(forum.admin_add(uid, board, int(level)))
        else:
            return json_response((254, _('Permission denied.')))
    else:
        check_site = forum.admin_check(operator)
        check_board = forum.admin_check(operator, board)
        if check_site[0] != 0:
            return json_response(check_site)
        if check_board[0] != 0:
            return json_response(check_board)
        if (check_site[2]['admin']
                or (check_board[2]['admin'] and check_board[2]['level'] == 0)):
            return json_response(forum.admin_add(uid, board, int(level)))
        else:
            return json_response((254, _('Permission denied.')))
Example #2
0
def admin_add(uid):
    board = request.args.get('board', '')
    level = request.args.get('level', '1')
    try:
        validate_board(_('Board Name'), board)
        validate_uint(_('Administrator Level'), level)
    except ValidationError as err:
        return validation_err_response(err)

    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')) )

    if level == '0':
        check = forum.admin_check(operator)
        if check[0] != 0:
            return json_response(check)
        if check[2]['admin']:
            return json_response(forum.admin_add(uid, board, int(level)) )
        else:
            return json_response((254, _('Permission denied.')) )
    else:
        check_site = forum.admin_check(operator)
        check_board = forum.admin_check(operator, board)
        if check_site[0] != 0:
            return json_response(check_site)
        if check_board[0] != 0:
            return json_response(check_board)
        if (
                check_site[2]['admin']
                or (check_board[2]['admin'] and check_board[2]['level'] == 0)
            ):
            return json_response(forum.admin_add(uid, board, int(level)) )
        else:
            return json_response((254, _('Permission denied.')) )
Example #3
0
def list_ban():
    board = request.args.get('board', '')
    pn = request.args.get('pn', '1')
    items_per_page = int(config['count_list_item'])
    is_admin = False
    uid = session.get('uid')
    if uid:
        admin_result = forum.admin_check(uid, board=board)
        if admin_result[0] != 0:
            return err_response(admin_result)
        global_result = forum.admin_check(uid)
        if global_result[0] != 0:
            return err_response(global_result)
        is_admin = admin_result[2]['admin'] or global_result[2]['admin']
    result = forum.ban_list(int(pn), items_per_page, board=board)
    if result[0] != 0:
        return err_response(result)
    else:
        return render_template(
            'list_ban.html',
            data = result[2],
            board = board,
            is_admin = is_admin,
            pn = int(pn),
            items_per_page = items_per_page
        )
Example #4
0
def topic(tid):
    pn = request.args.get('pn', '1')
    count_post = int(config['count_post'])

    try:
        validate_id(_('Page Number'), pn)
    except ValidationError as err:
        return validation_err_response(err, json=False)

    result_info = forum.topic_info(tid)
    if result_info[0] != 0:
        return err_response(result_info)
    topic_info = result_info[2]

    is_admin = False
    is_level0_admin = False
    uid = session.get('uid')
    if uid:
        result_admin_site = forum.admin_check(uid)
        if result_admin_site[0] != 0:
            return err_response(result_admin_site)
        result_admin = forum.admin_check(uid, topic_info['board'])
        if result_admin[0] != 0:
            return err_response(result_admin)
        if result_admin_site[2]['admin']:
            is_level0_admin = True
        elif result_admin[2]['admin']:
            is_level0_admin = (result_admin[2]['level'] == 0)
        else:
            is_level0_admin = False
        is_admin = (result_admin_site[2]['admin'] or result_admin[2]['admin'])

    result = forum.post_list(tid, int(pn), count_post)
    if result[0] != 0:
        return err_response(result)
    elif not result[2]['list']:
        return err_response((248, _('No such page.')) )
    else:
        data = result[2]
        for post in data['list']:
            result_subpost = forum.post_list(
                post['pid'], 1, COUNT_SUBPOST, subpost=True
            )
            if result_subpost[0] != 0:
                return err_response(result_subpost)
            post['subposts'] = result_subpost[2]
        return render_template(
            'topic_content.html',
            tid = tid,
            topic_info = topic_info,
            data = result[2],
            pn = int(pn),
            count_post = count_post,
            count_subpost = COUNT_SUBPOST,
            is_admin = is_admin,
            is_level0_admin = is_level0_admin
        )
Example #5
0
def topic(tid):
    pn = request.args.get('pn', '1')
    count_post = int(config['count_post'])

    try:
        validate_id(_('Page Number'), pn)
    except ValidationError as err:
        return validation_err_response(err, json=False)

    result_info = forum.topic_info(tid)
    if result_info[0] != 0:
        return err_response(result_info)
    topic_info = result_info[2]

    is_admin = False
    is_level0_admin = False
    uid = session.get('uid')
    if uid:
        result_admin_site = forum.admin_check(uid)
        if result_admin_site[0] != 0:
            return err_response(result_admin_site)
        result_admin = forum.admin_check(uid, topic_info['board'])
        if result_admin[0] != 0:
            return err_response(result_admin)
        if result_admin_site[2]['admin']:
            is_level0_admin = True
        elif result_admin[2]['admin']:
            is_level0_admin = (result_admin[2]['level'] == 0)
        else:
            is_level0_admin = False
        is_admin = (result_admin_site[2]['admin'] or result_admin[2]['admin'])

    result = forum.post_list(tid, int(pn), count_post)
    if result[0] != 0:
        return err_response(result)
    elif not result[2]['list']:
        return err_response((248, _('No such page.')))
    else:
        data = result[2]
        for post in data['list']:
            result_subpost = forum.post_list(post['pid'],
                                             1,
                                             COUNT_SUBPOST,
                                             subpost=True)
            if result_subpost[0] != 0:
                return err_response(result_subpost)
            post['subposts'] = result_subpost[2]
        return render_template('topic_content.html',
                               tid=tid,
                               topic_info=topic_info,
                               data=result[2],
                               pn=int(pn),
                               count_post=count_post,
                               count_subpost=COUNT_SUBPOST,
                               is_admin=is_admin,
                               is_level0_admin=is_level0_admin)
Example #6
0
def board_add_or_update():
    board = request.form.get('board', '')
    name = request.form.get('name', '')
    desc = request.form.get('desc', '')
    announce = request.form.get('announce', '')
    update = request.args.get('update', '')
    original_board = request.args.get('original', '')
    try:
        validate_board(_('URL Name'), board)
        validate(_('Name'), name, max=64, not_empty=True)
        validate(_('Description'), desc, max=255, not_empty=True)
        validate(_('Announcement'), announce)
        if update:
            validate_board(_('Original URL Name'), original_board)
    except ValidationError as err:
        return validation_err_response(err)
    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')))
    check = forum.admin_check(operator)
    if check[0] != 0:
        return json_response(check)
    if check[2]['admin']:
        if not update:
            return json_response(forum.board_add(board, name, desc, announce))
        else:
            return json_response(
                forum.board_update(original_board, board, name, desc,
                                   announce))
    else:
        return json_response((254, _('Permission denied.')))
Example #7
0
def board_add_or_update():
    board = request.form.get('board', '')
    name = request.form.get('name', '')
    desc = request.form.get('desc', '')
    announce = request.form.get('announce', '')
    update = request.args.get('update', '')
    original_board = request.args.get('original', '')
    try:
        validate_board(_('URL Name'), board)
        validate(_('Name'), name, max=64, not_empty=True)
        validate(_('Description'), desc, max=255, not_empty=True)
        validate(_('Announcement'), announce)
        if update:
            validate_board(_('Original URL Name'), original_board)
    except ValidationError as err:
        return validation_err_response(err)
    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')) )
    check = forum.admin_check(operator)
    if check[0] != 0:
        return json_response(check)
    if check[2]['admin']:
        if not update:
            return json_response(forum.board_add(board, name, desc, announce))
        else:
            return json_response(forum.board_update(
                original_board, board, name, desc, announce
            ))
    else:
        return json_response((254, _('Permission denied.')) )
Example #8
0
def admin_check(uid):
    board = request.args.get('board', '')
    try:
        if board:
            validate_board(_('Board Name'), board)
    except ValidationError as err:
        return validation_err_response(err)
    return json_response(forum.admin_check(uid, board))
Example #9
0
def admin_check(uid):
    board = request.args.get('board', '')
    try:
        if board:
            validate_board(_('Board Name'), board)
    except ValidationError as err:
        return validation_err_response(err)
    return json_response(forum.admin_check(uid, board))
Example #10
0
def admin_remove(uid):
    board = request.args.get('board', '')
    try:
        validate_board(_('Board Name'), board)
    except ValidationError as err:
        return validation_err_response(err)

    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')) )

    check = forum.admin_check(uid, board)
    if check[0] != 0:
        return json_response(check)
    if not check[2]['admin']:
        return json_response((4, _('No such board administrator.')) )
    if check[2]['level'] == 0:
        check_op = forum.admin_check(operator)
        if check_op[0] != 0:
            return json_response(check_op)
        if check_op[2]['admin']:
            return json_response(forum.admin_remove(uid, board))
        else:
            return json_response((254, _('Permission denied.')) )
    else:
        check_site = forum.admin_check(operator)
        check_board = forum.admin_check(operator, board)
        if check_site[0] != 0:
            return json_response(check_site)
        if check_board[0] != 0:
            return json_response(check_board)
        if (
                check_site[2]['admin']
                or (check_board[2]['admin'] and check_board[2]['level'] == 0)
           ):
            return json_response(forum.admin_remove(uid, board))
        else:
            return json_response((254, _('Permission denied.')) )
Example #11
0
def admin_remove(uid):
    board = request.args.get('board', '')
    try:
        validate_board(_('Board Name'), board)
    except ValidationError as err:
        return validation_err_response(err)

    operator = session.get('uid')
    if not operator:
        return json_response((254, _('Permission denied.')))

    check = forum.admin_check(uid, board)
    if check[0] != 0:
        return json_response(check)
    if not check[2]['admin']:
        return json_response((4, _('No such board administrator.')))
    if check[2]['level'] == 0:
        check_op = forum.admin_check(operator)
        if check_op[0] != 0:
            return json_response(check_op)
        if check_op[2]['admin']:
            return json_response(forum.admin_remove(uid, board))
        else:
            return json_response((254, _('Permission denied.')))
    else:
        check_site = forum.admin_check(operator)
        check_board = forum.admin_check(operator, board)
        if check_site[0] != 0:
            return json_response(check_site)
        if check_board[0] != 0:
            return json_response(check_board)
        if (check_site[2]['admin']
                or (check_board[2]['admin'] and check_board[2]['level'] == 0)):
            return json_response(forum.admin_remove(uid, board))
        else:
            return json_response((254, _('Permission denied.')))
Example #12
0
def list_ban():
    board = request.args.get('board', '')
    pn = request.args.get('pn', '1')
    items_per_page = int(config['count_list_item'])
    is_admin = False
    uid = session.get('uid')
    if uid:
        admin_result = forum.admin_check(uid, board=board)
        if admin_result[0] != 0:
            return err_response(admin_result)
        global_result = forum.admin_check(uid)
        if global_result[0] != 0:
            return err_response(global_result)
        is_admin = admin_result[2]['admin'] or global_result[2]['admin']
    result = forum.ban_list(int(pn), items_per_page, board=board)
    if result[0] != 0:
        return err_response(result)
    else:
        return render_template('list_ban.html',
                               data=result[2],
                               board=board,
                               is_admin=is_admin,
                               pn=int(pn),
                               items_per_page=items_per_page)
Example #13
0
def check_permission(operator, board, level0=False):
    '''Check if `operator` is administrator of `board` ('' means global)

    @param int operator
    @param str board
    @return bool
    '''
    check_global = forum.admin_check(operator)
    if check_global[0] != 0:
        raise ForumPermissionCheckError(check_global)
    if not board:
        return check_global[2]['admin']
    else:
        check = forum.admin_check(operator, board)
        if check[0] != 0:
            raise ForumPermissionCheckError(check)
        if not check[2]['admin']:
            board_admin = False
        else:
            if level0:
                board_admin = (check[2]['level'] == 0)
            else:
                board_admin = True
        return (check_global[2]['admin'] or board_admin)
Example #14
0
def check_permission(operator, board, level0=False):
    '''Check if `operator` is administrator of `board` ('' means global)

    @param int operator
    @param str board
    @return bool
    '''
    check_global = forum.admin_check(operator)
    if check_global[0] != 0:
        raise ForumPermissionCheckError(check_global)
    if not board:
        return check_global[2]['admin']
    else:
        check = forum.admin_check(operator, board)
        if check[0] != 0:
            raise ForumPermissionCheckError(check)
        if not check[2]['admin']:
            board_admin = False
        else:
            if level0:
                board_admin = (check[2]['level'] == 0)
            else:
                board_admin = True
        return (check_global[2]['admin'] or board_admin)
Example #15
0
def user(name):
    current_user = session.get('uid')
    if current_user:
        check_result = forum.admin_check(current_user)
        if check_result[0] != 0:
            return err_response(check_result)
        else:
            is_admin = check_result[2]['admin']
    else:
        is_admin = False
    result = forum.user_info(name)
    if result[0] != 0:
        return err_response(result)
    else:
        return render_template('user_info.html',
                               name=name,
                               data=result[2],
                               is_admin=is_admin)
Example #16
0
def user(name):
    current_user = session.get('uid')
    if current_user:
        check_result = forum.admin_check(current_user)
        if check_result[0] != 0:
            return err_response(check_result)
        else:
            is_admin = check_result[2]['admin']
    else:
        is_admin = False
    result = forum.user_info(name)
    if result[0] != 0:
        return err_response(result)
    else:
        return render_template(
            'user_info.html',
            name = name,
            data = result[2],
            is_admin = is_admin
        )