Skip to content
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

New requirements in Pow 1.1.0 #121

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ services:
jobs:
include:
- stage: test
elixir: 1.6
elixir: 1.7
otp_release: 20.0
script: &test_scripts
- mix test
- MIX_ENV=test mix credo --ignore design.tagtodo
- MIX_ENV=test mix credo
- stage: test
elixir: 1.8
script: *test_scripts
Expand Down
397 changes: 50 additions & 347 deletions CHANGELOG.md

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions lib/extensions/email_confirmation/ecto/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ defmodule PowEmailConfirmation.Ecto.Context do
|> user_mod.confirm_email_changeset(params)
|> Context.do_update(config)
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use confirm_email/3 instead"
def confirm_email(user, config), do: confirm_email(user, %{}, config)
end
5 changes: 0 additions & 5 deletions lib/extensions/email_confirmation/ecto/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,4 @@ defmodule PowEmailConfirmation.Ecto.Schema do
|> Changeset.change(changes)
|> Changeset.unique_constraint(:email)
end

# TODO: Remove by 1.1.0
@deprecated "Use `confirm_email_changeset/2` instead"
@doc false
def confirm_email_changeset(changeset), do: confirm_email_changeset(changeset, %{})
end
21 changes: 0 additions & 21 deletions lib/extensions/email_confirmation/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ defmodule PowEmailConfirmation.Plug do
{:ok, user} -> {:ok, user, maybe_renew_conn(conn, user, config)}
end
end
# TODO: Remove by 1.1.0
def confirm_email(conn, token) when is_binary(token) do
IO.warn "#{unquote(__MODULE__)}.confirm_email/2 called with token is deprecated, use `load_user_by_token/2` and `confirm_email/2` with map as second argument instead"

config = Plug.fetch_config(conn)

token
|> Context.get_by_confirmation_token(config)
|> maybe_confirm_email(conn, config)
end

defp confirm_email_user(conn) do
conn.assigns[:confirm_email_user]
Expand All @@ -110,15 +100,4 @@ defmodule PowEmailConfirmation.Plug do

Keyword.equal?(clauses1, clauses2)
end

# TODO: Remove by 1.1.0
defp maybe_confirm_email(nil, conn, _config), do: {:error, nil, conn}
defp maybe_confirm_email(user, conn, config) do
user
|> Context.confirm_email(%{}, config)
|> case do
{:error, changeset} -> {:error, changeset, conn}
{:ok, user} -> {:ok, user, maybe_renew_conn(conn, user, config)}
end
end
end
16 changes: 0 additions & 16 deletions lib/extensions/invitation/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,4 @@ defmodule PowInvitation.Plug do
_any -> {:error, conn}
end
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use `load_invited_user_by_token/2` instead"
def invited_user_from_token(conn, token) do
config = Plug.fetch_config(conn)

InvitationContext.get_by_invitation_token(token, config)
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "No longer used"
def assign_invited_user(conn, user) do
Conn.assign(conn, :invited_user, user)
end
end
36 changes: 4 additions & 32 deletions lib/extensions/persistent_session/plug/cookie.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ defmodule PowPersistentSession.Plug.Cookie do
user -> {token, {user, metadata}}
end
end
# TODO: Remove by 1.1.0
defp fetch_user({token, user_id}, config),
do: fetch_user({token, {user_id, []}}, config)

defp filter_invalid!([id: _value] = clauses), do: clauses
defp filter_invalid!(clauses), do: raise "Invalid get_by clauses stored: #{inspect clauses}"
Expand Down Expand Up @@ -287,7 +284,7 @@ defmodule PowPersistentSession.Plug.Cookie do
defp update_session_metadata(conn, metadata) do
case Keyword.get(metadata, :session_metadata) do
nil ->
fallback_session_fingerprint(conn, metadata)
conn

