Exemplo n.º 1
0
def _submit_data(user):

    answer_store = get_answer_store(user)

    if answer_store.answers:
        metadata = get_metadata(user)
        schema = load_schema_from_metadata(metadata)
        routing_path = PathFinder(schema, answer_store,
                                  metadata).get_routing_path()

        message = convert_answers(metadata,
                                  schema,
                                  answer_store,
                                  routing_path,
                                  flushed=True)
        message = current_app.eq['encrypter'].encrypt(message)

        sent = current_app.eq['submitter'].send_message(
            message, current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
            metadata["tx_id"])

        if not sent:
            raise SubmissionFailedException()

        get_questionnaire_store(user.user_id, user.user_ik).delete()
        return True
    else:
        return False
Exemplo n.º 2
0
def submit_answers(schema, questionnaire_store, full_routing_path):
    answer_store = questionnaire_store.answer_store
    list_store = questionnaire_store.list_store
    metadata = questionnaire_store.metadata

    message = json.dumps(
        convert_answers(schema, questionnaire_store, full_routing_path), for_json=True
    )

    encrypted_message = encrypt(
        message, current_app.eq["key_store"], KEY_PURPOSE_SUBMISSION
    )
    sent = current_app.eq["submitter"].send_message(
        encrypted_message,
        questionnaire_id=metadata.get("questionnaire_id"),
        case_id=metadata.get("case_id"),
        tx_id=metadata.get("tx_id"),
    )

    if not sent:
        raise SubmissionFailedException()

    submitted_time = datetime.utcnow()

    _store_submitted_time_in_session(submitted_time)

    if is_view_submitted_response_enabled(schema.json):
        _store_viewable_submission(
            answer_store.serialise(), list_store.serialise(), metadata, submitted_time
        )

    get_questionnaire_store(current_user.user_id, current_user.user_ik).delete()

    return redirect(url_for("post_submission.get_thank_you"))
Exemplo n.º 3
0
def send_feedback():

    if 'action[sign_out]' in request.form:
        return redirect(url_for('session.get_sign_out'))

    metadata = get_metadata(current_user)
    if not metadata:
        raise NoTokenException(401)

    form = FeedbackForm()

    if form.validate():
        message = convert_feedback(
            escape(request.form.get('message')),
            escape(request.form.get('name')),
            escape(request.form.get('email')),
            request.referrer or '',
            metadata,
            g.schema.json['survey_id'],
        )

        encrypted_message = encrypt(message, current_app.eq['key_store'], key_purpose=KEY_PURPOSE_SUBMISSION)
        sent = current_app.eq['submitter'].send_message(encrypted_message,
                                                        current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
                                                        metadata['tx_id'])

        if not sent:
            raise SubmissionFailedException()

    if request.form.get('redirect', 'true') == 'true':
        return redirect(url_for('feedback.thank_you'))

    return '', 200
Exemplo n.º 4
0
def _submit_data(user):

    answer_store = get_answer_store(user)

    if answer_store.answers:
        metadata = get_metadata(user)
        collection_metadata = get_collection_metadata(user)
        schema = load_schema_from_metadata(metadata)
        completed_blocks = get_completed_blocks(user)
        routing_path = PathFinder(schema, answer_store, metadata,
                                  completed_blocks).get_full_routing_path()

        message = convert_answers(metadata,
                                  collection_metadata,
                                  schema,
                                  answer_store,
                                  routing_path,
                                  flushed=True)
        encrypted_message = encrypt(message, current_app.eq['key_store'],
                                    KEY_PURPOSE_SUBMISSION)

        sent = current_app.eq['submitter'].send_message(
            encrypted_message, current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
            metadata['tx_id'])

        if not sent:
            raise SubmissionFailedException()

        get_questionnaire_store(user.user_id, user.user_ik).delete()
        return True

    return False
