Beispiel #1
0
def create_board(parent_id, settings):
    original_board_info = get_board_info(parent_id)
    if original_board_info == None:
        return (False, _('NO_SUCH_BOARD'))
    if not util.validate_boardname(settings['path']):
        return (False, _('INVALID_BOARDNAME'))
    check = _get_board_id_from_path(settings['path'])
    if check > 0:
        return (False, _('BOARD_ALREADY_EXIST'))
    if not acl.is_allowed('board', parent_id, settings['current_uid'], 'create'):
        return (False, _('NO_PERMISSION'))
    if settings['type'] == 2:
        if _get_board_id_from_path(settings['description']) < 0 or settings['description'].strip() == '':
            return (False, _('NO_SUCH_BOARD'))

    t = db.transaction()
    try:
        ret = db.insert('Boards', bName = settings['path'],
                uSerial = settings['board_owner'],
                bParent = parent_id, bDatetime = web.SQLLiteral('NOW()'),
                bInformation = settings['cover'],
                bDescription = settings['description'],
                bType = settings['type'],
                bReply = 1, bWrite = settings['guest_write'],
                bComment = settings['can_comment'],
                indexable = settings['indexable'], show_avatar = settings['show_avatar'])
    except:
        t.rollback()
    else:
        t.commit()

    return (True, 'SUCCESS')
Beispiel #2
0
def board_edit(current_uid, board_id, settings):
    # settings로 넘어오는 내용
    # path, name: 보드 전체 경로
    # description: 보드 짧은 설명
    # owner: 보대 ID. uid로 변환해야 함.
    # cover: 긴 설명, cover에 들어가는 내용
    # board_type: 0 - 폴더, 1 - 게시판
    # can_write_by_other: 쓰기 가능/불가능
    # can_comment: 0 - 불가능, 1 - 가능
    # indexable: 0 - 검색 제외, 1 - 검색 포함
    # show_avatar: 0 - 안 보임, 1 - 보임
    if not acl.is_allowed('board', board_id, current_uid, 'edit'):
        return (False, _('NO_PERMISSION'))
    original_board_info = get_board_info(board_id)
    if original_board_info == None:
        return (False, _('NO_SUCH_BOARD'))
    settings['board_id'] = board_id
    new_path = posixpath.join(settings['path'], settings['name'])
    if not util.validate_boardname(new_path):
        return (False, _('INVALID_BOARDNAME'))
    if settings['board_type'] == 2:
        if article._get_article_count(board_id) > 0:
            return (False, _('ALIAS_CANT_HAVE_ARTICLE'))
        if _get_board_id_from_path(settings['description']) < 0 or settings['description'].strip() == '':
            return (False, _('NO_SUCH_BOARD'))
    old_path = original_board_info.bName
    old_directory = posixpath.dirname(old_path)
    new_directory = settings['path']
    if _get_board_id_from_path(new_path) > 0 and old_path != new_path:
        return (False, _('BOARD_ALREADY_EXIST'))
    new_parent_id = _get_board_id_from_path(settings['path'])
    if new_parent_id < 0:
        return (False, _('INVALID_PARENT'))
    if new_parent_id != original_board_info.bParent:
        if not acl.is_allowed('board', new_parent_id, current_uid, 'create'):
            return (False, _('NO_PERMISSION_ON_NEW_PARENT'))

    t = db.transaction()
    try:
        result = db.update('Boards', vars=settings, where='bSerial = $board_id',
                bInformation = settings['cover'], bDescription = settings['description'],
                bType = settings['board_type'], 
                bReply = 1, bComment = settings['can_comment'],
                indexable = settings['indexable'], 
                stylesheet = settings['stylesheet'],
                show_avatar = settings['show_avatar'],
                bWrite = settings['can_write_by_other'], 
                uSerial = settings['owner'],
                bName = new_path, bParent = new_parent_id)
        result = move_child_boards(board_id, old_path, new_path)
    except:
        t.rollback()
    else:
        t.commit()
    return (True, new_path)