Skip to content

Commit

Permalink
Ajout custom_tag pour authentification requise (#4056)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Jul 11, 2024
1 parent 4b0ddd4 commit 6b71e9a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ defmodule TransportWeb.CustomTagsLive do
end

def tags_suggestions do
DB.Dataset.base_with_hidden_datasets()
|> select([d], fragment("distinct unnest(custom_tags)"))
|> DB.Repo.all()
|> Enum.sort()
tags_in_database =
DB.Dataset.base_with_hidden_datasets()
|> select([dataset: d], fragment("distinct unnest(custom_tags)"))
|> DB.Repo.all()

documented_tags = Enum.map(tags_documentation(), & &1.name)

(tags_in_database ++ documented_tags) |> Enum.sort() |> Enum.dedup()
end

defp tags_documentation do
def tags_documentation do
[
%{name: "licence-mobilités", doc: "Applique la licence mobilités pour ce jeu de données"},
%{
Expand All @@ -64,6 +68,10 @@ defmodule TransportWeb.CustomTagsLive do
name: "masqué",
doc:
"Masque ce jeu de données des statistiques, de la recherche et de l'API. Le jeu reste accessible via son URL directe (web et API)."
},
%{
name: "authentification_requise",
doc: "Indique sur la page du JDD qu'il est nécessaire de s'authentifier pour accéder aux données."
}
]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p :if={seasonal_warning?(@dataset)} class="notification mt-0">
ℹ️ <%= dgettext(
"page-dataset-details",
"This transport service operates seasonally. The associated resources may be outdated depending on the time of year. Contact the data producer through Discussions for more information."
) %>
</p>
<p :if={authentication_required?(@dataset)} class="notification mt-0">
ℹ️ <%= dgettext(
"page-dataset-details",
"The producer requires authentication to access the data. Consequently, some features on transport.data.gouv.fr, such as data availability, validations, and metadata, are unavailable for this dataset. Please follow the producer's instructions to gain access to the data."
) %>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@
</div>
<div class="dataset-infos">
<section>
<p :if={seasonal_warning?(@dataset)} class="notification">
ℹ️ <%= dgettext(
"page-dataset-details",
"This transport service operates seasonally. The associated resources may be outdated depending on the time of year. Contact the data producer through Discussions for more information."
) %>
</p>
<%= render("_banner.html", dataset: @dataset) %>
<div class="panel">
<%= description(@dataset) %>
</div>
Expand Down
5 changes: 4 additions & 1 deletion apps/transport/lib/transport_web/views/dataset_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,10 @@ defmodule TransportWeb.DatasetView do
iex> seasonal_warning?(%DB.Dataset{custom_tags: ["foo"]})
false
"""
def seasonal_warning?(%Dataset{} = dataset), do: DB.Dataset.has_custom_tag?(dataset, "saisonnier")
def seasonal_warning?(%DB.Dataset{} = dataset), do: DB.Dataset.has_custom_tag?(dataset, "saisonnier")

def authentication_required?(%DB.Dataset{} = dataset),
do: DB.Dataset.has_custom_tag?(dataset, "authentification_requise")

@doc """
iex> heart_class(%{42 => :producer}, %DB.Dataset{id: 42})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Manage services for this dataset"
msgstr ""

#, elixir-autogen, elixir-format
msgid "The producer requires authentication to access the data. Consequently, some features on transport.data.gouv.fr, such as data availability, validations, and metadata, are unavailable for this dataset. Please follow the producer's instructions to gain access to the data."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,7 @@ msgstr "Suivre ce jeu de données"
#, elixir-autogen, elixir-format
msgid "Manage services for this dataset"
msgstr "Gérez les services liés à ce jeu de données"

#, elixir-autogen, elixir-format
msgid "The producer requires authentication to access the data. Consequently, some features on transport.data.gouv.fr, such as data availability, validations, and metadata, are unavailable for this dataset. Please follow the producer's instructions to gain access to the data."
msgstr "Le producteur requiert une authentification pour accéder aux données. En conséquence, certaines fonctionnalités de transport.data.gouv.fr, comme la disponibilité des données, les rapports de validations et les métadonnées sont indisponibles pour ce jeu de données. Veuillez suivre les instructions du producteur pour obtenir l'accès aux données."
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 @@ -705,3 +705,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Manage services for this dataset"
msgstr ""

#, elixir-autogen, elixir-format
msgid "The producer requires authentication to access the data. Consequently, some features on transport.data.gouv.fr, such as data availability, validations, and metadata, are unavailable for this dataset. Please follow the producer's instructions to gain access to the data."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -647,20 +647,29 @@ defmodule TransportWeb.DatasetControllerTest do
] == content |> Floki.find("#quality-indicators table")
end

test "a banner is displayed for a seasonal dataset", %{conn: conn} do
dataset = insert(:dataset, is_active: true, custom_tags: ["saisonnier", "foo"])
mock_empty_history_resources()
describe "information 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)

dataset_has_banner_with_text(
conn,
dataset,
"Le service de transport de ce jeu de donnée ne fonctionne pas toute l'année"
)
end

assert TransportWeb.DatasetView.seasonal_warning?(dataset)
test "a dataset with authentication required", %{conn: conn} do
dataset = insert(:dataset, is_active: true, custom_tags: ["authentification_requise"])

[{"p", [{"class", "notification"}], [content]}] =
conn
|> get(dataset_path(conn, :details, dataset.slug))
|> html_response(200)
|> Floki.parse_document!()
|> Floki.find(".notification")
assert TransportWeb.DatasetView.authentication_required?(dataset)

assert content =~ "Le service de transport de ce jeu de donnée ne fonctionne pas toute l'année"
dataset_has_banner_with_text(
conn,
dataset,
"Le producteur requiert une authentification pour accéder aux données"
)
end
end

test "custom logo is displayed when set", %{conn: conn} do
Expand Down Expand Up @@ -798,4 +807,18 @@ defmodule TransportWeb.DatasetControllerTest do
|> Floki.parse_document!()
|> Floki.find(~s|div[data-section="dataset-header-links"] a|)
end

defp dataset_has_banner_with_text(%Plug.Conn{} = conn, %DB.Dataset{slug: slug}, text) do
mock_empty_history_resources()

content =
conn
|> get(dataset_path(conn, :details, slug))
|> html_response(200)
|> Floki.parse_document!()
|> Floki.find(".notification")
|> Floki.text()

assert content =~ text
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ defmodule TransportWeb.CustomTagsLiveTest do
assert rendered_view =~ "requestor_ref:OPENDATA"
end

test "tags_suggestions" do
test "tags_suggestions includes unique tags in the DB + documented tags" do
insert(:dataset, is_active: true, custom_tags: ["foo"])
insert(:dataset, is_active: true, custom_tags: ["foo", "bar"])
insert(:dataset, is_active: true, is_hidden: true, custom_tags: ["baz"])
insert(:dataset, is_active: false, custom_tags: ["nope"])

assert ["bar", "baz", "foo"] == TransportWeb.CustomTagsLive.tags_suggestions()
suggestions = MapSet.new(TransportWeb.CustomTagsLive.tags_suggestions())

assert MapSet.new(["bar", "baz", "foo"]) |> MapSet.subset?(suggestions)

documented_tags = Enum.map(TransportWeb.CustomTagsLive.tags_documentation(), & &1.name)
assert MapSet.new(["bar", "baz", "foo"] ++ documented_tags) |> MapSet.equal?(suggestions)
end
end

0 comments on commit 6b71e9a

Please sign in to comment.