예제 #1
0
파일: shout.py 프로젝트: charmander/weasyl
def remove(userid, commentid=None):
    query = d.execute(
        "SELECT userid, target_user, settings FROM comments WHERE commentid = %i AND settings !~ 'h'",
        [commentid], ["single"])

    if not query or ('s' in query[2] and userid not in staff.MODS):
        raise WeasylError("shoutRecordMissing")

    if userid != query[1] and userid not in staff.MODS:
        if userid != query[0]:
            raise WeasylError("InsufficientPermissions")

        # user is commenter
        replies = d.execute(
            "SELECT commentid FROM comments WHERE parentid = %d", [commentid])
        if replies:
            # a commenter cannot remove their comment if it has replies
            raise WeasylError("InsufficientPermissions")

    # remove notifications
    welcome.comment_remove(commentid, 'shout')
    d._page_header_info.invalidate(userid)

    # hide comment
    d.execute("UPDATE comments SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i", [userid, commentid])

    return query[1]
예제 #2
0
파일: shout.py 프로젝트: weykent/weasyl
def remove(userid, commentid=None):
    query = d.execute(
        "SELECT userid, target_user, settings FROM comments WHERE commentid = %i AND settings !~ 'h'",
        [commentid], ["single"])

    if not query or ('s' in query[2] and userid not in staff.MODS):
        raise WeasylError("shoutRecordMissing")

    if userid != query[1] and userid not in staff.MODS:
        if userid != query[0]:
            raise WeasylError("InsufficientPermissions")

        # user is commenter
        replies = d.execute(
            "SELECT commentid FROM comments WHERE parentid = %d", [commentid])
        if replies:
            # a commenter cannot remove their comment if it has replies
            raise WeasylError("InsufficientPermissions")

    # remove notifications
    welcome.comment_remove(commentid, 'shout')
    d._page_header_info.invalidate(userid)

    # hide comment
    d.execute(
        "UPDATE comments SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i",
        [userid, commentid])

    return query[1]
예제 #3
0
파일: comment.py 프로젝트: Syfaro/weasyl
def remove(userid, feature=None, commentid=None):

    if feature not in ["submit", "char", "journal"]:
        raise WeasylError("Unexpected")

    if feature == 'submit':
        query = d.execute(
            "SELECT userid, target_sub FROM comments WHERE commentid = %i AND settings !~ 'h'",
            [commentid], ["single"])
    else:
        query = d.execute(
            "SELECT userid, targetid FROM %scomment WHERE commentid = %i AND settings !~ 'h'",
            [feature, commentid], ["single"])

    if not query or query[1] is None:
        raise WeasylError("RecordMissing")

    target_table = {
        "submit": "submission",
        "char": "character",
        "journal": "journal",
    }

    owner = d.execute(
        "SELECT userid FROM %s WHERE %sid = %i",
        [target_table[feature], feature, query[1]], ["single"])
    is_owner = userid == owner[0]

    if not is_owner and userid not in staff.MODS:
        if userid != query[0]:
            raise WeasylError('InsufficientPermissions')

        # user is commenter
        comment_table = (
            "comments" if feature == 'submit' else feature + "comment")
        replies = d.execute(
            "SELECT commentid FROM %s WHERE parentid = %d",
            [comment_table, commentid])
        if replies:
            # a commenter cannot remove their comment if it has replies
            raise WeasylError("InsufficientPermissions")

    # remove notifications
    welcome.comment_remove(commentid, feature)
    d._page_header_info.invalidate(userid)

    # mark comments as hidden
    if feature == 'submit':
        d.execute(
            "UPDATE comments SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i",
            [userid, commentid])
    else:
        d.execute(
            "UPDATE %scomment SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i",
            [feature, userid, commentid])

    return query[1]
