Ejemplo n.º 1
0
    def revoke_ballot(self, db_user: User, db_review: ReviewDuplicate):
        """
        Revokes/Undo the implications of any successfull reviewed element

        :param db_user:
        :param db_review:
        :return:
        """
        db_review = DBDiscussionSession.query(ReviewDuplicate).get(db_review.uid)
        db_review.set_revoked(True)
        self.__rebend_objects_of_review(db_review)
        db_review_canceled = ReviewCanceled(author=db_user.uid, review_data={key_duplicate: db_review.uid})
        DBDiscussionSession.add(db_review_canceled)
        DBDiscussionSession.flush()
        transaction.commit()
        return True
Ejemplo n.º 2
0
def __add_duplication_review(duplicate_statement_uid, original_statement_uid, user_uid):
    """
    Adds a ReviewDuplicate row

    :param duplicate_statement_uid: Statement.uid
    :param original_statement_uid: Statement.uid
    :param user_uid: User.uid
    :return: None
    """
    LOG.debug("Flag statement %s by user %s as duplicate of %s", duplicate_statement_uid, user_uid,
              original_statement_uid)
    review_duplication = ReviewDuplicate(detector=user_uid, duplicate_statement=duplicate_statement_uid,
                                         original_statement=original_statement_uid)
    DBDiscussionSession.add(review_duplication)
    DBDiscussionSession.flush()
    transaction.commit()
Ejemplo n.º 3
0
def __add_duplication_review(duplicate_statement_uid, original_statement_uid,
                             user_uid):
    """
    Adds a ReviewDuplicate row

    :param duplicate_statement_uid: Statement.uid
    :param original_statement_uid: Statement.uid
    :param user_uid: User.uid
    :return: None
    """
    logger(
        'FlagingHelper', 'Flag statement {} by user {} as duplicate of'.format(
            duplicate_statement_uid, user_uid, original_statement_uid))
    review_duplication = ReviewDuplicate(
        detector=user_uid,
        duplicate_statement=duplicate_statement_uid,
        original_statement=original_statement_uid)
    DBDiscussionSession.add(review_duplication)
    DBDiscussionSession.flush()
    transaction.commit()
Ejemplo n.º 4
0
    def add_vote(self, db_user: User, db_review: ReviewDuplicate, is_okay: bool, application_url: str,
                 translator: Translator,
                 **kwargs):
        """
        Adds an vote for this queue. If any (positive or negative) limit is reached, the flagged element will disabled
        and the origin will be set as root for any relative

        :param db_user: current user who votes
        :param db_review: the review, which is voted vor
        :param is_okay: True, if the element is rightly flagged
        :param application_url: the app url
        :param translator: a instance of a translator
        :param kwargs: optional, keyworded arguments
        :return:
        """
        LOG.debug("Adding vote for review with id %s. Duplicate? %s", db_review.uid, is_okay)
        db_user_created_flag = DBDiscussionSession.query(User).get(db_review.detector_uid)
        rep_reason = None

        # add new vote
        add_vote_for(db_user, db_review, is_okay, LastReviewerDuplicate)

        # get all keep and delete votes
        count_of_reset, count_of_keep = self.get_review_count(db_review.uid)

        # do we reached any limit?
        reached_max = max(count_of_keep, count_of_reset) >= max_votes
        if reached_max:
            if count_of_reset > count_of_keep:  # disable the flagged part
                self.__bend_objects_of_review(db_review)
                rep_reason = get_reason_by_action(ReputationReasons.success_duplicate)
            else:  # just close the review
                rep_reason = get_reason_by_action(ReputationReasons.bad_duplicate)
            db_review.set_executed(True)
            db_review.update_timestamp()

        elif count_of_keep - count_of_reset >= min_difference:  # just close the review
            rep_reason = get_reason_by_action(ReputationReasons.bad_duplicate)
            db_review.set_executed(True)
            db_review.update_timestamp()

        elif count_of_reset - count_of_keep >= min_difference:  # disable the flagged part
            self.__bend_objects_of_review(db_review)
            rep_reason = get_reason_by_action(ReputationReasons.success_duplicate)
            db_review.set_executed(True)
            db_review.update_timestamp()

        if rep_reason:
            add_reputation_and_send_popup(db_user_created_flag, rep_reason, application_url, translator)
            DBDiscussionSession.add(db_review)
        DBDiscussionSession.flush()
        transaction.commit()

        return True