Ejemplo n.º 1
0
def get_gov_users(request, params=None, convert_to_options=False):
    if params:
        query_params = urlencode(params)
        data = get(request, GOV_USERS_URL + "?" + query_params)
    else:
        data = get(request, GOV_USERS_URL)

    if convert_to_options:
        converted = []

        # Hide users without emails (eg system users)
        for user in [user for user in data.json()["results"] if user["email"]]:
            first_name = user.get("first_name")
            last_name = user.get("last_name")
            email = user.get("email")

            if first_name:
                value = first_name + " " + last_name
                description = email
            else:
                value = email
                description = None

            converted.append(
                Option(key=user.get("id"),
                       value=value,
                       description=description))

        return converted
    return data.json(), data.status_code
Ejemplo n.º 2
0
def get_pv_gradings(request, convert_to_options=False):
    if convert_to_options:
        data = get(request, PV_GRADINGS_URL)

        converted_units = []
        for pvg in data.json().get("pv_gradings"):
            for key in pvg:
                converted_units.append(Option(
                    key=key,
                    value=pvg[key],
                ))
        return converted_units

    data = get(request, PV_GRADINGS_URL)
    return data.json().get("pv-gradings")
Ejemplo n.º 3
0
def get_signature_certificate(request):
    certificate = get(request, "/documents/certificate/")
    response = HttpResponse(certificate.content,
                            content_type=certificate.headers["Content-Type"])
    response["Content-Disposition"] = certificate.headers[
        "Content-Disposition"]
    return response
Ejemplo n.º 4
0
def get_open_general_licences(
    request,
    convert_to_options=False,
    name=None,
    site=None,
    status=None,
    case_type=None,
    control_list_entry=None,
    country=None,
    registered=False,
    disable_pagination=True,
    active_only=None,
):
    data = get(
        request, OPEN_GENERAL_LICENCES_URL +
        convert_parameters_to_query_params(locals())).json()

    if convert_to_options:
        return [
            Option(
                key=ogl["id"],
                value=ogl["case_type"]["reference"]["value"] + " (" +
                ogl["name"] + ")",
                tag=OpenGeneralLicenceQuestions.OpenGeneralLicences.
                ALREADY_REGISTERED if ogl["registrations"] else None,
                more_information=ogl["description"],
                disabled=bool(len(ogl["registrations"])),
            ) for ogl in data
        ]

    return data
Ejemplo n.º 5
0
def get_units(request, units=[]):  # noqa
    if units:
        return units
    data = get(request, UNITS_URL).json().get("units")
    for key, value in data.items():
        units.append(Option(key, value))
    return units
Ejemplo n.º 6
0
def get_statuses(request, convert_to_options=False):
    """ Get static list of case statuses. """
    data = get(request, STATUSES_URL)
    if convert_to_options:
        return [Option(key=item["id"], value=item["value"]) for item in data.json().get("statuses")]

    return data.json()["statuses"], data.status_code
Ejemplo n.º 7
0
def get_letter_paragraphs(request, ids: list):
    if not ids:
        return []

    data = get(request, PICKLIST_URL + "?type=letter_paragraph&disable_pagination=True" + "&ids=" + ",".join(ids))
    letter_paragraphs = data.json()["results"]
    return sort_letter_paragraphs(letter_paragraphs, ids)
Ejemplo n.º 8
0
def get_activity(request, pk, activity_filters=None):
    url = CASE_URL + pk + ACTIVITY_URL
    if activity_filters:
        params = convert_parameters_to_query_params(activity_filters)
        url = url + params
    data = get(request, url)
    return data.json()["activity"]
Ejemplo n.º 9
0
def get_compliance_licences(request, case_id, reference, page):
    data = get(
        request,
        COMPLIANCE_URL + case_id + COMPLIANCE_LICENCES_URL +
        f"?reference={reference}&page={page}",
    )
    return data.json()
Ejemplo n.º 10
0
def has_existing_applications_and_licences_and_nlrs(request):
    """
    Returns if an hmrc org has any submitted queries
    Returns if a standard org has any applications & licences
    """
    data = get(request, APPLICATIONS_URL + "existing/")
    return data.json()
