Skip to content

Commit

Permalink
Datasets expérimentaux (#4281)
Browse files Browse the repository at this point in the history
* API datasets: exclure les datasets experimentaux

See #4275.

* Datasets: label experimental

Fixes #4275.

* Emoji avertissement et affichage en priorité.

* Test de l'affichage de la banière "expérimental"
  • Loading branch information
ptitfred authored Oct 30, 2024
1 parent 45f0c29 commit e07b830
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apps/transport/lib/db/dataset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule DB.Dataset do
@licences_ouvertes ["fr-lo", "lov2"]
@licence_mobilités_tag "licence-mobilités"
@hidden_dataset_custom_tag_value "masqué"
@experimental_tag "experimental"

typed_schema "dataset" do
field(:datagouv_id, :string)
Expand Down Expand Up @@ -1125,4 +1126,17 @@ defmodule DB.Dataset do
@spec full_logo(__MODULE__.t()) :: binary()
def full_logo(%__MODULE__{full_logo: full_logo, custom_full_logo: custom_full_logo}),
do: custom_full_logo || full_logo

@doc """
iex> experimental?(%DB.Dataset{custom_tags: ["experimental", "foo"]})
true
iex> experimental?(%DB.Dataset{custom_tags: ["foo"]})
false
"""
def experimental?(%__MODULE__{} = dataset), do: has_custom_tag?(dataset, @experimental_tag)

def reject_experimental_datasets(queryable) do
queryable
|> where([d], @experimental_tag not in d.tags)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ defmodule TransportWeb.API.DatasetController do
def by_id(%Plug.Conn{} = conn, %{"id" => datagouv_id}) do
dataset =
Dataset
|> Dataset.reject_experimental_datasets()
|> preload([:resources, :aom, :region, :communes, :legal_owners_aom, :legal_owners_region])
|> Repo.get_by(datagouv_id: datagouv_id)

Expand All @@ -95,6 +96,7 @@ defmodule TransportWeb.API.DatasetController do
@spec geojson_by_id(Plug.Conn.t(), map) :: Plug.Conn.t()
def geojson_by_id(%Plug.Conn{} = conn, %{"id" => id}) do
Dataset
|> Dataset.reject_experimental_datasets()
|> Repo.get_by(datagouv_id: id)
|> Repo.preload([:aom, :region, :communes])
|> case do
Expand Down Expand Up @@ -374,6 +376,7 @@ defmodule TransportWeb.API.DatasetController do

%{}
|> Dataset.list_datasets()
|> Dataset.reject_experimental_datasets()
|> preload([:resources, :aom, :region, :communes, :legal_owners_aom, :legal_owners_region])
|> Repo.all()
|> Enum.map(fn dataset ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ defmodule TransportWeb.CustomTagsLive do
%{
name: "authentification_requise",
doc: "Indique sur la page du JDD qu'il est nécessaire de s'authentifier pour accéder aux données."
},
%{
name: "experimental",
doc: "Ajoute sur la page du JDD une bannière indiquant que le jeu est expérimental"
}
]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<p :if={experimental?(@dataset)} class="notification warning mt-0">
⚠️ <%= dgettext(
"page-dataset-details",
"This unofficial dataset is provided experimentally. Do not use it for travel information purpose."
) %>
</p>
<p :if={seasonal_warning?(@dataset)} class="notification mt-0">
ℹ️ <%= dgettext(
"page-dataset-details",
Expand Down
1 change: 1 addition & 0 deletions apps/transport/lib/transport_web/views/dataset_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule TransportWeb.DatasetView do
# ~H expects a variable named `assigns`, so wrapping the calls to `~H` inside
# a helper function would be cleaner and more future-proof to avoid conflicts at some point.
import Phoenix.Component, only: [sigil_H: 2, live_render: 3]
import DB.Dataset, only: [experimental?: 1]
import DB.MultiValidation, only: [get_metadata_info: 2, get_metadata_info: 3]
alias Shared.DateTimeDisplay
alias Transport.Validators.GTFSTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Data under the responsibility of"
msgstr ""

#, elixir-autogen, elixir-format
msgid "This unofficial dataset is provided experimentally. Do not use it for travel information purpose."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,7 @@ msgstr "Le producteur requiert une authentification pour accéder aux données.
#, elixir-autogen, elixir-format
msgid "Data under the responsibility of"
msgstr "Données sous la responsabilité de"

#, elixir-autogen, elixir-format
msgid "This unofficial dataset is provided experimentally. Do not use it for travel information purpose."
msgstr "Ce jeu de données non officiel est publié à titre expérimental. Veuillez à ne pas le réutiliser à des fins d'information voyageur."
4 changes: 4 additions & 0 deletions apps/transport/priv/gettext/page-dataset-details.pot
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Data under the responsibility of"
msgstr ""

#, elixir-autogen, elixir-format
msgid "This unofficial dataset is provided experimentally. Do not use it for travel information purpose."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,54 @@ defmodule TransportWeb.API.DatasetControllerTest do
assert_schema(json, "DatasetsResponse", TransportWeb.API.Spec.spec())
end

test "GET /api/datasets without the experimental tagged datasets", %{conn: conn} do
aom = insert(:aom, nom: "Angers Métropole", siren: "siren")

insert(:resource,
dataset:
insert(:dataset,
custom_title: "TC",
type: "public-transit",
licence: "lov2",
datagouv_id: "datagouv-1",
slug: "slug-1",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
aom: aom,
tags: ["netex"]
),
url: "https://link.to/gbfs.json",
datagouv_id: "1",
type: "main",
format: "gbfs"
)

insert(:resource,
dataset:
insert(:dataset,
custom_title: "Tarifs (expérimental)",
type: "public-transit",
licence: "lov2",
datagouv_id: "datagouv-2",
slug: "slug-2",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
aom: aom,
tags: ["netex", "experimental"]
),
url: "https://link.to/gbfs.json",
datagouv_id: "2",
type: "main",
format: "gbfs"
)

path = Helpers.dataset_path(conn, :datasets)

json = conn |> get(path) |> json_response(200)

assert [%{"title" => "TC"}] = json
end

test "GET /api/datasets/:id *without* history, multi_validation and resource_metadata", %{conn: conn} do
aom = insert(:aom, nom: "Angers Métropole", siren: "siren", id: 4242)
region = DB.Region |> Ecto.Query.where(insee: "52") |> DB.Repo.one!()
Expand Down Expand Up @@ -506,6 +554,35 @@ defmodule TransportWeb.API.DatasetControllerTest do
|> json_response(200)
end

test "GET /api/datasets/:id with a dataset tagged 'experimental'", %{conn: conn} do
setup_empty_history_resources()

%DB.Dataset{datagouv_id: visible_dataset_datagouv_id} =
insert(:dataset,
datagouv_id: "datagouv-1",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
tags: ["netex"]
)

%DB.Dataset{datagouv_id: experimental_dataset_datagouv_id} =
insert(:dataset,
datagouv_id: "datagouv-2",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
tags: ["netex", "experimental"]
)

assert %{"datagouv_id" => ^visible_dataset_datagouv_id} =
conn
|> get(Helpers.dataset_path(conn, :by_id, visible_dataset_datagouv_id))
|> json_response(200)

conn
|> get(Helpers.dataset_path(conn, :by_id, experimental_dataset_datagouv_id))
|> json_response(404)
end

test "gtfs-rt features are filled", %{conn: conn} do
dataset_1 = insert(:dataset, datagouv_id: datagouv_id_1 = Ecto.UUID.generate())
resource_1 = insert(:resource, dataset_id: dataset_1.id, format: "gtfs-rt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ defmodule TransportWeb.DatasetControllerTest do
] == content |> Floki.find("#quality-indicators table")
end

describe "information banners are displayed" do
describe "information & warning banners are displayed" do
test "a seasonal dataset", %{conn: conn} do
dataset = insert(:dataset, is_active: true, custom_tags: ["saisonnier", "foo"])
assert TransportWeb.DatasetView.seasonal_warning?(dataset)
Expand All @@ -702,6 +702,17 @@ defmodule TransportWeb.DatasetControllerTest do
"Le producteur requiert une authentification pour accéder aux données"
)
end

test "an experimental dataset", %{conn: conn} do
dataset = insert(:dataset, is_active: true, custom_tags: ["experimental", "foo"])
assert DB.Dataset.experimental?(dataset)

dataset_has_banner_with_text(
conn,
dataset,
"Ce jeu de données non officiel est publié à titre expérimental. Veuillez à ne pas le réutiliser à des fins d'information voyageur."
)
end
end

test "custom logo is displayed when set", %{conn: conn} do
Expand Down

0 comments on commit e07b830

Please sign in to comment.