diff --git a/apps/transport/lib/transport_web/endpoint.ex b/apps/transport/lib/transport_web/endpoint.ex index f915f2c566..5d78f922b0 100644 --- a/apps/transport/lib/transport_web/endpoint.ex +++ b/apps/transport/lib/transport_web/endpoint.ex @@ -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 diff --git a/apps/transport/lib/transport_web/live/discussions_live.ex b/apps/transport/lib/transport_web/live/discussions_live.ex index 24f3f35fed..149506881d 100644 --- a/apps/transport/lib/transport_web/live/discussions_live.ex +++ b/apps/transport/lib/transport_web/live/discussions_live.ex @@ -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 diff --git a/apps/transport/test/transport_web/live_views/discussions_live_test.exs b/apps/transport/test/transport_web/live_views/discussions_live_test.exs index 9957921e61..8e9eb38aa8 100644 --- a/apps/transport/test/transport_web/live_views/discussions_live_test.exs +++ b/apps/transport/test/transport_web/live_views/discussions_live_test.exs @@ -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, @@ -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, @@ -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) diff --git a/config/prod.exs b/config/prod.exs index 723cd72f58..5e4fd11b1c 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -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 diff --git a/config/runtime.exs b/config/runtime.exs index a21feb0607..38bd3cdb6f 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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.