Beispiel #1
0
def set_correction_of_statement(elements, db_user, translator) -> dict:
    """
    Adds a proposal for a statements correction and returns info if the proposal could be set

    :param elements: List of dicts with text and uids for proposals of edits for new statements
    :param db_user: User
    :param translator: Translator
    :rtype: dict
    :return: Dictionary with info and/or error
    """

    review_count = len(elements)
    added_reviews = [EditQueue().add_edit_reviews(db_user, el['uid'], el['text']) for el in elements]

    if added_reviews.count(Code.SUCCESS) == 0:  # no edits set
        if added_reviews.count(Code.DOESNT_EXISTS) > 0:
            LOG.debug("Internal Key Error")
            return {
                'info': translator.get(_.internalKeyError),
                'error': True
            }
        if added_reviews.count(Code.DUPLICATE) > 0:
            LOG.debug("Already edit proposals")
            return {
                'info': translator.get(_.alreadyEditProposals),
                'error': True
            }
        LOG.debug("No corrections given")
        return {
            'info': translator.get(_.noCorrections),
            'error': True
        }

    DBDiscussionSession.flush()
    transaction.commit()

    added_values = [EditQueue().add_edit_values_review(db_user, el['uid'], el['text']) for el in elements]
    if Code.SUCCESS not in added_values:
        return {
            'info': translator.get(_.alreadyEditProposals),
            'error': True
        }
    DBDiscussionSession.flush()
    transaction.commit()

    msg = ''
    if review_count > added_values.count(Code.SUCCESS) \
            or added_reviews.count(Code.SUCCESS) != added_values.count(Code.SUCCESS):
        msg = translator.get(_.alreadyEditProposals)
    return {
        'error': False,
        'info': msg
    }
Beispiel #2
0
 def test_is_arguments_premise_in_edit_queue(self):
     db_reviews = DBDiscussionSession.query(ReviewEdit).filter_by(
         is_executed=False, is_revoked=False).all()
     for db_review in db_reviews:
         db_premise = DBDiscussionSession.query(Premise).filter_by(
             statement_uid=db_review.statement_uid).first()
         if not db_premise:  # skip this cause we just have random data
             continue
         db_arg = DBDiscussionSession.query(Argument).filter_by(
             premisegroup_uid=db_premise.premisegroup_uid).first()
         self.assertTrue(
             EditQueue().is_arguments_premise_in_edit_queue(db_arg))
Beispiel #3
0
    def __get_statement_array_for_justify_argument(self, argument_uid, attack_type, db_user, history, argument, uids,
                                                   _um):
        if db_user and db_user.nickname != nick_of_anonymous_user:  # add seen by if the statement is visible
            add_seen_argument(argument_uid, db_user)
        # get all premises in this group
        db_premises = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=argument.premisegroup_uid).all()
        premises_array = []
        for premise in db_premises:
            text = premise.get_text()
            premises_array.append({
                'id': premise.statement_uid,
                'title': text
            })

        # for each justifying premise, we need a new confrontation: (restriction is based on fix #38)
        is_undermine = Relations.UNDERMINE if attack_type == Relations.UNDERMINE else None
        attacking_arg_uids = get_all_attacking_arg_uids_from_history(self.path)

        arg_id_sys, attack = attacks.get_attack_for_argument(argument.uid, last_attack=is_undermine,
                                                             restrictive_arg_uids=attacking_arg_uids,
                                                             history=self.path)
        the_other_one = True
        url = ''

        # with a chance of 50% or at the end we will seed the new "support step"
        if not attack:
            new_arg = get_another_argument_with_same_conclusion(argument.uid, history)
            the_other_one = new_arg is None
            if new_arg:
                the_other_one = False
                url = _um.get_url_for_support_each_other(argument.uid, new_arg.uid)

        if the_other_one:
            url = _um.get_url_for_reaction_on_argument(argument.uid, attack, arg_id_sys)
        return self.__create_answer_dict(argument.uid, premises_array, 'justify', url,
                                         is_markable=True,
                                         is_editable=not EditQueue().is_arguments_premise_in_edit_queue(argument),
                                         is_author=is_author_of_argument(db_user, argument.uid),
                                         is_visible=argument.uid in uids,
                                         attack_url=_um.get_url_for_jump(argument.uid))
Beispiel #4
0
def review_edit_argument(request):
    """
    Values for the review for an argument, which should be edited

    :param request: current request of the server
    :return: json-dict()
    """
    LOG.debug("Review request to edit argument: %s - %s", request.json_body,
              request.authenticated_userid)
    ui_locales = get_discussion_language(request.matchdict, request.params,
                                         request.session)
    db_review = request.validated['db_review']
    db_user = request.validated['user']
    is_edit_okay = request.validated['is_edit_okay']
    main_page = request.application_url
    _t = Translator(ui_locales)

    QueueAdapter(EditQueue(), db_user, main_page,
                 _t).add_vote(db_review, is_edit_okay)
    send_request_for_recent_reviewer_socketio(db_user.nickname, main_page,
                                              key_edit)
    return True
