예제 #1
0
파일: edit.py 프로젝트: tbsschroeder/dbas
    def revoke_ballot(self, db_user: User, db_review: ReviewEdit):
        """
        Revokes/Undo the implications of any successfull reviewed element

        :param db_user:
        :param db_review:
        :return:
        """
        db_review = DBDiscussionSession.query(ReviewEdit).get(db_review.uid)
        db_review.set_revoked(True)
        DBDiscussionSession.query(LastReviewerEdit).filter_by(
            review_uid=db_review.uid).delete()
        db_value = DBDiscussionSession.query(ReviewEditValue).filter_by(
            review_edit_uid=db_review.uid)
        content = db_value.first().content
        db_value.delete()
        # delete forbidden textversion
        DBDiscussionSession.query(TextVersion).filter_by(
            content=content).delete()
        db_review_canceled = ReviewCanceled(
            author=db_user.uid, review_data={key_edit: db_review.uid})
        DBDiscussionSession.add(db_review_canceled)
        DBDiscussionSession.flush()
        transaction.commit()
        return True
예제 #2
0
 def test_get_reviews_of(self):
     engelbert = DBDiscussionSession.query(User).filter_by(
         nickname='Engelbert').first()
     self.assertGreaterEqual(user.get_reviews_of(engelbert, True), 0)
     self.assertGreaterEqual(user.get_reviews_of(engelbert, False), 0)
     rv = ReviewEdit(self.user_tobi.uid, 1, 1)
     yesterday = date.today() - timedelta(1)
     rv.timestamp = arrow.get(yesterday.strftime('%Y-%m-%d'))
     DBDiscussionSession.add(rv)
     transaction.commit()
     self.assertGreaterEqual(user.get_reviews_of(self.user_tobi, True), 0)
     self.assertGreaterEqual(user.get_reviews_of(self.user_tobi, False), 0)
예제 #3
0
def __add_edit_reviews(element, db_user):
    """
    Setup a new ReviewEdit row

    :param element: String
    :param db_user: User
    :return: -1 if the statement of the element does not exists, -2 if this edit already exists, 1 on success, 0 otherwise
    """
    logger('ReviewQueues', 'current element: {}'.format(element))
    db_statement = DBDiscussionSession.query(Statement).get(element['uid'])
    if not db_statement:
        logger('ReviewQueues',
               'statement {} not found (return -1)'.format(element['uid']))
        return Code.DOESNT_EXISTS

    # already set an correction for this?
    if is_statement_in_edit_queue(
            element['uid']):  # if we already have an edit, skip this
        logger('ReviewQueues',
               '{} already got an edit (return -2)'.format(element['uid']))
        return Code.DUPLICATE

    # is text different?
    db_tv = DBDiscussionSession.query(TextVersion).get(
        db_statement.textversion_uid)
    if len(element['text']) > 0 and db_tv.content.lower().strip(
    ) != element['text'].lower().strip():
        logger(
            'ReviewQueues',
            'added review element for {}  (return 1)'.format(element['uid']))
        DBDiscussionSession.add(
            ReviewEdit(detector=db_user.uid, statement=element['uid']))
        return Code.SUCCESS

    return Code.ERROR
예제 #4
0
파일: edit.py 프로젝트: tbsschroeder/dbas
    def add_edit_reviews(self, db_user: User, uid: int, text: str):
        """
        Setup a new ReviewEdit row

        :param db_user: User
        :param uid: Statement.uid
        :param text: New content for statement
        :return: -1 if the statement of the element does not exists, -2 if this edit already exists, 1 on success,
        0 otherwise
        """
        db_statement = DBDiscussionSession.query(Statement).get(uid)
        if not db_statement:
            LOG.warning("Statement %s not found (return %s)", uid,
                        Code.DOESNT_EXISTS)
            return Code.DOESNT_EXISTS

        # already set an correction for this?
        if self.is_statement_in_edit_queue(
                uid):  # if we already have an edit, skip this
            LOG.warning("Statement %s already got an edit (return %s)", uid,
                        Code.DUPLICATE)
            return Code.DUPLICATE

        # is text different?
        db_tv = DBDiscussionSession.query(TextVersion).get(
            db_statement.textversion_uid)
        if len(text) > 0 and db_tv.content.lower().strip() != text.lower(
        ).strip():
            LOG.debug("Added review element for %s. (return %s)", uid,
                      Code.SUCCESS)
            DBDiscussionSession.add(
                ReviewEdit(detector=db_user.uid, statement=uid))
            return Code.SUCCESS

        LOG.debug("No case for %s (return %s)", uid, Code.ERROR)
        return Code.ERROR
예제 #5
0
파일: edit.py 프로젝트: tbsschroeder/dbas
    def add_vote(self, db_user: User, db_review: ReviewEdit, 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 get a new
        textversion

        :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("Add a vote for edit queue")
        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, LastReviewerEdit)

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

        # do we reached any limit?
        reached_max = max(count_of_edit, count_of_dont_edit) >= max_votes
        if reached_max:
            if count_of_dont_edit < count_of_edit:  # accept the edit
                self.__accept_edit_review(db_review)
                rep_reason = get_reason_by_action(
                    ReputationReasons.success_edit)
            else:  # just close the review
                rep_reason = get_reason_by_action(ReputationReasons.bad_edit)
            db_review.set_executed(True)
            db_review.update_timestamp()

        elif count_of_edit - count_of_dont_edit >= min_difference:  # accept the edit
            self.__accept_edit_review(db_review)
            rep_reason = get_reason_by_action(ReputationReasons.success_edit)
            db_review.set_executed(True)
            db_review.update_timestamp()

        elif count_of_dont_edit - count_of_edit >= min_difference:  # decline edit
            rep_reason = get_reason_by_action(ReputationReasons.bad_edit)
            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