Ejemplo n.º 11
0
def get_queues(
    request,
    disable_pagination=True,
    page=1,
    convert_to_options=False,
    users_team_first=False,
    include_system=False,
    name=None,
):
    data = get(request, QUEUES_URL + convert_parameters_to_query_params(locals())).json()

    if convert_to_options:
        options = []

        for queue in data:
            option = Option(queue.get("id"), queue.get("name"))

            queue_team = queue.get("team")
            if queue_team:
                option.description = queue_team.get("name")
                option.data_attribute = queue_team.get("id")

            options.append(option)

        return options
    else:
        return data
Ejemplo n.º 12
0
def get_external_locations(request,
                           pk,
                           convert_to_options=False,
                           exclude: list = None,
                           application_type: str = None):
    data = get(
        request,
        ORGANISATIONS_URL + str(pk) + EXTERNAL_LOCATIONS_URL + "?" +
        convert_value_to_query_param("exclude", exclude) + "&" +
        convert_value_to_query_param("application_type", application_type),
    )

    if convert_to_options:
        external_locations_options = []

        for external_location in data.json().get("external_locations"):
            external_location_id = external_location.get("id")
            external_location_name = external_location.get("name")
            external_location_address = ((
                external_location.get("address") + NEWLINE +
                external_location.get("country").get("name"))
                                         if external_location.get("country")
                                         else external_location.get("address"))

            external_locations_options.append(
                Option(external_location_id,
                       external_location_name,
                       description=external_location_address))

        return external_locations_options

    return data.json(), data.status_code
Ejemplo n.º 13
0
def get_open_licence_return_download(request, pk):
    data = get(request, OPEN_LICENCE_RETURNS_URL + str(pk) + "/")
    open_licence_returns = data.json()
    response = HttpResponse("\n" + open_licence_returns["returns_data"],
                            content_type="text/csv")
    response[
        "Content-Disposition"] = f'attachment; filename="{open_licence_returns["year"]}{FILENAME}"'
    return response
Ejemplo n.º 14
0
def get_users_team_queues(request, user, convert_to_options=True):
    data = get(request, "/users/" + user + "/team-queues/").json()
    if convert_to_options:
        return [
            Option(key=queue[0], value=queue[1], description=None)
            for queue in data["queues"]
        ]
    return data, data.status_code
Ejemplo n.º 15
0
def get_users_by_team(request, pk, convert_to_options=False):
    data = get(request, TEAMS_URL + pk + "/users")
    if convert_to_options:
        return [
            Option(user["id"], user["email"]) for user in data.json()["users"]
            if user["email"]
        ]
    return data.json(), data.status_code
Ejemplo n.º 16
0
def get_application_ecju_queries(request, pk):
    data = get(request,
               CASES_URL + pk + ECJU_QUERIES_URL).json()["ecju_queries"]

    open_queries = [x for x in data if not x["response"]]
    closed_queries = [x for x in data if x["response"]]

    return open_queries, closed_queries
Ejemplo n.º 17
0
def get_picklists_list(request,
                       type,
                       page=1,
                       name=None,
                       disable_pagination=False,
                       show_deactivated=True):
    response = get(request,
                   PICKLIST_URL + convert_parameters_to_query_params(locals()))
    return response.json()
Ejemplo n.º 18
0
def get_goods(request,
              page: int = 1,
              description=None,
              part_number=None,
              control_list_entry=None,
              for_application=None):
    data = get(request,
               GOODS_URL + convert_parameters_to_query_params(locals()))
    return data.json()
Ejemplo n.º 19
0
def get_flags_for_team_of_level(request, level, team_id, include_system_flags=False):
    """
    :param request: headers for the request
    :param level: 'cases', 'goods'
    :param include_system_flags: used to indicate adding system flags to list of team flags returned
    :return:
    """
    data = get(request, FLAGS_URL + convert_parameters_to_query_params(locals()) + "&disable_pagination=True")
    return data.json(), data.status_code
Ejemplo n.º 20
0
def get_enforcement_xml(request, queue_pk):
    data = get(request, ENFORCEMENT_URL + str(queue_pk))

    # Check if XML
    if data.headers._store["content-type"][1] == "text/xml":
        response = HttpResponse(data.content, content_type="text/xml")
        response["Content-Disposition"] = 'attachment; filename="enforcement_check.xml"'
        return response, data.status_code
    else:
        return None, data.status_code
