示例#1
0
def set_position(db_user: User, db_issue: Issue, statement_text: str, feature_data: dict = {}) -> dict:
    """
    Set new position for current discussion and returns collection with the next url for the discussion.

    :param statement_text: The text of the new position statement.
    :param db_issue: The issue which gets the new position
    :param db_user: The user who sets the new position.
    :param feature_data: More data which is used by additional features
    :rtype: dict
    :return: Prepared collection with statement_uids of the new positions and next url or an error
    """
    LOG.debug("%s", statement_text)

    new_statement: Statement = insert_as_statement(statement_text, db_user, db_issue, is_start=True)

    if db_issue.decision_process:
        dp = db_issue.decision_process
        if 'decidotron_cost' not in feature_data:
            transaction.abort()
            LOG.error('Cost missing for an issue with a decision_process')
            return {
                'status': 'fail',  # best error management
                'errors': 'Cost missing for an issue with a decision_process'
            }
        else:
            cost = int(float(feature_data['decidotron_cost']))

            if dp.min_position_cost <= cost <= (dp.max_position_cost or dp.budget) and not dp.position_ended():
                add_associated_cost(db_issue, new_statement, cost)
            else:
                transaction.abort()
                LOG.error(
                    f'Cost has to be {dp.min_position_cost} <= cost <= {dp.max_position_cost or dp.budget}. cost is: {cost}')
                return {
                    'status': 'fail',
                    'errors': f'Cost has to be {dp.min_position_cost} <= cost <= {dp.max_position_cost or dp.budget}.'
                }

    _um = UrlManager(db_issue.slug)
    url = _um.get_url_for_statement_attitude(new_statement.uid)
    rep_added = add_reputation_for(db_user, get_reason_by_action(ReputationReasons.first_position))
    had_access = has_access_to_review_system(db_user)
    if not rep_added:
        add_reputation_for(db_user, get_reason_by_action(ReputationReasons.new_statement))
    broke_limit = has_access_to_review_system(db_user) and not had_access
    if broke_limit:
        url += '#access-review'

    return {
        'status': 'success',
        'url': url,
        'statement_uids': [new_statement.uid],
        'errors': ''
    }
示例#2
0
def set_arguments_premises(db_issue: Issue, db_user: User,
                           db_argument: Argument,
                           premisegroups: List[List[str]],
                           attack_type: Relations, history, mailer) -> dict:
    """
    Set new premise for a given conclusion and returns dictionary with url for the next step of the discussion

    :param db_issue:
    :param db_user:
    :param db_argument:
    :param premisegroups:
    :param attack_type:
    :param history:
    :param mailer:
    :rtype: dict
    :return: Prepared collection with statement_uids of the new premises and next url or an error
    """
    # escaping will be done in QueryHelper().set_statement(...)
    langs = {
        'default_locale_name': db_issue.lang,
        'discussion_lang': db_issue.lang
    }
    arg_infos = {
        'arg_id': db_argument.uid,
        'attack_type': attack_type,
        'premisegroups': premisegroups,
        'history': history
    }
    url, statement_uids, error = __process_input_premises_for_arguments_and_receive_url(
        langs, arg_infos, db_issue, db_user, mailer)

    prepared_dict = {'error': error, 'statement_uids': statement_uids}

    if url is None:
        return prepared_dict

    # add reputation
    had_access = has_access_to_review_system(db_user)
    rep_added = add_reputation_for(
        db_user, get_reason_by_action(ReputationReasons.first_new_argument))
    if not rep_added:
        add_reputation_for(
            db_user, get_reason_by_action(ReputationReasons.new_statement))
    broke_limit = has_access_to_review_system(db_user) and not had_access
    if broke_limit:
        url += '#access-review'
        prepared_dict['url'] = url

    prepared_dict['url'] = url

    LOG.debug("Returning %s", prepared_dict)
    return prepared_dict
示例#3
0
def __add_reputation(db_user: User, db_issue: Issue, url: str, prepared_dict: dict):
    """

    :param db_user:
    :param db_issue:
    :param url:
    :param prepared_dict:
    :return:
    """
    had_access = has_access_to_review_system(db_user)
    rep_added = add_reputation_for(db_user, get_reason_by_action(ReputationReasons.first_justification))
    if not rep_added:
        add_reputation_for(db_user, get_reason_by_action(ReputationReasons.new_statement))
    broke_limit = has_access_to_review_system(db_user) and not had_access
    if broke_limit:
        _t = Translator(db_issue.lang)
        send_request_for_info_popup_to_socketio(db_user.nickname, _t.get(_.youAreAbleToReviewNow), '/review')
        prepared_dict['url'] = '{}{}'.format(url, '#access-review')
示例#4
0
    def test_add_reputation_and_check_review_access(self):
        # user has no access
        self.assertFalse(has_access_to_review_system(self.user_tobi))

        # add points
        broke_limit = add_reputation_and_check_review_access(
            self.user_tobi, ReputationReasons.success_flag)
        self.assertTrue(broke_limit)

        # now we have access
        self.assertTrue(has_access_to_review_system(self.user_tobi))
        db_last = DBDiscussionSession.query(ReputationHistory).filter_by(
            reputator_uid=2).order_by(ReputationHistory.uid.asc()).first()
        DBDiscussionSession.query(ReputationHistory).filter_by(
            uid=db_last.uid).delete()

        # we lost access
        self.assertFalse(has_access_to_review_system(self.user_tobi))
        DBDiscussionSession.flush()
        transaction.commit()
示例#5
0
def set_position(db_user: User, db_issue: Issue, statement_text: str) -> dict:
    """
    Set new position for current discussion and returns collection with the next url for the discussion.

    :param statement_text: The text of the new position statement.
    :param db_issue: The issue which gets the new position
    :param db_user: The user who sets the new position.
    :rtype: dict
    :return: Prepared collection with statement_uids of the new positions and next url or an error
    """
    LOG.debug("%s", statement_text)

    user.update_last_action(db_user)

    new_statement: Statement = insert_as_statement(statement_text,
                                                   db_user,
                                                   db_issue,
                                                   is_start=True)

    _um = UrlManager(db_issue.slug)
    url = _um.get_url_for_statement_attitude(new_statement.uid)
    rep_added = add_reputation_for(
        db_user, get_reason_by_action(ReputationReasons.first_position))
    had_access = has_access_to_review_system(db_user)
    if not rep_added:
        add_reputation_for(
            db_user, get_reason_by_action(ReputationReasons.new_statement))
    broke_limit = has_access_to_review_system(db_user) and not had_access
    if broke_limit:
        url += '#access-review'

    return {
        'status': 'success',
        'url': url,
        'statement_uids': [new_statement.uid],
        'error': ''
    }
示例#6
0
 def test_has_access_to_review_system(self):
     self.assertFalse(has_access_to_review_system(self.user_torben))
     self.assertTrue(has_access_to_review_system(self.user_christian))