def test_valid_statement(self): request = construct_dummy_request() response = discussion.valid_statement(location='json_body')(request) self.assertFalse(response) self.assertIsInstance(response, bool) request = construct_dummy_request(json_body={'statement_id': 1}) response = discussion.valid_statement(location='json_body')(request) self.assertFalse(response, 'uid 1 is disabled and should not be returned') self.assertIsInstance(response, bool) request = construct_dummy_request(json_body={'statement_id': 'a'}) response = discussion.valid_statement(location='json_body')(request) self.assertFalse(response, 'uid a is not parsable') self.assertIsInstance(response, bool) self.assertIsInstance(response, bool) request = construct_dummy_request(matchdict={'statement_id': 'a'}) response = discussion.valid_statement(location='path')(request) self.assertFalse(response, 'uid a is not parsable') self.assertIsInstance(response, bool) request = construct_dummy_request(json_body={'statement_id': 2}) response = discussion.valid_statement(location='json_body')(request) self.assertTrue(response) self.assertIsInstance(response, bool) request = construct_dummy_request(matchdict={'statement_id': 2}) response = discussion.valid_statement(location='path')(request) self.assertTrue(response) self.assertIsInstance(response, bool)
""" ajax interface for getting a dump :param request: current request of the server :return: json-set with everything """ LOG.debug("Get infos about an argument via AJAX. %s", request.json_body) lang = request.validated['lang'] db_user = request.validated['user'] db_argument = request.validated['argument'] return get_all_infos_about_argument(db_argument, request.application_url, db_user, lang) @view_config(route_name='get_arguments_by_statement_uid', renderer='json') @validate(valid_any_issue_by_id, valid_statement(location='path')) def get_arguments_by_statement_id(request): """ Returns all arguments, which use the given statement :param request: current request of the server :return: json-dict() """ LOG.debug("Return all arguments which use the given statement. %s", request.json_body) db_statement = request.validated['statement'] db_issue = request.validated['issue'] argument_list = get_arguments_by_statement_uid(db_statement, db_issue) for el in argument_list.get('arguments', []): el['url'] = '/discuss' + el['url'] return argument_list
lock = request.validated['lock'] db_review = request.validated['db_model'] db_user = request.validated['user'] if lock: return OptimizationQueue().lock_optimization_review( db_user, db_review, _tn) else: 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',
_dh = DictionaryHelper(rdict['ui_locales'], prepared_discussion['issues']['lang']) nickname = request.authenticated_userid if request.authenticated_userid else nick_of_anonymous_user _dh.add_discussion_end_text(prepared_discussion['discussion'], prepared_discussion['extras'], nickname, at_start=True) return prepared_discussion @view_config(route_name='discussion_attitude', renderer='../../templates/discussion/main.pt', permission='everybody') @validate(check_authentication, valid_user_optional, valid_statement(location='path', depends_on={valid_issue_by_slug})) def attitude(request): """ View configuration for discussion step, where we will ask the user for her attitude towards a statement. Route: /discuss/{slug}/attitude/{position_id} :param request: request of the web server :return: dictionary """ LOG.debug("View attitude: %s", request.matchdict) emit_participation(request) db_statement = request.validated['statement'] db_issue = request.validated['issue'] db_user = request.validated['user']
def get_reference(request): """ Returns all references for an argument or statement :param request: current request of the server :return: json-dict() """ LOG.debug("Return references for request: %s", request.json_body) uids = request.validated['uids'] is_argument = request.validated['is_argument'] return get_references(uids, is_argument, request.application_url) @view_config(route_name='set_references', renderer='json') @validate(valid_user, valid_any_issue_by_id, valid_statement('json_body'), has_keywords_in_json_path(('text', str), ('ref_source', str))) def set_references(request): """ Sets a reference for a statement or an arguments :param request: current request of the server :return: json-dict() """ LOG.debug("Set a reference for a statement or an argument. Request: %s", request.json_body) db_statement = request.validated['statement'] text = escape_string(request.validated['text']) source = escape_string(request.validated['ref_source']) db_user = request.validated['user'] db_issue = request.validated['issue'] return set_reference(text, source, db_user, db_statement, db_issue.uid)
history = history_handler.save_and_set_cookie(request, db_user, db_issue) prepared_discussion = discussion.attitude(db_issue, db_user, db_position, history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) keys = [ item['attitude'] for item in prepared_discussion['items']['elements'] ] return {'bubbles': bubbles, 'attitudes': dict(zip(keys, items))} @justify_statement.get() @validate(valid_issue_by_slug, valid_token_optional, valid_statement(location='path'), valid_attitude) def discussion_justify_statement(request) -> dict: """ Pick attitude from path and query the statement. Show the user some statements to follow the discussion. Path: /{slug}/justify/{statement_id}/{attitude} :param request: request :return: dict """ 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'],
db_user = request.validated['user'] history = history_handler.save_and_set_cookie(request, db_user, db_issue) prepared_discussion = discussion.attitude(db_issue, db_user, db_position, history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) keys = [item['attitude'] for item in prepared_discussion['items']['elements']] return { 'bubbles': bubbles, 'attitudes': dict(zip(keys, items)) } @justify_statement.get() @validate(valid_issue_by_slug, valid_token_optional, valid_statement(location='path'), valid_attitude) def discussion_justify_statement(request) -> dict: """ Pick attitude from path and query the statement. Show the user some statements to follow the discussion. Path: /{slug}/justify/{statement_id}/{attitude} :param request: request :return: dict """ 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)
@view_config(route_name='get_public_user_data', renderer='json') @validate(has_keywords(('nickname', str))) def get_public_user_data(request): """ Returns dictionary with public user data :param request: request of the web server :return: """ logger('views', 'main: {}'.format(request.json_body)) return user.get_public_data(request.validated['nickname'], get_language_from_cookie(request)) @view_config(route_name='get_arguments_by_statement_uid', renderer='json') @validate(valid_statement(location='json_body')) def get_arguments_by_statement_id(request): """ Returns all arguments, which use the given statement :param request: current request of the server :return: json-dict() """ logger('views', 'main: {}'.format(request.json_body)) return get_arguments_by_statement_uid(request.validated['statement']) @view_config(route_name='get_references', renderer='json') @validate(has_keywords(('uids', list), ('is_argument', bool))) def get_reference(request): """