예제 #1
0
파일: board.py 프로젝트: peremen/noah3k
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)
예제 #2
0
파일: web_board.py 프로젝트: peremen/noah3k
    def modify_post(self, board_name, board_id, current_uid = -1):
        board_info = board.get_board_info(board_id)
        if not acl.is_allowed('board', board_id, current_uid, 'modify'):
            return util.render().error(error_message=_('NO_PERMISSION'), help_context='error')
        data = web.input()
        comment = 1 if data.has_key('commentable') else 0
        write_by_other = 1 if data.has_key('writable') else 0
        indexable = 1 if data.has_key('indexable') else 0
        show_avatar = 1 if data.has_key('show_avatar') else 0

        owner_uid = user._get_uid_from_username(web.input().owner)
        if owner_uid < 0:
            return util.render().error(error_message=_('NO_SUCH_USER_FOR_BOARD_ADMIN'), help_context='error')

        board_info = dict(path = data.path, name = data.name,
                owner = owner_uid, board_type = int(data.type),
                can_comment = comment, can_write_by_other = write_by_other,
                indexable = indexable, show_avatar = show_avatar,
                stylesheet = data.stylesheet,
                description = data.description,
                cover = data.information)
        result = board.board_edit(current_uid, board_id, board_info)
        if result[0] == False:
            return util.render().error(error_message = result[1], help_context='error')
        else:
            raise web.seeother(util.link('%s') % result[1])
예제 #3
0
파일: web_board.py 프로젝트: peremen/noah3k
    def create_board_post(self, board_name, board_id, current_uid = -1):
        board_info = board.get_board_info(board_id)
        if not acl.is_allowed('board', board_id, current_uid, 'create'):
            return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
        user_data = web.input()
        comment = 1 if user_data.has_key('commentable') else 0
        write_by_other = 1 if user_data.has_key('writable') else 0
        indexable = 1 if user_data.has_key('indexable') else 0
        show_avatar = 1 if user_data.has_key('show_avatar') else 0

        owner_uid = user._get_uid_from_username(user_data.owner)
        if owner_uid < 0:
            return util.render().error(error_message=_('NO_SUCH_USER_FOR_BOARD_ADMIN'), help_context='error')
        if user_data.name.strip() == '':
            return util.render().error(error_message = _('NO_NAME_SPECIFIED'), help_context='error')
        if board_name == '^root':
            new_path = posixpath.join('/', user_data.name)
        else:
            new_path = posixpath.join('/', board_name, user_data.name)
        if board._get_board_id_from_path(new_path) > 0:
            return util.render().error(error_message = _('BOARD_EXISTS'), help_context='error')

        settings = dict(path=new_path, board_owner = owner_uid,
                cover = user_data.information,
                description = user_data.description,
                type = int(user_data.type),
                guest_write = write_by_other,
                can_comment = comment,
                indexable = indexable, show_avatar = show_avatar,
                current_uid = current_uid)
        ret = board.create_board(board_id, settings)
        if ret[0] == False:
            return util.render().error(error_message = ret[1] ,help_context = 'error')
        raise web.seeother(util.link('%s') % (new_path))