Beispiel #5
0
    def __get_statement_array_for_justify_statement(self, db_user, history, argument, uids, _tn, _um):
        if db_user and argument.uid in uids:  # add seen by if the statement is visible
            add_seen_argument(argument.uid, db_user)

        # get all premises in the premisegroup of this argument
        db_premises = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=argument.premisegroup_uid).all()
        premise_array = []
        for premise in db_premises:
            text = premise.get_text()
            premise_array.append({'title': text, 'id': premise.statement_uid})

        # filter forbidden attacks
        forbidden_attacks = attacks.get_forbidden_attacks_based_on_history(self.path)

        # get attack for each premise, so the urls will be unique
        arg_id_sys, attack = attacks.get_attack_for_argument(argument.uid, history=self.path,
                                                             restrictive_arg_uids=forbidden_attacks)
        already_used = 'reaction/' + str(argument.uid) + '/' in self.path
        additional_text = '(' + _tn.get(_.youUsedThisEarlier) + ')'

        url = _um.get_url_for_discussion_finish(
            argument.uid)  # finish the discussion if D-BAS can't find something to talk about

        if attack:  # if there is an attack get the url to a reaction
            url = _um.get_url_for_reaction_on_argument(argument.uid, attack.value, arg_id_sys)
        else:  # if there is no attack, search for an argument to ask the user about
            new_arg = get_another_argument_with_same_conclusion(argument.uid, history)
            if new_arg:  # if one is found: get the url
                url = _um.get_url_for_support_each_other(argument.uid, new_arg.uid)

        return self.__create_answer_dict(str(argument.uid), premise_array, 'justify', url,
                                         already_used=already_used,
                                         already_used_text=additional_text,
                                         is_editable=not EditQueue().is_arguments_premise_in_edit_queue(argument),
                                         is_markable=True,
                                         is_author=is_author_of_argument(db_user, argument.uid),
                                         is_visible=argument.uid in uids,
                                         attack_url=_um.get_url_for_jump(argument.uid))
Beispiel #6
0
 def test_is_statement_in_edit_queue(self):
     db_review_edits = DBDiscussionSession.query(ReviewEdit).all()
     for review in db_review_edits:
         self.assertTrue(EditQueue().is_statement_in_edit_queue(
             review.statement_uid, review.is_executed))
     self.assertFalse(EditQueue().is_statement_in_edit_queue(50))
Beispiel #7
0
    def get_array_for_start(self, db_user: User) -> dict:
        """
        Prepares the dict with all items for the first step in discussion, where the user chooses a position.

        :param db_user: User
        :return:
        """
        LOG.debug("Entering get_array_for_start with user: %s", db_user.nickname)

        statements = [el.statement_uid for el in
                      DBDiscussionSession.query(StatementToIssue).filter_by(issue_uid=self.db_issue.uid).all()]
        db_statements = DBDiscussionSession.query(Statement) \
            .filter(Statement.is_disabled == False,
                    Statement.is_position == True,
                    Statement.uid.in_(statements)).all()

        uids = [element.uid for element in db_statements if db_statements]
        slug = self.db_issue.slug

        statements_array = []
        _um = UrlManager(slug, history=self.path)

        ed = EditQueue()
        for statement in db_statements:
            if statement.uid in uids:  # add seen by if the statement is visible
                add_seen_statement(statement.uid, db_user)

            position_dict = self.__create_answer_dict(statement.uid,
                                                      [{
                                                          'title': statement.get_text(),
                                                          'id': statement.uid
                                                      }],
                                                      'start',
                                                      _um.get_url_for_statement_attitude(statement.uid),
                                                      is_editable=not ed.is_statement_in_edit_queue(
                                                          statement.uid),
                                                      is_markable=True,
                                                      is_author=is_author_of_statement(db_user, statement.uid),
                                                      is_visible=statement.uid in uids)
            if self.db_issue.decision_process:
                position_dict['cost'] = DBDiscussionSession.query(PositionCost).get(statement.uid).cost

            statements_array.append(position_dict)

        _tn = Translator(self.lang)

        shuffle_list_by_user(db_user, statements_array)

        if not self.issue_read_only:
            if db_user.nickname == nick_of_anonymous_user:
                statements_array.append(self.__create_answer_dict('login',
                                                                  [{
                                                                      'id': '0',
                                                                      'title': _tn.get(_.wantToStateNewPosition)
                                                                  }],
                                                                  'justify',
                                                                  'login'))
            else:
                title = _tn.get(_.newConclusionRadioButtonText) if len(db_statements) > 0 else _tn.get(
                    _.newConclusionRadioButtonTextNewIdea)
                statements_array.append(self.__create_answer_dict('start_statement',
                                                                  [{'title': title, 'id': 0}],
                                                                  'start',
                                                                  'add'))

        return {'elements': statements_array, 'extras': {'cropped_list': len(uids) < len(db_statements)}}