Esempio n. 1
0
def get_complete_review_count(db_user: User) -> int:
    """
    Sums up the review points of the user

    :param db_user: User
    :return: int
    """
    user_rep, all_rights = get_reputation_of(db_user)
    count = 0
    mapping = get_review_modal_mapping()
    for key in mapping:
        if user_rep >= reputation_borders[key] or all_rights:
            last_reviewer = get_last_reviewer_by_key(key)
            count += get_review_count_for(mapping[key], last_reviewer, db_user)
    return count
Esempio n. 2
0
    def __get_queue_information(self, queue_name: str):
        """
        Returns some information of the current queue

        :param queue_name: name of the queue
        :return:
        """
        last_reviewer = get_last_reviewer_by_key(queue_name)
        table = get_review_model_by_key(queue_name)
        task_count = get_review_count_for(table, last_reviewer, self.db_user)
        count, all_rights = get_reputation_of(self.db_user)
        visit_key_str = _.get_key_by_string('visit{}Queue'.format(
            start_with_capital(queue_name)))
        visit_limit_key_str = _.get_key_by_string(
            'visit{}QueueLimitation'.format(start_with_capital(queue_name)))
        return {
            'task_name':
            self.translator.get(get_title_by_key(queue_name)),
            'id':
            queue_name,
            'url':
            f'{self.application_url}/review/{queue_name}',
            'icon':
            reputation_icons[queue_name],
            'task_count':
            task_count,
            'is_allowed':
            count >= reputation_borders[queue_name] or all_rights,
            'is_allowed_text':
            self.translator.get(visit_key_str),
            'is_not_allowed_text':
            self.translator.get(visit_limit_key_str).format(
                str(reputation_borders[queue_name])),
            'last_reviews':
            self.__get_last_reviewer_of(last_reviewer, self.application_url)
        }
Esempio n. 3
0
    def __test_cancel_ballot(self, key):
        queue = get_queue_by_key(key)
        adapter = QueueAdapter(queue=queue(),
                               db_user=self.user,
                               application_url='main',
                               translator=self.tn)
        review_table = get_review_model_by_key(key)
        last_reviewer_table = get_last_reviewer_by_key(key)

        # count of elements before we add new things to cancel
        review_count_1 = DBDiscussionSession.query(review_table).count()

        # add things which we can cancel
        if key in [key_merge, key_split]:
            db_new_review = review_table(detector=4, premisegroup=5)
        elif key is key_duplicate:
            db_new_review = review_table(detector=4,
                                         duplicate_statement=5,
                                         original_statement=4)
        else:
            db_new_review = review_table(detector=4)

        DBDiscussionSession.add(db_new_review)
        DBDiscussionSession.flush()

        if key == key_split:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    should_split=True))
        elif key == key_merge:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    should_merge=True))
        else:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    is_okay=True))

        DBDiscussionSession.flush()

        # count of elements after we add new things to cancel
        review_count_2 = DBDiscussionSession.query(review_table).count()
        review_canceled_1 = DBDiscussionSession.query(ReviewCanceled).count()

        # cancel things
        adapter.cancel_ballot(db_new_review)

        # count of elements after we canceled
        review_count_3 = DBDiscussionSession.query(review_table).count()
        review_canceled_2 = DBDiscussionSession.query(ReviewCanceled).count()

        self.assertLess(review_count_1, review_count_2)
        self.assertEqual(review_count_3, review_count_2)
        self.assertTrue(db_new_review.is_revoked)

        self.assertLess(review_canceled_1, review_canceled_2)
        self.__delete_review_in_test_cancel_ballot(key, db_new_review,
                                                   last_reviewer_table,
                                                   review_table)