Esempio n. 1
0
 def test_valid_argument_with_missing_issue_should_fail(self):
     request = construct_dummy_request()
     response = discussion.valid_argument(location='json_body',
                                          depends_on={
                                              discussion.valid_issue_by_slug
                                          })(request)
     self.assertFalse(response)
     self.assertIsInstance(response, bool)
Esempio n. 2
0
    def test_valid_argument(self):
        request = construct_dummy_request()
        response = discussion.valid_argument(location='json_body')(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(json_body={'argument_id': 1})
        response = discussion.valid_argument(location='json_body')(request)
        self.assertFalse(response, 'uid 1 should be disabled')
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(json_body={'argument_id': 'a'})
        response = discussion.valid_argument(location='json_body')(request)
        self.assertFalse(response, 'uid a is not parsable')
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(matchdict={'argument_id': 'a'})
        response = discussion.valid_argument(location='json_body')(request)
        self.assertFalse(response, 'uid a is not parsable')
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(json_body={'argument_id': 2})
        response = discussion.valid_argument(location='json_body')(request)
        self.assertTrue(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(matchdict={'argument_id': 2})
        response = discussion.valid_argument(location='path')(request)
        self.assertTrue(response)
        self.assertIsInstance(response, bool)
Esempio n. 3
0
        return OptimizationQueue().unlock_optimization_review(db_review, _tn)


@view_config(route_name='revoke_statement_content',
             renderer='json',
             require_csrf=False)
@validate(valid_user_as_author_of_statement,
          valid_statement(location='json_body'))
def revoke_statement_content(request):
    """
    Revokes the given user as author from a statement

    :param request: current request of the server
    :return: json-dict()
    """
    LOG.debug("Revoke a user as author. %s", request.json_body)
    db_user = request.validated['user']
    statement = request.validated['statement']
    return revoke_author_of_statement_content(statement, db_user)


@view_config(route_name='revoke_argument_content',
             renderer='json',
             require_csrf=False)
@validate(valid_user_as_author_of_argument,
          valid_argument(location='json_body'))
def revoke_argument_content(request):
    db_user = request.validated['user']
    argument = request.validated['argument']
    return revoke_author_of_argument_content(argument, db_user)
Esempio n. 4
0
    """
    LOG.debug("Set new premise for start: %s", request.json_body)
    prepared_dict = set_positions_premise(request.validated['issue'],
                                          request.validated['user'],
                                          request.validated['conclusion'],
                                          request.validated['premisegroups'],
                                          request.validated['supportive'],
                                          request.cookies.get('_HISTORY_'),
                                          request.mailer)
    __modifiy_discussion_url(prepared_dict)
    return prepared_dict


@view_config(route_name='set_new_premises_for_argument', renderer='json')
@validate(valid_user, valid_premisegroups,
          valid_argument(location='json_body',
                         depends_on={valid_issue_not_readonly}),
          has_keywords_in_json_path(('attack_type', str)))
def set_new_premises_for_argument(request):
    """
    Sets a new premise for an argument

    :param request: request of the web server
    :return: json-dict()
    """
    LOG.debug("Set new premise for an argument. %s", request.json_body)
    prepared_dict = set_arguments_premises(
        request.validated['issue'], request.validated['user'],
        request.validated['argument'], request.validated['premisegroups'],
        relation_mapper[request.validated['attack_type']],
        request.cookies['_HISTORY_']
        if '_HISTORY_' in request.cookies else None, request.mailer)
Esempio n. 5
0
    modify_discussion_url(prepared_discussion)
    modify_discussion_bubbles(prepared_discussion, request.registry)

    append_extras_dict_during_justification_statement(request, db_user,
                                                      db_issue, db_statement,
                                                      prepared_discussion,
                                                      inner_attitude)

    return prepared_discussion


@view_config(route_name='discussion_dontknow_argument',
             renderer='../../templates/discussion/main.pt',
             permission='everybody')
@validate(check_authentication, valid_user_optional,
          valid_argument(location='path', depends_on={valid_issue_by_slug}))
def dontknow_argument(request) -> dict:
    r"""
    View configuration for discussion step, where we will ask the user for her a justification of her opinion/interest.

    Path: /discuss/{slug}/justify/{argument_id:\d+}/dontknow}

    :param request: request of the web server
    :return: dict
    """
    LOG.debug("Do not know an argument for this step. %s", request.matchdict)
    emit_participation(request)

    db_argument: Argument = request.validated['argument']

    db_issue = request.validated['issue']
Esempio n. 6
0
    """
    db_user = request.validated['user']
    db_issue = request.validated['issue']
    history = history_handler.save_and_set_cookie(request, db_user, db_issue)

    prepared_discussion = discussion.justify_statement(
        db_issue, db_user, request.validated['statement'],
        request.validated['attitude'], history, request.path)
    bubbles, items = extract_items_and_bubbles(prepared_discussion)

    return {'bubbles': bubbles, 'items': items}


@dontknow_argument.get()
@validate(valid_issue_by_slug, valid_token_optional,
          valid_argument(location='path'))
def discussion_dontknow_argument(request) -> dict:
    """
    Dont know an argument.

    /{slug}/justify/{argument_id}/dontknow

    :param request:
    :return:
    """
    db_user = request.validated['user']
    db_issue = request.validated['issue']
    hist = history_handler.save_and_set_cookie(request, db_user, db_issue)

    prepared_discussion = discussion.dont_know_argument(
        db_issue, db_user, request.validated['argument'], hist, request.path)
Esempio n. 7
0
    db_user = request.validated['user']
    db_issue = request.validated['issue']
    history = history_handler.save_and_set_cookie(request, db_user, db_issue)

    prepared_discussion = discussion.justify_statement(db_issue, db_user, request.validated['statement'],
                                                       request.validated['attitude'], history, request.path)
    bubbles, items = extract_items_and_bubbles(prepared_discussion)

    return {
        'bubbles': bubbles,
        'items': items
    }


@dontknow_argument.get()
@validate(valid_issue_by_slug, valid_token_optional, valid_argument(location='path'))
def discussion_dontknow_argument(request) -> dict:
    """
    Dont know an argument.

    /{slug}/justify/{argument_id}/dontknow

    :param request:
    :return:
    """
    db_user = request.validated['user']
    db_issue = request.validated['issue']
    hist = history_handler.save_and_set_cookie(request, db_user, db_issue)

    prepared_discussion = discussion.dont_know_argument(db_issue, db_user, request.validated['argument'], hist,
                                                        request.path)