def get_completeness(user): from app.helpers.path_finder_helper import path_finder completeness_object = g.get('_completeness') if completeness_object is None: metadata = get_metadata(user) answer_store = get_answer_store(user) completed_blocks = get_completed_blocks(user) routing_path = path_finder.get_full_routing_path() completeness_object = g._completeness = Completeness( g.schema, answer_store, completed_blocks, routing_path, metadata) return completeness_object
def login(): """ Initial url processing - expects a token parameter and then will authenticate this token. Once authenticated it will be placed in the users session :return: a 302 redirect to the next location for the user """ # logging in again clears any session state if cookie_session: cookie_session.clear() decrypted_token = decrypt_token(request.args.get('token')) validate_jti(decrypted_token) claims = parse_runner_claims(decrypted_token) g.schema = load_schema_from_metadata(claims) schema_metadata = g.schema.json['metadata'] validate_metadata(claims, schema_metadata) eq_id = claims['eq_id'] form_type = claims['form_type'] tx_id = claims['tx_id'] ru_ref = claims['ru_ref'] logger.bind(eq_id=eq_id, form_type=form_type, tx_id=tx_id, ru_ref=ru_ref) logger.info('decrypted token and parsed metadata') store_session(claims) cookie_session['theme'] = g.schema.json['theme'] cookie_session['survey_title'] = g.schema.json['title'] cookie_session['expires_in'] = get_session_timeout_in_seconds(g.schema) if claims.get('account_service_url'): cookie_session['account_service_url'] = claims.get( 'account_service_url') if claims.get('account_service_log_out_url'): cookie_session['account_service_log_out_url'] = claims.get( 'account_service_log_out_url') routing_path = path_finder.get_full_routing_path() completeness = get_completeness(current_user) router = Router(g.schema, routing_path, completeness) next_location = router.get_next_location() return redirect(next_location.url(claims))
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)
def get_thank_you(schema, metadata, eq_id, form_type): # pylint: disable=unused-argument 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'])) return render_theme_template( schema.json['theme'], template_name='thank-you.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']), is_view_submitted_response_enabled= is_view_submitted_response_enabled(schema.json), view_submission_url=view_submission_url, view_submission_duration=view_submission_duration) routing_path = path_finder.get_full_routing_path() collection_id = metadata['collection_exercise_sid'] router = Router(schema, routing_path, completeness) next_location = router.get_next_location() return _redirect_to_location(collection_id, metadata.get('eq_id'), metadata.get('form_type'), next_location)