Exemplo n.º 5
0
def submit_answers(eq_id, form_type, collection_id, metadata, answer_store):
    is_completed, invalid_location = is_survey_completed(
        answer_store, metadata)

    if is_completed:
        path_finder = PathFinder(g.schema_json, answer_store, metadata)

        message = convert_answers(metadata, g.schema_json, answer_store,
                                  path_finder.get_routing_path())
        message = current_app.eq['encrypter'].encrypt(message)
        sent = current_app.eq['submitter'].send_message(
            message, current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
            metadata['tx_id'])

        if not sent:
            raise SubmissionFailedException()

        current_app.eq['session_storage'].store_survey_completed_metadata(
            metadata['tx_id'], metadata['period_str'], metadata['ru_ref'])
        get_questionnaire_store(current_user.user_id,
                                current_user.user_ik).delete()
        _remove_survey_session_data()

        return redirect(
            url_for('.get_thank_you',
                    eq_id=eq_id,
                    form_type=form_type,
                    collection_id=collection_id))
    else:
        return redirect(invalid_location.url(metadata))
Exemplo n.º 6
0
 def send_answers(self, message):
     """
     Sends the answers to rabbit mq and returns a timestamp for submission
     :param message: The payload to submit
     :raise: a submission failed exception
     """
     encrypted_message = self.encrypt_message(message)
     sent = self.send_message(encrypted_message,
                              settings.EQ_RABBITMQ_QUEUE_NAME)
     if not sent:
         raise SubmissionFailedException()
Exemplo n.º 7
0
def _submit_data(user):
    answer_store = get_answer_store(user)

    if answer_store:
        questionnaire_store = get_questionnaire_store(user.user_id,
                                                      user.user_ik)
        answer_store = questionnaire_store.answer_store
        metadata = questionnaire_store.metadata
        response_metadata = questionnaire_store.response_metadata
        progress_store = questionnaire_store.progress_store
        list_store = questionnaire_store.list_store
        submitted_at = datetime.now(timezone.utc)
        schema = load_schema_from_metadata(metadata)

        router = Router(
            schema,
            answer_store,
            list_store,
            progress_store,
            metadata,
            response_metadata,
        )
        full_routing_path = router.full_routing_path()

        message = json_dumps(
            convert_answers(
                schema,
                questionnaire_store,
                full_routing_path,
                submitted_at,
                flushed=True,
            ))

        encrypted_message = encrypt(message, current_app.eq["key_store"],
                                    KEY_PURPOSE_SUBMISSION)

        sent = current_app.eq["submitter"].send_message(
            encrypted_message,
            tx_id=metadata.get("tx_id"),
            case_id=metadata["case_id"],
        )

        if not sent:
            raise SubmissionFailedException()

        get_questionnaire_store(user.user_id, user.user_ik).delete()
        logger.info("successfully flushed answers")
        return True

    logger.info("no answers found to flush")
    return False
Exemplo n.º 8
0
def submit_answers(routing_path, eq_id, form_type, schema):
    metadata = get_metadata(current_user)
    collection_metadata = get_collection_metadata(current_user)
    answer_store = get_answer_store(current_user)

    message = json.dumps(
        convert_answers(
            metadata,
            collection_metadata,
            schema,
            answer_store,
            routing_path,
        ))

    encrypted_message = encrypt(message, current_app.eq['key_store'],
                                KEY_PURPOSE_SUBMISSION)
    sent = current_app.eq['submitter'].send_message(
        encrypted_message,
        current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
        metadata['tx_id'],
    )
    if current_app.config['EQ_PUBSUB_ENABLED']:
        current_app.eq['pubsub_submitter'].send_message(
            encrypted_message,
            current_app.config['EQ_PUBSUB_TOPIC_ID'],
            metadata['tx_id'],
        )

    if not sent:
        raise SubmissionFailedException()

    submitted_time = datetime.utcnow()

    _store_submitted_time_in_session(submitted_time)

    if is_view_submitted_response_enabled(schema.json):
        _store_viewable_submission(list(answer_store), metadata,
                                   submitted_time)

    get_questionnaire_store(current_user.user_id,
                            current_user.user_ik).delete()

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))
    def submit_questionnaire(self):

        payload = self.get_payload()
        message = json_dumps(payload)

        encrypted_message = encrypt(message, current_app.eq["key_store"],
                                    KEY_PURPOSE_SUBMISSION)
        submitted = current_app.eq["submitter"].send_message(
            encrypted_message,
            case_id=self._metadata["case_id"],
            tx_id=self._metadata.get("tx_id"),
        )

        if not submitted:
            raise SubmissionFailedException()

        cookie_session["submitted"] = True

        self._store_submitted_time_and_display_address_in_session()
        self._questionnaire_store.delete()