session_metadata ->
metadata = Map.get(conn.private, :pow_session_metadata, [])
Expand All @@ -296,22 +293,6 @@ defmodule PowPersistentSession.Plug.Cookie do
end
end

# TODO: Remove by 1.1.0
defp fallback_session_fingerprint(conn, metadata) do
case Keyword.get(metadata, :session_fingerprint) do
nil ->
conn

fingerprint ->
metadata =
conn.private
|> Map.get(:pow_session_metadata, [])
|> Keyword.put(:fingerprint, fingerprint)

Conn.put_private(conn, :pow_session_metadata, metadata)
end
end

defp gen_token(config) do
uuid = UUID.generate()

Expand Down Expand Up @@ -361,17 +342,8 @@ defmodule PowPersistentSession.Plug.Cookie do
end

defp max_age(config) do
# TODO: Remove by 1.1.0
case Config.get(config, :persistent_session_cookie_max_age) do
nil ->
config
|> PowPersistentSession.Plug.Base.ttl()
|> Integer.floor_div(1000)

max_age ->
IO.warn("use of `:persistent_session_cookie_max_age` config value in #{inspect unquote(__MODULE__)} is deprecated, please use `:persistent_session_ttl`")

max_age
end
config
|> PowPersistentSession.Plug.Base.ttl()
|> Integer.floor_div(1000)
end
end
5 changes: 0 additions & 5 deletions lib/extensions/reset_password/ecto/context.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule PowResetPassword.Ecto.Context do
@moduledoc false
alias Pow.{Config, Ecto.Context, Operations}
alias PowResetPassword.Ecto.Schema

@spec get_by_email(binary(), Config.t()) :: Context.user() | nil
def get_by_email(email, config), do: Operations.get_by([email: email], config)
Expand All @@ -12,8 +11,4 @@ defmodule PowResetPassword.Ecto.Context do
|> user_mod.reset_password_changeset(params)
|> Context.do_update(config)
end

# TODO: Remove by 1.1.0
@deprecated "Use `PowResetPassword.Ecto.Schema.reset_password_changeset/2` instead"
def password_changeset(user, params), do: Schema.reset_password_changeset(user, params)
end
24 changes: 0 additions & 24 deletions lib/extensions/reset_password/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ defmodule PowResetPassword.Plug do
|> struct()
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "No longer used"
def assign_reset_password_user(conn, user) do
Conn.assign(conn, :reset_password_user, user)
end

@doc """
Finds a user for the provided params, creates a token, and stores the user
for the token.
Expand Down Expand Up @@ -104,23 +97,6 @@ defmodule PowResetPassword.Plug do
end
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use `load_user_by_token/2` instead"
def user_from_token(conn, token) do
{store, store_config} =
conn
|> Plug.fetch_config()
|> store()

store_config
|> store.get(token)
|> case do
:not_found -> nil
user -> user
end
end

@doc """
Updates the password for the user fetched in the connection.

Expand Down
50 changes: 1 addition & 49 deletions lib/mix/pow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ defmodule Mix.Pow do
:ok
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use `ensure_ecto!` or `ensure_phoenix!` instead"
@spec ensure_dep!(binary(), atom(), OptionParser.argv()) :: :ok | no_return
def ensure_dep!(task, dep, _args) do
fetch_deps()
|> top_level_dep_in_deps?(dep)
|> case do
true ->
:ok

false ->
Mix.raise("mix #{task} can only be run inside an application directory that has #{inspect dep} as dependency")
end
end

@doc """
Raises an exception if application doesn't have Ecto as dependency.
"""
Expand All @@ -53,15 +37,7 @@ defmodule Mix.Pow do
end)
end

# TODO: Remove by 1.1.0 and only support Elixir 1.7
defp fetch_deps do
System.version()
|> Version.match?("~> 1.6.0")
|> case do
true -> apply(Dep, :loaded, [[]])
false -> apply(Dep, :load_on_environment, [[]])
end
end
defp fetch_deps, do: Dep.load_on_environment([])

