예제 #1
0
def get_view_submission(schema, eq_id, form_type):  # pylint: disable=unused-argument

    session_data = get_session_store().session_data

    if _is_submission_viewable(schema.json, session_data.submitted_time):
        submitted_data = data_access.get_by_key(SubmittedResponse,
                                                session_data.tx_id)

        if submitted_data:

            metadata_context = build_metadata_context_for_survey_completed(
                session_data)

            pepper = current_app.eq['secret_store'].get_secret_by_name(
                'EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER')
            encrypter = StorageEncryption(current_user.user_id,
                                          current_user.user_ik, pepper)

            submitted_data = json.loads(
                encrypter.decrypt_data(submitted_data.data))
            answer_store = AnswerStore(
                existing_answers=submitted_data.get('answers'))

            metadata = submitted_data.get('metadata')

            routing_path = PathFinder(schema, answer_store, metadata,
                                      []).get_full_routing_path()

            schema_context = _get_schema_context(routing_path, 0, metadata,
                                                 answer_store, schema)
            rendered_schema = renderer.render(schema.json, **schema_context)
            summary_rendered_context = build_summary_rendering_context(
                schema, rendered_schema['sections'], answer_store, metadata)

            context = {
                'summary': {
                    'groups':
                    summary_rendered_context,
                    'answers_are_editable':
                    False,
                    'is_view_submission_response_enabled':
                    is_view_submitted_response_enabled(schema.json),
                },
                'variables': None,
            }

            return render_theme_template(
                schema.json['theme'],
                template_name='view-submission.html',
                metadata=metadata_context,
                analytics_ua_id=current_app.config['EQ_UA_ID'],
                survey_id=schema.json['survey_id'],
                survey_title=TemplateRenderer.safe_content(
                    schema.json['title']),
                content=context)

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))
예제 #2
0
    def test_summary_context_html_encodes_answers(self):
        sections = self.schema.sections
        answer_store = AnswerStore([{
            'answer_id': 'dessert',
            'block_id': 'dessert-block',
            'value': """<>"'&""",
            'answer_instance': 0,
        }])

        summary_rendering_context = build_summary_rendering_context(self.schema, sections, answer_store, self.metadata)

        answer = summary_rendering_context[1]['blocks'][0]['questions'][0]['answers'][0]
        self.assertEqual(answer['value'], '&lt;&gt;&#34;&#39;&amp;')
예제 #3
0
def get_summary(eq_id, form_type, collection_id):  # pylint: disable=unused-argument
    answer_store = get_answer_store(current_user)
    path_finder = PathFinder(g.schema_json, answer_store, get_metadata(current_user))
    latest_location = path_finder.get_latest_location(get_completed_blocks(current_user))
    metadata = get_metadata(current_user)

    if latest_location.block_id is 'summary':
        answers = get_answer_store(current_user)
        schema_context = build_schema_context(metadata, g.schema.aliases, answers)
        rendered_schema_json = renderer.render(g.schema_json, **schema_context)
        summary_context = build_summary_rendering_context(rendered_schema_json, answer_store, metadata)
        return _build_template(current_location=latest_location, context=summary_context)

    return redirect(latest_location.url(metadata))
def build_view_context_for_summary(schema, section_list, answer_store,
                                   metadata, block_type, variables,
                                   schema_context):
    summary_rendering_context = build_summary_rendering_context(
        schema, section_list, answer_store, metadata, schema_context)

    context = {
        'summary': {
            'groups': summary_rendering_context,
            'answers_are_editable': True,
            'summary_type': block_type,
        },
        'variables': variables,
    }
    return context
예제 #5
0
    def test_build_summary_rendering_context(self):
        answer_store = MagicMock()
        routing_path = [
            Location(
                block_id='choose-your-side-block',
                group_id='14ba4707-321d-441d-8d21-b8367366e766',
                group_instance=0,
            )
        ]
        navigator = Mock()
        navigator.get_routing_path = Mock(return_value=routing_path)

        with patch('app.templating.summary_context.PathFinder',
                   return_value=navigator):
            context = build_summary_rendering_context(self.schema_json,
                                                      answer_store,
                                                      self.metadata)

        self.assertEqual(len(context), 1)
예제 #6
0
def _get_context(block, current_location, answer_store):

    error_messages = SchemaHelper.get_messages(g.schema_json)
    form, template_params = get_form_for_location(block, current_location,
                                                  answer_store, error_messages)
    content = {'form': form, 'block': block}
    if template_params:
        content.update(template_params)

    if block['type'] == 'Summary':
        metadata = get_metadata(current_user)
        aliases = SchemaHelper.get_aliases(g.schema_json)
        schema_context = build_schema_context(metadata, aliases, answer_store)
        rendered_schema_json = renderer.render(g.schema_json, **schema_context)
        content.update({
            'summary':
            build_summary_rendering_context(rendered_schema_json, answer_store,
                                            metadata)
        })

    return content
