-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch sites creation to read teams schemas (#4823)
* Expose site limit, usage, ensure_can_add_new_site via Adapter * Print to stdout if TEST_READ_TEAM_SCHEMAS is enabled * Add factory wrappers for remaining subscription types * Ensure consistent ordering when fetching latest subscription * Switch creating new site to read team schemas * Dedup code based on read team schemas switching * Switch to transitional factory where necessary * Update yet another test requiring transitional factory
- Loading branch information
Showing
13 changed files
with
174 additions
and
105 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
defmodule Plausible.Teams.Adapter do | ||
@moduledoc """ | ||
Commonly used teams-transition functions | ||
""" | ||
alias Plausible.Teams | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
alias Plausible.Teams | ||
import Teams.Adapter | ||
end | ||
end | ||
|
||
def team_or_user(user) do | ||
switch( | ||
user, | ||
team_fn: &Function.identity/1, | ||
user_fn: &Function.identity/1 | ||
) | ||
end | ||
|
||
def switch(user, opts \\ []) do | ||
team_fn = Keyword.fetch!(opts, :team_fn) | ||
user_fn = Keyword.fetch!(opts, :user_fn) | ||
|
||
if Teams.read_team_schemas?(user) do | ||
team = | ||
case Teams.get_by_owner(user) do | ||
{:ok, team} -> team | ||
{:error, _} -> nil | ||
end | ||
|
||
team_fn.(team) | ||
else | ||
user_fn.(user) | ||
end | ||
end | ||
end |
This file contains 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 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 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 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 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
Oops, something went wrong.