Skip to content

Commit

Permalink
Suppression feature flag espace réutilisateur
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Dec 18, 2024
1 parent 8f9d6d3 commit 5f3612e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 102 deletions.
12 changes: 0 additions & 12 deletions apps/transport/lib/transport_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ defmodule TransportWeb.Router do
pipeline :reuser_space do
plug(:browser)
plug(:authentication_required, destination_path: "/infos_reutilisateurs")
plug(:check_reuser_space_enabled)
end

scope "/", OpenApiSpex.Plug do
Expand Down Expand Up @@ -387,17 +386,6 @@ defmodule TransportWeb.Router do
end
end

def check_reuser_space_enabled(%Plug.Conn{} = conn, _) do
if TransportWeb.Session.display_reuser_space?(conn) do
conn
else
conn
|> put_flash(:info, dgettext("alert", "This feature is currently not available."))
|> redirect(to: "/")
|> halt()
end
end

# Check that a secret key is passed in the URL in the `export_key` query parameter
defp check_export_secret_key(%Plug.Conn{params: params} = conn, _) do
export_key_value = Map.get(params, "export_key", "")
Expand Down
17 changes: 0 additions & 17 deletions apps/transport/lib/transport_web/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ defmodule TransportWeb.Session do
DB.Dataset.base_query() |> where([dataset: d], d.organization_id in ^org_ids) |> DB.Repo.exists?()
end

@doc """
A temporary helper method to determine if we should display "reuser space features".
Convenient method to find various entrypoints in the codebase:
- links and buttons to the reuser space
- follow dataset hearts (search results, dataset pages)
- reuser space
Enable it for everybody but keep a "kill switch" to disable it quickly
by setting an environment variable and rebooting the app.
transport.data.gouv.fr admins get access no matter what.
"""
def display_reuser_space?(%Plug.Conn{} = conn) do
feature_disabled = Application.fetch_env!(:transport, :disable_reuser_space)
admin?(conn) or not feature_disabled
end