@doc """
Raises an exception if application doesn't have Phoenix as dependency.
Expand Down Expand Up @@ -147,36 +123,12 @@ defmodule Mix.Pow do
""")
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Please use `Pow.Phoenix.parse_structure/1` instead"
@spec context_app :: atom() | no_return
def context_app do
this_app = otp_app()

this_app
|> Application.get_env(:generators, [])
|> Keyword.get(:context_app)
|> case do
nil -> this_app
false -> Mix.raise("No context_app configured for current application")
{app, _path} -> app
app -> app
end
end

@doc false
@spec otp_app :: atom() | no_return
def otp_app do
Keyword.fetch!(Mix.Project.config(), :app)
end

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use `app_base/1` instead"
@spec context_base(atom()) :: atom()
def context_base(app), do: app_base(app)

@doc """
Fetches the context base module for the app.
"""
Expand Down
19 changes: 2 additions & 17 deletions lib/mix/pow/ecto/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ defmodule Mix.Pow.Ecto.Migration do
@moduledoc """
Utilities module for ecto migrations in mix tasks.
"""
alias Mix.Generator

# TODO: Remove by 1.1.0
@doc false
@deprecated "Use `create_migration_file/3`"
defdelegate create_migration_files(repo, name, content), to: __MODULE__, as: :create_migration_file
alias Mix.{EctoSQL, Generator}

@doc """
Creates a migration file for a repo.
Expand All @@ -17,7 +12,7 @@ defmodule Mix.Pow.Ecto.Migration do
base_name = "#{Macro.underscore(name)}.exs"
path =
repo
|> source_repo_priv()
|> EctoSQL.source_repo_priv()
|> Path.join("migrations")
|> maybe_create_directory()
timestamp = timestamp(path)
Expand Down Expand Up @@ -68,14 +63,4 @@ defmodule Mix.Pow.Ecto.Migration do

defp pad(i) when i < 10, do: <<?0, ?0 + i>>
defp pad(i), do: to_string(i)

# TODO: Remove by 1.1.0 and only use Ecto 3.0
defp source_repo_priv(repo) do
mod =
if Pow.dependency_vsn_match?(:ecto, "< 3.0.0"),
do: Mix.Ecto,
else: Mix.EctoSQL

mod.source_repo_priv(repo)
end
end
16 changes: 0 additions & 16 deletions lib/pow.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
defmodule Pow do
@moduledoc false

@doc """
Checks for version requirement in dependencies.
"""
@spec dependency_vsn_match?(atom(), binary()) :: boolean()
def dependency_vsn_match?(dep, req) do
case :application.get_key(dep, :vsn) do
{:ok, actual} ->
actual
|> List.to_string()
|> Version.match?(req)

_any ->
false
end
end
end
8 changes: 0 additions & 8 deletions lib/pow/ecto/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,9 @@ defmodule Pow.Ecto.Context do
end
end

# TODO: Remove by 1.1.0
@deprecated "Use `Pow.Config.repo!/1` instead"
defdelegate repo(config), to: Config, as: :repo!

defp repo_opts(config, opts) do
config
|> Config.get(:repo_opts, [])
|> Keyword.take(opts)
end

# TODO: Remove by 1.1.0
@deprecated "Use `Pow.Config.user!/1` instead"
defdelegate user_schema_mod(config), to: Config, as: :user!
end
4 changes: 0 additions & 4 deletions lib/pow/ecto/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ defmodule Pow.Ecto.Schema do
Enum.filter(fields, &not Enum.member?(existing_fields, {elem(&1, 0), elem(&1, 1)}))
end

# TODO: Remove by 1.1.0
@deprecated "No longer public method"
def filter_new_fields(fields, existing_fields), do: __filter_new_fields__(fields, existing_fields)

@doc false
defmacro __register_fields__ do
quote do
Expand Down
Loading