Ejemplo n.º 1
0
def unreport(things, correct=False, auto = False, banned_by = ''):
    things = tup(things)

    # load authors (to set the spammer flag)
    try:
        aids = set(t.author_id for t in things)
    except AttributeError:
        aids = None

    authors = Account._byID(tuple(aids), data=True) if aids else {}


    # load all reports (to set their amount to be +/-1)
    reports = Report.reported(things=things, amount = 0)

    # mark the reports as finalized:
    for r in reports.values(): Report.accept(r, correct)

    amount = 1 if correct else -1

    spammer = {}
    for t in things:
        # clean up inconsistencies
        if getattr(t, Report._field) != 0:
            setattr(t, Report._field, 0)
            t._commit()
            # flag search indexer that something has changed
            tc.changed(t)
            
        # update the spam flag
        if t._spam != correct and hasattr(t, 'author_id'):
            # tally the spamminess of the author
            spammer[t.author_id] = spammer.get(t.author_id,0) + amount
            #author = authors.get(t.author_id)
            #if author:
            #    karma_whack(author, t.__class__, -amount)

    #will be empty if the items didn't have authors
    for s, v in spammer.iteritems():
        if authors[s].spammer + v >= 0:
            authors[s]._incr('spammer', v)
            
    # mark all as spam
    admintools.spam(things, amount = amount, auto = auto, banned_by = banned_by)
Ejemplo n.º 2
0
def unreport(things, correct=False, auto=False, banned_by=''):
    things = tup(things)

    # load authors (to set the spammer flag)
    try:
        aids = set(t.author_id for t in things)
    except AttributeError:
        aids = None

    authors = Account._byID(tuple(aids), data=True) if aids else {}

    # load all reports (to set their amount to be +/-1)
    reports = Report.reported(things=things, amount=0)

    # mark the reports as finalized:
    for r in reports.values():
        Report.accept(r, correct)

    amount = 1 if correct else -1

    spammer = {}
    for t in things:
        # clean up inconsistencies
        if getattr(t, Report._field) != 0:
            setattr(t, Report._field, 0)
            t._commit()
            # flag search indexer that something has changed
            tc.changed(t)

        # update the spam flag
        if t._spam != correct and hasattr(t, 'author_id'):
            # tally the spamminess of the author
            spammer[t.author_id] = spammer.get(t.author_id, 0) + amount
            #author = authors.get(t.author_id)
            #if author:
            #    karma_whack(author, t.__class__, -amount)

    #will be empty if the items didn't have authors
    for s, v in spammer.iteritems():
        if authors[s].spammer + v >= 0:
            authors[s]._incr('spammer', v)

    # mark all as spam
    admintools.spam(things, amount=amount, auto=auto, banned_by=banned_by)
Ejemplo n.º 3
0
    def _new(cls, author, link, parent, body, ip, spam = False, date = None):
        comment = Comment(body = body,
                          link_id = link._id,
                          sr_id = link.sr_id,
                          author_id = author._id,
                          ip = ip,
                          date = date)

        comment._spam = spam

        #these props aren't relations
        if parent:
            comment.parent_id = parent._id

        comment._commit()

        link._incr('num_comments', 1)

        inbox_rel = None
        if parent:
            to = Account._byID(parent.author_id)
            # only global admins can be message spammed.
            if not comment._spam or to.name in g.admins:
                inbox_rel = Inbox._add(to, comment, 'inbox')

        #clear that chache
        clear_memo('builder.link_comments2', link._id)

        # flag search indexer that something has changed
        tc.changed(comment)

        #update last modified
        set_last_modified(author, 'overview')
        set_last_modified(author, 'commented')
        set_last_modified(link, 'comments')

        #update the comment cache
        from r2.lib.comment_tree import add_comment
        add_comment(comment)

        return (comment, inbox_rel)
Ejemplo n.º 4
0
    def _new(cls, author, link, parent, body, ip, spam=False, date=None):
        comment = Comment(body=body,
                          link_id=link._id,
                          sr_id=link.sr_id,
                          author_id=author._id,
                          ip=ip,
                          date=date)

        comment._spam = spam

        #these props aren't relations
        if parent:
            comment.parent_id = parent._id

        comment._commit()

        link._incr('num_comments', 1)

        inbox_rel = None
        if parent:
            to = Account._byID(parent.author_id)
            # only global admins can be message spammed.
            if not comment._spam or to.name in g.admins:
                inbox_rel = Inbox._add(to, comment, 'inbox')

        #clear that chache
        clear_memo('builder.link_comments2', link._id)

        # flag search indexer that something has changed
        tc.changed(comment)

        #update last modified
        set_last_modified(author, 'overview')
        set_last_modified(author, 'commented')
        set_last_modified(link, 'comments')

        #update the comment cache
        from r2.lib.comment_tree import add_comment
        add_comment(comment)

        return (comment, inbox_rel)
Ejemplo n.º 5
0
    def _new(cls, author, link, parent, body, ip, spam = False, date = None):
        comment = Comment(body = body,
                          link_id = link._id,
                          sr_id = link.sr_id,
                          author_id = author._id,
                          ip = ip,
                          date = date)

        comment._spam = spam

        #these props aren't relations
        if parent:
            comment.parent_id = parent._id

        comment._commit()

        link._incr('num_comments', 1)

        inbox_rel = comment._send_post_notifications(link, comment, parent)

        #clear that chache
        clear_memo('builder.link_comments2', link._id)

        # flag search indexer that something has changed
        tc.changed(comment)

        #update last modified
        set_last_modified(author, 'overview')
        set_last_modified(author, 'commented')
        set_last_modified(link, 'comments')

        #update the comment cache
        from r2.lib.comment_tree import add_comment
        add_comment(comment)

        return (comment, inbox_rel)
Ejemplo n.º 6
0
    def _new(cls, author, link, parent, body, ip, spam=False, date=None):
        comment = Comment(body=body,
                          link_id=link._id,
                          sr_id=link.sr_id,
                          author_id=author._id,
                          ip=ip,
                          date=date)

        comment._spam = spam

        #these props aren't relations
        if parent:
            comment.parent_id = parent._id

        comment._commit()

        link._incr('num_comments', 1)

        inbox_rel = comment._send_post_notifications(link, comment, parent)

        #clear that chache
        clear_memo('builder.link_comments2', link._id)

        # flag search indexer that something has changed
        tc.changed(comment)

        #update last modified
        set_last_modified(author, 'overview')
        set_last_modified(author, 'commented')
        set_last_modified(link, 'comments')

        #update the comment cache
        from r2.lib.comment_tree import add_comment
        add_comment(comment)

        return (comment, inbox_rel)