예제 #6
0
def __proposal_for_the_element(db_review, data, db_user):
    """
    Adds proposal for the ReviewEdit

    :param db_review: ReviewEdit
    :param data: String
    :param db_user: User
    :return: None
    """
    # sort the new edits by argument uid
    argument_dict, statement_dict = __prepare_dicts_for_proposals(data)

    logger(
        'review.opinions', 'detector {}, statements {}, arguments {}'.format(
            db_user.uid, statement_dict, argument_dict))

    # add reviews
    new_edits = list()
    for argument_uid in argument_dict:
        DBDiscussionSession.add(
            ReviewEdit(detector=db_user.uid, argument=argument_uid))
        DBDiscussionSession.flush()
        transaction.commit()
        db_review_edit = DBDiscussionSession.query(ReviewEdit).filter(
            ReviewEdit.detector_uid == db_user.uid,
            ReviewEdit.argument_uid == argument_uid).order_by(
                ReviewEdit.uid.desc()).first()
        logger(
            'review.opinions', 'New ReviewEdit with uid ' +
            str(db_review_edit.uid) + ' (argument)')

        for edit in argument_dict[argument_uid]:
            new_edits.append(
                ReviewEditValue(review_edit=db_review_edit.uid,
                                statement=edit['uid'],
                                typeof=edit['type'],
                                content=edit['val']))

    for statement_uid in statement_dict:
        DBDiscussionSession.add(
            ReviewEdit(detector=db_user.uid, statement=statement_uid))
        DBDiscussionSession.flush()
        transaction.commit()
        db_review_edit = DBDiscussionSession.query(ReviewEdit).filter(
            ReviewEdit.detector_uid == db_user.uid,
            ReviewEdit.statement_uid == statement_uid).order_by(
                ReviewEdit.uid.desc()).first()
        logger(
            'review.opinions', 'New ReviewEdit with uid ' +
            str(db_review_edit.uid) + ' (statement)')

        for edit in statement_dict[statement_uid]:
            new_edits.append(
                ReviewEditValue(review_edit=db_review_edit.uid,
                                statement=statement_uid,
                                typeof=edit['type'],
                                content=edit['val']))

    if len(new_edits) > 0:
        DBDiscussionSession.add_all(new_edits)

    # edit given, so this review is executed
    db_review.set_executed(True)
    db_review.update_timestamp()
    DBDiscussionSession.add(db_review)
    DBDiscussionSession.flush()
    transaction.commit()
예제 #7
0
    def __proposal_for_the_element(self, db_review: ReviewOptimization,
                                   data: dict, db_user: User):
        """
        Adds proposal for the ReviewEdit

        :param db_review: ReviewEdit
        :param data: dict
        :param db_user: User
        :return: None
        """
        # sort the new edits by argument uid
        argument_dict, statement_dict = self.__prepare_dicts_for_proposals(
            data)

        LOG.debug("Detector %s, statements %s, arguments %s", db_user.uid,
                  statement_dict, argument_dict)

        # add reviews
        new_edits = list()
        for argument_uid in argument_dict:
            DBDiscussionSession.add(
                ReviewEdit(detector=db_user.uid, argument=argument_uid))
            DBDiscussionSession.flush()
            transaction.commit()
            db_review_edit = DBDiscussionSession.query(ReviewEdit).filter(
                ReviewEdit.detector_uid == db_user.uid,
                ReviewEdit.argument_uid == argument_uid).order_by(
                    ReviewEdit.uid.desc()).first()
            LOG.debug("New ReviewEdit with uid %s (argument)",
                      db_review_edit.uid)

            for edit in argument_dict[argument_uid]:
                new_edits.append(
                    ReviewEditValue(review_edit=db_review_edit.uid,
                                    statement=edit['uid'],
                                    typeof=edit['type'],
                                    content=edit['val']))

        for statement_uid in statement_dict:
            DBDiscussionSession.add(
                ReviewEdit(detector=db_user.uid, statement=statement_uid))
            DBDiscussionSession.flush()
            transaction.commit()
            db_review_edit = DBDiscussionSession.query(ReviewEdit).filter(
                ReviewEdit.detector_uid == db_user.uid,
                ReviewEdit.statement_uid == statement_uid).order_by(
                    ReviewEdit.uid.desc()).first()
            LOG.debug("New ReviewEdit with uid %s (statement)",
                      db_review_edit.uid)

            for edit in statement_dict[statement_uid]:
                new_edits.append(
                    ReviewEditValue(review_edit=db_review_edit.uid,
                                    statement=statement_uid,
                                    typeof=edit['type'],
                                    content=edit['val']))

        if len(new_edits) > 0:
            DBDiscussionSession.add_all(new_edits)

        # edit given, so this review is executed
        db_review.set_executed(True)
        db_review.update_timestamp()
        DBDiscussionSession.add(db_review)
        DBDiscussionSession.flush()
        transaction.commit()