@spec set_session_attribute_attribute(Plug.Conn.t(), binary(), boolean()) :: Plug.Conn.t()
defp set_session_attribute_attribute(%Plug.Conn{} = conn, key, value) do
current_user = current_user(conn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@
<i class="fa fa-external-link-alt"></i>
<%= link("Backoffice", to: backoffice_page_path(@conn, :edit, @dataset.id)) %> &middot;
<% end %>
<%= if TransportWeb.Session.display_reuser_space?(@conn) do %>
<i class="fa fa-external-link-alt"></i>
<%= if @current_user do %>
<%= if @is_producer do %>
<%= link(dgettext("default", "Producer space"),
to: espace_producteur_path(@conn, :edit_dataset, @dataset.id, utm_campaign: "dataset_details"),
<i class="fa fa-external-link-alt"></i>
<%= if @current_user do %>
<%= if @is_producer do %>
<%= link(dgettext("default", "Producer space"),
to: espace_producteur_path(@conn, :edit_dataset, @dataset.id, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% else %>
<%= if @follows_dataset do %>
<%= link(dgettext("default", "Reuser space"),
to: reuser_space_path(@conn, :datasets_edit, @dataset.id, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% else %>
<%= if @follows_dataset do %>
<%= link(dgettext("default", "Reuser space"),
to: reuser_space_path(@conn, :datasets_edit, @dataset.id, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% else %>
<%= link(dgettext("default", "Reuser space"),
to: reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% end %>
<%= link(dgettext("default", "Reuser space"),
to: reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% end %>
<% else %>
<%= link(dgettext("default", "Reuser space"),
to: page_path(@conn, :infos_reutilisateurs, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% end %>
<% else %>
<%= link(dgettext("default", "Reuser space"),
to: page_path(@conn, :infos_reutilisateurs, utm_campaign: "dataset_details"),
target: "_blank"
) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@
</div>
<div class="dataset-metas">
<div class="panel">
<%= if TransportWeb.Session.display_reuser_space?(@conn) do %>
<%= live_render(@conn, TransportWeb.Live.FollowDatasetLive,
session: %{"current_user" => @current_user, "dataset_id" => @dataset.id}
) %>
<% end %>
<%= live_render(@conn, TransportWeb.Live.FollowDatasetLive,
session: %{"current_user" => @current_user, "dataset_id" => @dataset.id}
) %>
<div class="dataset__logo">
<%= img_tag(DB.Dataset.full_logo(@dataset), alt: @dataset.custom_title) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@
</div>
</div>
<div class="dataset__type">
<%= if not is_nil(@current_user) and TransportWeb.Session.display_reuser_space?(@conn) do %>
<i class={heart_class(@dataset_heart_values, dataset)}></i>
<% end %>
<i class={heart_class(@dataset_heart_values, dataset)}></i>
<%= unless is_nil(icon_type_path(dataset)) do %>
<%= img_tag(icon_type_path(dataset), alt: dataset.type) %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@
to: page_path(@conn, :espace_producteur, utm_campaign: "menu_dropdown")
) %>
<% end %>
<%= if TransportWeb.Session.display_reuser_space?(@conn) do %>
<%= link(gettext("Reuser space"),
to: reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "menu_dropdown")
) %>
<% end %>
<%= link(gettext("Reuser space"),
to: reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "menu_dropdown")
) %>
<a
class="navigation__link nagivation__link--logout"
href={session_path(@conn, :delete, redirect_path: current_path(@conn))}
Expand Down
14 changes: 6 additions & 8 deletions apps/transport/lib/transport_web/templates/page/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
<a href={page_path(@conn, :espace_producteur, utm_campaign: "home_button")} class="button">
<%= dgettext("page-index", "Producer space") %>
</a>
<%= if TransportWeb.Session.display_reuser_space?(@conn) do %>
<a
href={reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "home_button")}
class="button reuser-space"
>
<%= dgettext("page-index", "Reuser space") %>
</a>
<% end %>
<a
href={reuser_space_path(@conn, :espace_reutilisateur, utm_campaign: "home_button")}
class="button reuser-space"
>
<%= dgettext("page-index", "Reuser space") %>
</a>
</div>
<div class="home-search">
<div class="searchBar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ defmodule TransportWeb.ReuserSpaceControllerTest do
# Feedback form is displayed
refute content |> Floki.parse_document!() |> Floki.find("form.feedback-form") |> Enum.empty?()
end

test "reuser space disabled by killswitch", %{conn: conn} do
old_value = Application.fetch_env!(:transport, :disable_reuser_space)
Application.put_env(:transport, :disable_reuser_space, true)
conn = Plug.Test.init_test_session(conn, %{current_user: %{}})
refute TransportWeb.Session.display_reuser_space?(conn)
conn = conn |> get(@home_url)
assert redirected_to(conn, 302) == "/"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "La fonctionnalité n'est pas disponible pour le moment"
Application.put_env(:transport, :disable_reuser_space, old_value)
end
end

describe "datasets_edit" do
Expand Down
18 changes: 0 additions & 18 deletions apps/transport/test/transport_web/session_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ defmodule TransportWeb.SessionTest do
end
end

describe "display_reuser_space?" do
test "killswitch can disable the reuser space" do
old_value = Application.fetch_env!(:transport, :disable_reuser_space)
Application.put_env(:transport, :disable_reuser_space, true)
conn = Plug.Test.init_test_session(%Plug.Conn{}, %{})
refute TransportWeb.Session.display_reuser_space?(conn)
Application.put_env(:transport, :disable_reuser_space, old_value)
end

test "admins get access when killswitch is enabled" do
old_value = Application.fetch_env!(:transport, :disable_reuser_space)
Application.put_env(:transport, :disable_reuser_space, true)
conn = Plug.Test.init_test_session(%Plug.Conn{}, %{current_user: %{"is_admin" => true}})
assert TransportWeb.Session.display_reuser_space?(conn)
Application.put_env(:transport, :disable_reuser_space, old_value)
end
end

def pan_org do
%{"slug" => "equipe-transport-data-gouv-fr", "name" => "PAN", "id" => @pan_org_id}
end
Expand Down
1 change: 0 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ config :transport,
worker: worker,
webserver: webserver,
# kill switches: set specific variable environments to disable features
disable_reuser_space: System.get_env("DISABLE_REUSER_SPACE") in ["1", "true"],
disable_national_gtfs_map: System.get_env("DISABLE_NATIONAL_GTFS_MAP") in ["1", "true"]

config :unlock,
Expand Down

0 comments on commit 5f3612e

Please sign in to comment.