-
Notifications
You must be signed in to change notification settings - Fork 16
Add feature flag for Smartling integration work #3231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thecristen
merged 7 commits into
main
from
lb/add-feature-flag-for-smartling-integration-work
Jun 16, 2026
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1b3bdff
WIP set up flag for Smartling integration work
c760ad5
WIP incorporating Laboratory flags
d29e98c
Update package
1e6e4f7
Add flag logic back to router
b6f21c5
Move Laboratory config block to shared env config file
a667382
WIP
992aa47
Update Laboratory package
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| defmodule DotcomWeb.Plugs.PutFlagsInAssignsHook do | ||
| @moduledoc """ | ||
| Grabs Laboratory flags from session and makes them available as assigns | ||
| """ | ||
|
|
||
| import Phoenix.Component | ||
|
|
||
| def on_mount(:default, _params, session, socket) do | ||
| flags = Application.get_env(:laboratory, :features) |> Enum.map(fn {key, _, _} -> key end) | ||
|
|
||
| socket = | ||
| Enum.reduce(flags, socket, fn flag, socket -> | ||
| value = | ||
| case session_value = session[Atom.to_string(flag)] do | ||
| nil -> nil | ||
| _ -> session_value | ||
| end | ||
|
|
||
| socket |> assign(flag, value) | ||
| end) | ||
|
|
||
| {:cont, socket} | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| defmodule DotcomWeb.Plugs.PutFlagsInSession do | ||
| @moduledoc """ | ||
| Reads in Laboratory flags and makes them available on live view sessions. | ||
| Necessary because cookies are hard to access from LiveView. | ||
| """ | ||
| import Plug.Conn | ||
|
|
||
| def init(_) do | ||
| %{} | ||
| end | ||
|
|
||
| def call(conn, _opts) do | ||
| conn = fetch_cookies(conn) | ||
| flags = Application.get_env(:laboratory, :features) |> Enum.map(fn {key, _, _} -> key end) | ||
|
|
||
| Enum.reduce(flags, conn, fn flag, conn -> | ||
| value = | ||
| case conn.cookies[Atom.to_string(flag)] do | ||
| nil -> false | ||
| "true" -> true | ||
| end | ||
|
|
||
| conn | ||
| # Makes it available in LiveView | ||
| |> put_session(flag, value) | ||
| # Makes it available in traditional controllers | ||
| |> assign(flag, value) | ||
| end) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| defmodule DotcomWeb.Plugs.PutFlagsInSessionTest do | ||
| use DotcomWeb.ConnCase, async: true | ||
|
|
||
| import DotcomWeb.Plugs.PutFlagsInSession | ||
|
|
||
| describe "Put Flags in Session Plug" do | ||
| test "flag is false if it has not been set", %{conn: conn} do | ||
| conn = | ||
| conn | ||
| |> Plug.Test.init_test_session(%{}) | ||
| |> fetch_session() | ||
| |> bypass_through(DotcomWeb.Router, :get_flags) | ||
| |> get("/") | ||
|
|
||
| assert conn.assigns.test_flag == false | ||
| assert conn.private.plug_session["test_flag"] == false | ||
| end | ||
|
|
||
| test "flag is true if it has been set", %{conn: conn} do | ||
| conn = | ||
| conn | ||
| |> put_resp_cookie("test_flag", "true") | ||
| |> Plug.Test.init_test_session(%{}) | ||
| |> fetch_session() | ||
| |> bypass_through(DotcomWeb.Router, :get_flags) | ||
| |> get("/") | ||
|
|
||
| assert conn.assigns.test_flag == true | ||
| assert conn.private.plug_session["test_flag"] == true | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.