Skip to content

Commit

Permalink
Put new sites list logic behind a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zoldar committed Oct 30, 2024
1 parent c263d7f commit 7ee5b34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/plausible/sites.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,21 @@ defmodule Plausible.Sites do
)
end

defdelegate list(user, pagination_params, opts \\ []), to: Plausible.Teams.Sites
def list(user, pagination_params, opts \\ []) do
if Plausible.Teams.read_team_schemas?(user) do
Plausible.Teams.Sites.list(user, pagination_params, opts)
else
old_list(user, pagination_params, opts)
end
end

defdelegate list_with_invitations(user, pagination_params, opts \\ []),
to: Plausible.Teams.Sites
def list_with_invitations(user, pagination_params, opts \\ []) do
if Plausible.Teams.read_team_schemas?(user) do
Plausible.Teams.Sites.list_with_invitations(user, pagination_params, opts)
else
old_list_with_invitations(user, pagination_params, opts)
end
end

@spec old_list(Auth.User.t(), map(), [list_opt()]) :: Scrivener.Page.t()
def old_list(user, pagination_params, opts \\ []) do
Expand Down
4 changes: 4 additions & 0 deletions lib/plausible/teams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ defmodule Plausible.Teams do
alias __MODULE__
alias Plausible.Repo

def read_team_schemas?(user) do
FunWithFlags.enabled?(:read_team_schemas, for: user)
end

def with_subscription(team) do
Repo.preload(team, subscription: last_subscription_query())
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ else
FunWithFlags.disable(:experimental_reduced_joins)
end

FunWithFlags.enable(:read_team_schemas)

Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, :manual)

# warn about minio if it's included in tests but not running
Expand Down

0 comments on commit 7ee5b34

Please sign in to comment.