예제 #4
0
파일: comment.py 프로젝트: taedixon/weasyl
def remove(userid, feature=None, commentid=None):

    if feature not in ["submit", "char", "journal"]:
        raise WeasylError("Unexpected")

    if feature == 'submit':
        query = d.execute(
            "SELECT userid, target_sub FROM comments WHERE commentid = %i AND settings !~ 'h'",
            [commentid], ["single"])
    else:
        query = d.execute(
            "SELECT userid, targetid FROM %scomment WHERE commentid = %i AND settings !~ 'h'",
            [feature, commentid], ["single"])

    if not query or query[1] is None:
        raise WeasylError("RecordMissing")

    target_table = {
        "submit": "submission",
        "char": "character",
        "journal": "journal",
    }

    owner = d.execute("SELECT userid FROM %s WHERE %sid = %i",
                      [target_table[feature], feature, query[1]], ["single"])
    is_owner = userid == owner[0]

    if not is_owner and userid not in staff.MODS:
        if userid != query[0]:
            raise WeasylError('InsufficientPermissions')

        # user is commenter
        comment_table = ("comments" if feature == 'submit' else feature +
                         "comment")
        replies = d.execute("SELECT commentid FROM %s WHERE parentid = %d",
                            [comment_table, commentid])
        if replies:
            # a commenter cannot remove their comment if it has replies
            raise WeasylError("InsufficientPermissions")

    # remove notifications
    welcome.comment_remove(commentid, feature)
    d._page_header_info.invalidate(userid)

    # mark comments as hidden
    if feature == 'submit':
        d.execute(
            "UPDATE comments SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i",
            [userid, commentid])
    else:
        d.execute(
            "UPDATE %scomment SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i",
            [feature, userid, commentid])

    return query[1]
예제 #5
0
def remove(userid, feature=None, commentid=None):
    if feature not in ["submit", "char", "journal", "siteupdate"]:
        raise WeasylError("Unexpected")

    if feature == 'submit':
        query = d.engine.execute(
            "SELECT userid, target_sub FROM comments WHERE commentid = %(comment)s AND target_sub IS NOT NULL AND settings !~ 'h'",
            comment=commentid,
        ).first()
    elif feature == 'siteupdate':
        query = d.engine.execute(
            "SELECT userid, targetid FROM siteupdatecomment WHERE commentid = %(comment)s AND hidden_at IS NULL",
            comment=commentid,
        ).first()
    else:
        query = d.engine.execute(
            "SELECT userid, targetid FROM {feature}comment WHERE commentid = %(comment)s AND settings !~ 'h'"
            .format(feature=feature),
            comment=commentid,
        ).first()

    if not query:
        raise WeasylError("RecordMissing")

    target_table = {
        "submit": "submission",
        "char": "character",
        "journal": "journal",
    }

    if feature == 'siteupdate':
        is_owner = False
    else:
        owner = d.engine.scalar(
            "SELECT userid FROM {table} WHERE {feature}id = %(target)s".format(
                table=target_table[feature], feature=feature),
            target=query[1],
        )
        is_owner = userid == owner

    if not is_owner and userid not in staff.MODS:
        if userid != query[0]:
            raise WeasylError('InsufficientPermissions')

        # user is commenter
        comment_table = ("comments" if feature == 'submit' else feature +
                         "comment")
        has_replies = d.engine.scalar(
            "SELECT EXISTS (SELECT FROM {table} WHERE parentid = %(comment)s AND settings !~ 'h')"
            .format(table=comment_table),
            comment=commentid)
        if has_replies:
            # a commenter cannot remove their comment if it has replies
            raise WeasylError("InsufficientPermissions")

    # remove notifications
    welcome.comment_remove(commentid, feature)
    d._page_header_info.invalidate(userid)

    # mark comments as hidden
    if feature == 'submit':
        d.engine.execute(
            "UPDATE comments SET settings = settings || 'h', hidden_by = %(hidden_by)s WHERE commentid = %(comment)s",
            comment=commentid,
            hidden_by=userid,
        )
    elif feature == 'siteupdate':
        d.engine.execute(
            "UPDATE siteupdatecomment SET hidden_at = now(), hidden_by = %(hidden_by)s WHERE commentid = %(comment)s",
            comment=commentid,
            hidden_by=userid,
        )
    else:
        d.engine.execute(
            "UPDATE {feature}comment SET settings = settings || 'h', hidden_by = %(hidden_by)s WHERE commentid = %(comment)s"
            .format(feature=feature),
            comment=commentid,
            hidden_by=userid,
        )

    return query[1]