Beispiel #1
0
def _render_template(template, **kwargs):
    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    return template_helper.render_template(template,
                                           cookie_message=cookie_message,
                                           allow_analytics=allow_analytics,
                                           **kwargs)
Beispiel #2
0
def _build_template(current_location,
                    context,
                    template,
                    schema,
                    answer_store,
                    metadata,
                    routing_path=None):
    front_end_navigation = _get_front_end_navigation(answer_store,
                                                     current_location,
                                                     metadata, schema,
                                                     routing_path)
    previous_location = path_finder.get_previous_location(current_location)
    previous_url = previous_location.url(
        metadata) if previous_location is not None else None
    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    add_person_url = None
    if routing_path:
        add_person_location = routing_path[routing_path.index(current_location)
                                           - 1]
        add_person_url = add_person_location.url(
            metadata) if add_person_location else None

    return _render_template(context, current_location, template,
                            front_end_navigation, previous_url, add_person_url,
                            schema, metadata, answer_store, cookie_message,
                            allow_analytics)
Beispiel #3
0
def settings():
    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    cookie_template = render_theme_template(theme=cookie_session.get('theme', 'default'),
                                            analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                            analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                            cookie_message=cookie_message,
                                            allow_analytics=allow_analytics,
                                            template_name='static/cookies-settings.html')
    return cookie_template
Beispiel #4
0
def get_thank_you(schema, metadata, eq_id, form_type):
    session_data = get_session_store().session_data
    completeness = get_completeness(current_user)

    if session_data.submitted_time:
        metadata_context = build_metadata_context_for_survey_completed(
            session_data)

        view_submission_url = None
        view_submission_duration = 0
        if _is_submission_viewable(schema.json, session_data.submitted_time):
            view_submission_url = url_for('.get_view_submission',
                                          eq_id=eq_id,
                                          form_type=form_type)
            view_submission_duration = humanize.naturaldelta(
                timedelta(seconds=schema.json['view_submitted_response']
                          ['duration']))

        cookie_message = request.cookies.get('ons_cookie_message_displayed')
        allow_analytics = analytics_allowed(request)

        return render_theme_template(
            schema.json['theme'],
            template_name='thank-you.html',
            metadata=metadata_context,
            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']),
            is_view_submitted_response_enabled=
            is_view_submitted_response_enabled(schema.json),
            view_submission_url=view_submission_url,
            account_service_url=cookie_session.get('account_service_url'),
            account_service_log_out_url=cookie_session.get(
                'account_service_log_out_url'),
            view_submission_duration=view_submission_duration,
            cookie_message=cookie_message,
            allow_analytics=allow_analytics)

    routing_path = path_finder.get_full_routing_path()

    router = Router(schema, routing_path, completeness)
    next_location = router.get_next_location()

    return _redirect_to_location(metadata['collection_exercise_sid'],
                                 metadata.get('eq_id'),
                                 metadata.get('form_type'), next_location)
Beispiel #5
0
def _render_error_page(status_code):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    return render_theme_template(
        'default',
        'errors/error.html',
        status_code=status_code,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        cookie_message=cookie_message,
        allow_analytics=allow_analytics,
        account_service_url=cookie_session.get('account_service_url'),
        ua=user_agent,
        tx_id=tx_id), status_code
Beispiel #6
0
def render_template(template_name):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    return render_theme_template(
        cookie_session.get('theme', 'default'),
        template_name=template_name,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        cookie_message=cookie_message,
        allow_analytics=allow_analytics,
        ua=user_agent,
        tx_id=tx_id,
        account_service_url=cookie_session.get('account_service_url'),
        survey_title=TemplateRenderer.safe_content(
            cookie_session.get('survey_title', '')))
Beispiel #7
0
def contact():
    session = None
    survey_id = None
    session_store = get_session_store()

    if session_store:
        session = session_store.session_data
        schema = load_schema_from_session_data(session)
        survey_id = schema.json['survey_id']

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    contact_template = render_theme_template(theme=cookie_session.get('theme', 'default'),
                                             template_name='static/contact-us.html',
                                             session=session,
                                             survey_id=survey_id,
                                             analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                             analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                             cookie_message=cookie_message,
                                             allow_analytics=allow_analytics)
    return contact_template
Beispiel #8
0
def get_sign_out():
    """
    Signs the user first out of eq, then the account service by hitting the account services'
    logout url.
    """
    account_service_log_out_url = cookie_session.get('account_service_log_out_url')
    logout_user()

    if account_service_log_out_url:
        return redirect(account_service_log_out_url)

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    return render_theme_template(cookie_session.get('theme', 'default'),
                                 template_name='signed-out.html',
                                 analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                 analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                 cookie_message=cookie_message,
                                 allow_analytics=allow_analytics,
                                 account_service_url=cookie_session.get('account_service_url'),
                                 survey_title=TemplateRenderer.safe_content(cookie_session.get('survey_title', '')))
Beispiel #9
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)
Beispiel #10
0
 def test_with_cookie_usage_true_double_quotes(self):
     request = MockRequest('{"essential": true, "usage": true}')
     self.assertTrue(analytics_allowed(request))
Beispiel #11
0
 def test_with_cookie_usage_true(self):
     request = MockRequest("{'essential': true, 'usage': true}")
     self.assertTrue(analytics_allowed(request))