Skip to content

Commit

Permalink
Merge branch 'master' into espace_producteur_download_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Jan 18, 2024
2 parents d215e73 + 7a766f1 commit 6eaf65b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
15 changes: 0 additions & 15 deletions apps/transport/lib/transport_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,4 @@ defmodule TransportWeb.Endpoint do
plug(Plug.Session, @session_options)

plug(TransportWeb.Plugs.Router)

@doc """
Callback invoked for dynamically configuring the endpoint.
It receives the endpoint configuration and checks if
configuration should be loaded from the system environment.
"""
def init(_key, config) do
if config[:load_from_system_env] do
port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
{:ok, Keyword.put(config, :http, [:inet6, port: port])}
else
{:ok, config}
end
end
end
6 changes: 3 additions & 3 deletions apps/transport/lib/transport_web/live/discussions_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ defmodule TransportWeb.DiscussionsLive do
end
end

defp organization_info(%DB.Dataset{organization: nil}), do: :no_organization
defp organization_info(%DB.Dataset{organization_id: nil}), do: :no_organization

defp organization_info(%DB.Dataset{organization: organization}) when is_binary(organization) do
Datagouvfr.Client.Organization.Wrapper.get(organization, restrict_fields: true)
defp organization_info(%DB.Dataset{organization_id: organization_id}) when is_binary(organization_id) do
Datagouvfr.Client.Organization.Wrapper.get(organization_id, restrict_fields: true)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ defmodule Transport.TransportWeb.DiscussionsLiveTest do
end

test "render some discussions", %{conn: conn} do
dataset = insert(:dataset, datagouv_id: datagouv_id = Ecto.UUID.generate(), organization: "producer_org")
dataset =
insert(:dataset,
datagouv_id: datagouv_id = Ecto.UUID.generate(),
organization_id: organization_id = Ecto.UUID.generate()
)

Datagouvfr.Client.Discussions.Mock |> expect(:get, 1, fn ^datagouv_id -> discussions() end)

Datagouvfr.Client.Organization.Mock
|> expect(:get, 1, fn "producer_org", [restrict_fields: true] -> organization() end)
|> expect(:get, 1, fn ^organization_id, [restrict_fields: true] -> organization() end)

{:ok, view, _html} =
live_isolated(conn, TransportWeb.DiscussionsLive,
Expand Down Expand Up @@ -52,11 +56,12 @@ defmodule Transport.TransportWeb.DiscussionsLiveTest do
end

test "renders even if data.gouv is down", %{conn: conn} do
dataset = insert(:dataset, datagouv_id: datagouv_id = Ecto.UUID.generate(), organization: "producer_org")
dataset =
insert(:dataset, datagouv_id: datagouv_id = Ecto.UUID.generate(), organization_id: org_id = Ecto.UUID.generate())

# in case of request failure, the function returns an empty list.
Datagouvfr.Client.Discussions.Mock |> expect(:get, 1, fn ^datagouv_id -> [] end)
Datagouvfr.Client.Organization.Mock |> expect(:get, 1, fn _id, _opts -> {:error, "error reason"} end)
Datagouvfr.Client.Organization.Mock |> expect(:get, 1, fn ^org_id, _opts -> {:error, "error reason"} end)

assert {:ok, view, _html} =
live_isolated(conn, TransportWeb.DiscussionsLive,
Expand All @@ -73,7 +78,7 @@ defmodule Transport.TransportWeb.DiscussionsLiveTest do
end

test "renders even if there is no organization", %{conn: conn} do
dataset = insert(:dataset, datagouv_id: datagouv_id = Ecto.UUID.generate(), organization: nil)
dataset = insert(:dataset, datagouv_id: datagouv_id = Ecto.UUID.generate(), organization_id: nil)

Datagouvfr.Client.Discussions.Mock |> expect(:get, 1, fn ^datagouv_id -> discussions() end)

Expand Down
10 changes: 0 additions & 10 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import Config

config :transport, TransportWeb.Endpoint,
http: [port: {:system, "PORT"}, compress: true],
url: [scheme: "https", host: System.get_env("DOMAIN_NAME", "transport.data.gouv.fr"), port: 443],
cache_static_manifest: "priv/static/cache_manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE"),
force_ssl: [rewrite_on: [:x_forwarded_proto]],
live_view: [
signing_salt: System.get_env("SECRET_KEY_BASE")
]

config :transport,
# The key used by Cloak. See `Transport.Vault`.
# This value should be base64 encrypted
Expand Down
10 changes: 10 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ if config_env() == :prod do
# under "Queue config". For most users, configuring :timeout is enough, as it now includes both queue and query time
timeout: 15_000

config :transport, TransportWeb.Endpoint,
http: [port: System.get_env("PORT"), compress: true],
url: [scheme: "https", host: System.get_env("DOMAIN_NAME"), port: 443],
cache_static_manifest: "priv/static/cache_manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE"),
force_ssl: [rewrite_on: [:x_forwarded_proto]],
live_view: [
signing_salt: System.get_env("SECRET_KEY_BASE")
]

if app_env == :production do
# data.gouv.fr IDs for national databases created automatically and
# published by us on data.gouv.fr.
Expand Down

0 comments on commit 6eaf65b

Please sign in to comment.