Example #1
0
def get_selected_businesses():
    """
    This function returns list of business objects against selected business_ids in flask session
    return: list
    """
    selected_businesses = []
    for business_id in flask_session["share_survey_data"]:
        selected_businesses.append(get_business_by_id(business_id))
    return selected_businesses
Example #2
0
def share_survey_survey_select(session):
    party_id = session.get_party_id()
    surveys = get_surveys_listed_against_party_and_business_id(
        flask_session['share_survey_business_selected'], party_id)
    is_max_share_survey = request.args.get('max_share_survey', False)
    flask_session['share_survey_surveys_selected'] = None
    selected_business = get_business_by_id(
        [flask_session['share_survey_business_selected']])
    return render_template('surveys/surveys-share/survey-select.html',
                           surveys=surveys,
                           business_name=selected_business[0]['name'],
                           is_max_share_survey=is_max_share_survey)
Example #3
0
def send_instruction_get(session):
    email = flask_session['share_survey_recipient_email_address']
    selected_surveys = []
    for survey_id in flask_session['share_survey_surveys_selected']:
        selected_surveys.append(
            survey_controller.get_survey(app.config['SURVEY_URL'],
                                         app.config['BASIC_AUTH'], survey_id))
    selected_business = get_business_by_id(
        [flask_session['share_survey_business_selected']])
    return render_template('surveys/surveys-share/send-instructions.html',
                           email=email,
                           surveys=selected_surveys,
                           form=ConfirmEmailChangeForm(),
                           business_name=selected_business[0]['name'])
Example #4
0
def send_instruction_get(session):
    email = flask_session["share_survey_recipient_email_address"]
    share_dict = {}
    for business_id in flask_session["share_survey_data"]:
        selected_business = get_business_by_id(business_id)
        surveys = []
        for survey_id in flask_session["share_survey_data"][business_id]:
            surveys.append(
                survey_controller.get_survey(app.config["SURVEY_URL"],
                                             app.config["BASIC_AUTH"],
                                             survey_id))
        share_dict[selected_business[0]["id"]] = {
            "name": selected_business[0]["name"],
            "surveys": surveys,
        }
    return render_template(
        "surveys/surveys-share/send-instructions.html",
        email=email,
        share_dict=share_dict,
        form=ConfirmEmailChangeForm(),
    )
Example #5
0
def share_survey_survey_select(session):
    party_id = session.get_party_id()
    share_dict = {}
    for business_id in flask_session["share_survey_data"]:
        selected_business = get_business_by_id(business_id)
        surveys = get_surveys_listed_against_party_and_business_id(
            business_id, party_id)
        share_dict[selected_business[0]["id"]] = {
            "name": selected_business[0]["name"],
            "surveys": surveys,
        }
    error = request.args.get("error", "")
    failed_surveys_list = flask_session.get(
        "validation_failure_share_surveys_list")
    selected_survey_list = flask_session.get("share_surveys_selected_list")
    return render_template(
        "surveys/surveys-share/survey-select.html",
        share_dict=share_dict,
        error=error,
        failed_surveys_list=failed_surveys_list
        if failed_surveys_list is not None else [],
        selected_survey_list=selected_survey_list
        if selected_survey_list is not None else [],
    )
def get_share_survey_summary(token):
    """
    Endpoint to verify token and retrieve the summary page
    :param token: share survey token
    :type token: str
    """
    logger.info("Getting share survey summary", token=token)
    try:
        response = party_controller.verify_pending_survey_token(token)
        pending_share_surveys = response.json()
        share_dict = {}
        distinct_businesses = set()
        batch_number = pending_share_surveys[0]["batch_no"]
        originator_party = party_controller.get_respondent_party_by_id(
            pending_share_surveys[0]["shared_by"])
        shared_by = originator_party["emailAddress"]
        for pending_share_survey in pending_share_surveys:
            distinct_businesses.add(pending_share_survey["business_id"])
        for business_id in distinct_businesses:
            business_surveys = []
            for pending_share_survey in pending_share_surveys:
                if pending_share_survey["business_id"] == business_id:
                    business_surveys.append(
                        survey_controller.get_survey(
                            app.config["SURVEY_URL"], app.config["BASIC_AUTH"],
                            pending_share_survey["survey_id"]))
            selected_business = get_business_by_id(business_id)
            share_dict[selected_business[0]["id"]] = {
                "name": selected_business[0]["name"],
                "trading_as": selected_business[0]["trading_as"],
                "surveys": business_surveys,
            }
        return render_template("surveys/surveys-share/summary.html",
                               share_dict=share_dict,
                               batch_no=batch_number,
                               shared_by=shared_by)

    except ApiError as exc:
        # Handle api errors
        if exc.status_code == 409:
            logger.info(
                "Expired share survey email verification token",
                token=token,
                api_url=exc.url,
                api_status_code=exc.status_code,
            )
            return render_template("surveys/surveys-link-expired.html",
                                   is_transfer=False)
        elif exc.status_code == 404:
            logger.warning(
                "Unrecognised share survey email verification token",
                token=token,
                api_url=exc.url,
                api_status_code=exc.status_code,
            )
            return render_template("surveys/surveys-link-not-valid.html",
                                   is_transfer=False)
        else:
            logger.info("Failed to verify share survey email",
                        token=token,
                        api_url=exc.url,
                        api_status_code=exc.status_code)
            raise exc