예제 #7
0
def _render_submission_page(session_data, submitted_data, schema, eq_id,
                            form_type):  # pylint: disable=unused-argument, too-many-locals

    metadata_context = build_metadata_context_for_survey_completed(
        session_data)

    pepper = current_app.eq['secret_store'].get_secret_by_name(
        'EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER')

    encrypter = StorageEncryption(current_user.user_id, current_user.user_ik,
                                  pepper)
    submitted_data = encrypter.decrypt_data(submitted_data.data)

    # for backwards compatibility
    # submitted data used to be base64 encoded before encryption
    try:
        submitted_data = base64url_decode(submitted_data.decode()).decode()
    except ValueError:
        pass

    submitted_data = json.loads(submitted_data)
    answer_store = AnswerStore(submitted_data.get('answers'))

    metadata = submitted_data.get('metadata')
    collection_metadata = submitted_data.get('collection_metadata')

    routing_path = PathFinder(schema, answer_store, metadata,
                              []).get_full_routing_path()

    schema_context = _get_schema_context(routing_path, None, metadata,
                                         collection_metadata, answer_store,
                                         schema)
    section_list = schema.json['sections']
    summary_rendered_context = build_summary_rendering_context(
        schema, section_list, answer_store, metadata, schema_context)

    context = {
        'summary': {
            'groups':
            summary_rendered_context,
            'answers_are_editable':
            False,
            'is_view_submission_response_enabled':
            is_view_submitted_response_enabled(schema.json),
        },
        'variables': None,
    }

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    download_pdf_url = url_for('post_submission.download_pdf',
                               eq_id=eq_id,
                               form_type=form_type)

    return render_theme_template(
        schema.json['theme'],
        template_name='view-submission.html',
        metadata=metadata_context,
        download_pdf_url=download_pdf_url,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        survey_id=schema.json['survey_id'],
        survey_title=TemplateRenderer.safe_content(schema.json['title']),
        account_service_url=cookie_session.get('account_service_url'),
        account_service_log_out_url=cookie_session.get(
            'account_service_log_out_url'),
        content=context,
        cookie_message=cookie_message,
        allow_analytics=allow_analytics)
 def test_build_summary_rendering_context(self):
     sections = self.schema.sections
     summary_rendering_context = build_summary_rendering_context(
         self.schema, sections, self.answer_store, self.metadata,
         self.schema_context)
     self.check_summary_rendering_context(summary_rendering_context)
 def test_build_summary_rendering_context(self):
     sections = [self.schema.get_section('property-details-section')]
     summary_rendering_context = build_summary_rendering_context(
         self.schema, sections, self.answer_store, self.metadata,
         self.schema_context)
     self.check_summary_rendering_context(summary_rendering_context)
def get_view_submission(schema, eq_id, form_type):  # pylint: disable=unused-argument, too-many-locals

    session_data = get_session_store().session_data

    if _is_submission_viewable(schema.json, session_data.submitted_time):
        submitted_data = data_access.get_by_key(SubmittedResponse,
                                                session_data.tx_id)

        if submitted_data:

            metadata_context = build_metadata_context_for_survey_completed(
                session_data)

            pepper = current_app.eq['secret_store'].get_secret_by_name(
                'EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER')

            encrypter = StorageEncryption(current_user.user_id,
                                          current_user.user_ik, pepper)
            submitted_data = encrypter.decrypt_data(submitted_data.data)

            # for backwards compatibility
            # submitted data used to be base64 encoded before encryption
            try:
                submitted_data = base64url_decode(
                    submitted_data.decode()).decode()
            except ValueError:
                pass

            submitted_data = json.loads(submitted_data)
            answer_store = AnswerStore(submitted_data.get('answers'))

            metadata = submitted_data.get('metadata')
            collection_metadata = submitted_data.get('collection_metadata')

            routing_path = PathFinder(schema, answer_store, metadata,
                                      []).get_full_routing_path()

            schema_context = _get_schema_context(routing_path, None, metadata,
                                                 collection_metadata,
                                                 answer_store, schema)
            section_list = schema.json['sections']
            summary_rendered_context = build_summary_rendering_context(
                schema, section_list, answer_store, metadata, schema_context)

            context = {
                'summary': {
                    'groups':
                    summary_rendered_context,
                    'answers_are_editable':
                    False,
                    'is_view_submission_response_enabled':
                    is_view_submitted_response_enabled(schema.json),
                },
                'variables': None,
            }

            return render_theme_template(
                schema.json['theme'],
                template_name='view-submission.html',
                metadata=metadata_context,
                analytics_ua_id=current_app.config['EQ_UA_ID'],
                survey_id=schema.json['survey_id'],
                survey_title=TemplateRenderer.safe_content(
                    schema.json['title']),
                account_service_url=cookie_session.get('account_service_url'),
                account_service_log_out_url=cookie_session.get(
                    'account_service_log_out_url'),
                content=context)

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))