Ejemplo n.º 21
0
def get_applications(request, page: int = 1, submitted: bool = True):
    """
    Returns a list of applications
    :param request: Standard HttpRequest object
    :param page: Returns n page of page results
    :param submitted: Returns submitted applications if True, else returns draft applications if False
    """
    data = get(request,
               APPLICATIONS_URL + convert_parameters_to_query_params(locals()))
    return data.json()
Ejemplo n.º 22
0
def get_gov_pv_gradings(request, convert_to_options=False):
    pv_gradings = get(request, GOV_PV_GRADINGS_URL).json().get("pv_gradings")
    if convert_to_options:
        converted_units = []
        for pv_grading_entry in pv_gradings:
            for key in pv_grading_entry:
                converted_units.append(Option(key=key, value=pv_grading_entry[key]))
        return converted_units

    return pv_gradings
Ejemplo n.º 23
0
def get_gov_user_from_form_selection(request, pk, json):
    user = json.get("user")
    if user:
        data = get(request, GOV_USERS_URL + json.get("user"))
        return data.json(), data.status_code
    return {
        "errors": {
            "user": [AssignUserPage.USER_ERROR_MESSAGE]
        }
    }, HTTPStatus.BAD_REQUEST
Ejemplo n.º 24
0
def get_document_download_stream(request, url):
    response = get(request, url)
    if response.status_code == HTTPStatus.OK:
        return StreamingHttpResponse(
            response, content_type=response.headers._store["content-type"][1])
    elif response.status_code == HTTPStatus.UNAUTHORIZED:
        error = Document.ACCESS_DENIED
    else:
        error = Document.DOWNLOAD_ERROR
    return error_page(request, error)
Ejemplo n.º 25
0
def get_compliance_people_present(request, case_id):
    data = get(
        request,
        COMPLIANCE_URL
        + COMPLIANCE_VISIT_URL
        + str(case_id)
        + "/"
        + COMPLIANCE_PEOPLE_PRESENT_URL
        + "?disable_pagination=True",
    )
    return data.json()
Ejemplo n.º 26
0
def get_user(request, pk=None, params=None):
    if pk:
        url = USERS_URL + str(pk)
    else:
        url = USERS_URL + "me/"
    if params:
        from core.helpers import convert_dict_to_query_params

        url = url + "?" + convert_dict_to_query_params(params)

    return get(request, url).json()
Ejemplo n.º 27
0
def get_organisations(request, page: int = 1, search_term=None, org_type=None):
    """
    Returns a list of organisations
    :param request: Standard HttpRequest object
    :param page: Returns n page of page results
    :param search_term: Filter by name
    :param org_type: Filter by org type - 'hmrc', 'commercial', 'individual', or an array of it
    """
    data = get(
        request,
        ORGANISATIONS_URL + convert_parameters_to_query_params(locals()))
    return data.json()
Ejemplo n.º 28
0
def get_control_list_entries(request,
                             convert_to_options=False,
                             converted_control_list_entries_cache=[]):  # noqa
    if convert_to_options:
        if converted_control_list_entries_cache:
            return converted_control_list_entries_cache
        else:
            data = get(request, CONTROL_LIST_ENTRIES_URL + "?flatten=True")

        for control_list_entry in data.json().get("control_list_entries"):
            converted_control_list_entries_cache.append(
                Option(
                    key=control_list_entry["rating"],
                    value=control_list_entry["rating"],
                    description=control_list_entry["text"],
                ))

        return converted_control_list_entries_cache

    data = get(request, CONTROL_LIST_ENTRIES_URL)
    return data.json().get("control_list_entries")
Ejemplo n.º 29
0
def get_roles(request, convert_to_options=False):
    data = get(request, GOV_USERS_ROLES_URL)

    if convert_to_options:
        converted = []

        for item in data.json().get("roles"):
            converted.append(Option(key=item["id"], value=item["name"]))

        return converted

    return data.json(), data.status_code
Ejemplo n.º 30
0
def get_permissions(request, convert_to_options=False):
    data = get(request, GOV_USERS_PERMISSIONS_URL)

    if convert_to_options:
        converted = []

        for item in data.json().get("permissions"):
            converted.append(Option(key=item["id"], value=item["name"]))

        return converted

    return data.json()["permissions"]