Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api) : Remove the now useless "proxy" to a given service #247

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions api/src/data_inclusion/api/inclusion_data/routes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Annotated, TypeVar

from furl import furl
from pydantic.json_schema import SkipJsonSchema

import fastapi
from fastapi.responses import RedirectResponse

from data_inclusion import schema as di_schema
from data_inclusion.api import auth
Expand Down Expand Up @@ -130,44 +128,6 @@ def retrieve_service_endpoint(
return services.retrieve_service(db_session=db_session, source=source, id_=id)


@router.get(
"/services/{source}/{id}/redirige",
include_in_schema=False,
)
def redirect_service_endpoint(
request: fastapi.Request,
source: Annotated[str, fastapi.Path()],
id: Annotated[str, fastapi.Path()],
depuis: Annotated[str, fastapi.Query()],
db_session=fastapi.Depends(db.get_session),
):
"""Redirige vers le lien source du service donné"""

# This endpoint is not token restricted.
# This is to record redirections stemming from 3rd party website
# like les emplois, while keeping things simple for the 3rd party.

# The required `depuis` query param only purpose is to associate
# the query to a consumer, since there is not token authentication.

# The redirection should forward any other query parameters, such
# as utm query parameters

service_instance = services.retrieve_service(
db_session=db_session, source=source, id_=id
)

if service_instance.lien_source is None:
return fastapi.Response(status_code=fastapi.status.HTTP_404_NOT_FOUND)

params = dict(request.query_params)
del params["depuis"]

target_url = furl(str(service_instance.lien_source)).add(params)

return RedirectResponse(str(target_url))


@router.get(
"/search/services",
response_model=pagination.BigPage[schemas.ServiceSearchResult],
Expand Down
36 changes: 0 additions & 36 deletions api/tests/e2e/api/test_inclusion_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from unittest.mock import ANY

import pytest
import sqlalchemy as sqla

from data_inclusion import schema
from data_inclusion.api.request import models
from data_inclusion.api.utils import soliguide

from ... import factories
Expand Down Expand Up @@ -1340,37 +1338,3 @@ def test_retrieve_service_and_notify_soliguide(

assert response.status_code == status_code
assert fake_soliguide_client.retrieved_ids == retrieved_ids


@pytest.mark.parametrize(
("lien_source", "depuis", "status_code"),
[
("https://dora.incubateur.net/", "les-emplois", 307),
("https://dora.incubateur.net/", None, 422),
(None, "les-emplois", 404),
],
)
def test_redirect_service(api_client, lien_source, depuis, status_code, db_session):
service = factories.ServiceFactory(lien_source=lien_source)

url = "/api/v0/services/"
params = {"mtm_campaign": "LesEmplois"}
if depuis is not None:
params["depuis"] = depuis
response = api_client.get(
url + f"{service.source}/{service.id}/redirige",
follow_redirects=False,
params=params,
)

assert response.status_code == status_code

if status_code == 307:
assert response.headers["location"] == f"{lien_source}?mtm_campaign=LesEmplois"

assert (
db_session.scalar(
sqla.select(sqla.func.count()).select_from(models.Request)
)
== 1
)
Loading