예제 #4
0
파일: board.py 프로젝트: peremen/noah3k
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')
예제 #5
0
 def delete_post(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('article', article_id, current_uid, 'delete'):
         return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
     ret = article.delete_article(current_uid, article_id)
     attachment.remove_all_attachment(article_id)
     if ret[0] == True:
         raise web.seeother(util.link('/%s') % (board_name))
     else:
         return util.render().error(error_message = ret[1], help_context='error')
예제 #6
0
 def delete_get(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('article', article_id, current_uid, 'delete'):
         return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
     default_referer = os.path.join(util.link('/'), board_name, '+read', str(article_id))
     action=os.path.join(util.link('/'), board_name, '+delete', str(article_id))
     return util.render().question(
             question=_('Do you want to delete the article?'),
             board_path = board_name, 
             board_desc = _('Confirmation'), title=_('Confirmation'),
             action = action,
             referer=web.ctx.env.get('HTTP_REFERER', default_referer))
예제 #7
0
    def comment_post(self, board_name, board_id, article_id, current_uid = -1):
        if not acl.is_allowed('board', board_id, current_uid, 'comment'):
            return util.render().error(error_message=_('NO_PERMISSION'), help_context='error')
        comment = web.input().comment
        board_info = board.get_board_info(board_id)
        ret = article.write_comment(current_uid, board_id, article_id, comment)
        if ret[0] == True:
            user.update_unreaded_articles_board(current_uid, board_id)
            user.read_article(current_uid, ret[1])

            raise web.seeother(util.link('/%s/+read/%s') % (board_name, article_id))
        else:
            return util.render().error(error_message = ret[1], help_context='error')
예제 #8
0
파일: web_board.py 프로젝트: peremen/noah3k
    def modify_get(self, board_name, board_id, current_uid = -1):
        board_info = board.get_board_info(board_id)
        if not acl.is_allowed('board', board_id, current_uid, 'modify'):
            return util.render().error(error_message=_('NO_PERMISSION'), help_context='error')
        if board_id == 1:
            board_name = '^root'
        default_referer = posixpath.join(util.link('/'), board_name, '+summary')

        return util.render().board_edit(
                action='modify', board_info = board_info,
                board_path = board_name, 
                board_desc = board_info.bDescription, 
                stylesheet = board_info.stylesheet,
                title = _('Modify information - %s') % (board_info.bName),
                referer = web.ctx.env.get('HTTP_REFERER', default_referer))
예제 #9
0
 def modify_get(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('article', article_id, current_uid, 'modify'):
         return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
     board_info = board.get_board_info(board_id)
     board_desc = board_info.bDescription
     article_ = article.get_article(board_id, article_id)
     uploads = attachment.get_attachment(article_id)
     return util.render().article_edit(
             title = _('Modify - /%s')% board_name,
             stylesheet = board_info.stylesheet,
             action='modify/%s' % article_id, 
             action_name = _('Modify article'),
             board_path = board_name, board_desc = board_desc,
             article_title = article_.aTitle, body = article_.aContent,
             attachment = uploads, help_context = 'article_edit')
예제 #10
0
 def reply_get(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('board', board_id, current_uid, 'write'):
         return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
     board_info = board.get_board_info(board_id)
     board_desc = board_info.bDescription
     user_info = user.get_user(current_uid)[1]
     article_ = article.get_article(board_id, article_id)
     quote_text = _('From %s\'s Article %s:') % (user._get_username_from_uid(article_.uSerial), util.remove_bracket(article_.aTitle))
     body = '\n\n\n[quote=%s]%s\n[/quote]\n\n%s' % (quote_text, article_.aContent, user_info.uSig)
     return util.render().article_edit(
             title = _('Reply - /%s') % board_name,
             stylesheet = board_info.stylesheet,
             action='reply/%s' % article_id, 
             action_name = _('Reply to the article'),
             board_path = board_name, board_desc = board_desc,
             body = body, article_title = article_.aTitle,
             help_context = 'article_edit')
예제 #11
0
파일: board.py 프로젝트: peremen/noah3k
def delete_board(current_uid, board_id):
    original_board_info = get_board_info(board_id)
    old_path = original_board_info.bName
    if not acl.is_allowed('board', board_id, current_uid, 'delete'):
        return (False, _('NO_PERMISSION'))
    val = dict(old_path = old_path + r'/%')
    has_child = False
    result = db.select('Boards', val, where = 'bName LIKE $old_path')
    for r in result:
        if (r.bName == old_path) or (not r.bName.startswith(old_path)):
            continue
        has_child = True
    if has_child:
        return (False, _('HAS_CHILD'))
    val = dict(board_id = board_id)
    result = db.delete('Boards', vars=val, where='bSerial = $board_id')
    delete_all_article(board_id)
    return (True, posixpath.dirname(old_path))
예제 #12
0
    def modify_post(self, board_name, board_id, article_id, current_uid = -1):
        if not acl.is_allowed('article', article_id, current_uid, 'modify'):
            return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
        data = web.input(new_attachment= {})
        fs = web.ctx.get('_fieldstorage')
        try:
            if fs.has_key('delete'):
                to_delete = fs['delete']
                if type(to_delete) == list:
                    for f in to_delete:
                        attachment.remove_attachment(article_id, f.value)
                else:
                    try:
                        attachment.remove_attachment(article_id, to_delete.value)
                    except:
                        pass
            if fs.has_key('new_attachment'):
                new_attachment = fs['new_attachment']
                if type(new_attachment) == list:
                    for f in new_attachment:
                        attachment.add_attachment(article_id, f.filename, f.value)
                else:
                    try:
                        attachment.add_attachment(article_id, new_attachment.filename, new_attachment.value)
                    except:
                        pass
        except:
            pass

        mark_as_unreaded = web.input().has_key('unreaded')

        a = dict(title = data.title, body = data.content)
        board_info = board.get_board_info(board_id)
        ret = article.modify_article(current_uid, board_id, article_id, a, mark_as_unreaded)
        if ret[0] == True:
            raise web.seeother(util.link('/%s/+read/%s') % (board_name, ret[1]))
        else:
            return util.render().error(error_message = ret[1], help_context='error')
예제 #13
0
 def reply_post(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('board', board_id, current_uid, 'write'):
         return util.render().error(error_message = _('NO_PERMISSION'), help_context = 'error')
     reply = dict(title = web.input().title, body = web.input().content)
     board_info = board.get_board_info(board_id)
     ret = article.reply_article(current_uid, board_id, article_id, reply)
     if ret[0] == True:
         fs = web.ctx.get('_fieldstorage')
         try:
             if fs.has_key('new_attachment'):
                 new_attachment = fs['new_attachment']
                 if type(new_attachment) == list:
                     for f in new_attachment:
                         attachment.add_attachment(ret[1], f.filename, f.value)
                 else:
                     try:
                         attachment.add_attachment(ret[1], new_attachment.filename, new_attachment.value)
                     except:
                         pass
         except:
             pass
         raise web.seeother(util.link('/%s/+read/%s') % (board_name, ret[1]))
     else:
         return util.render().error(error_message = ret[1], help_context='error')
예제 #14
0
 def unmark_get(self, board_name, board_id, article_id, current_uid = -1):
     if not acl.is_allowed('board', board_id, current_uid, 'mark'):
         return util.render().error(error_message=_('NO_PERMISSION'), help_context='error')
     article.unmark_article(article_id)
     raise web.seeother(util.link('/%s/+read/%s') % (board_name, article_id))