Skip to content

Commit

Permalink
Remove deprecations and up requirements
Browse files Browse the repository at this point in the history
New minimum:

- Elixir 1.7
- Ecto 3.0
- Phoenix 1.4
  • Loading branch information
danschultzer committed Feb 4, 2020
1 parent 1b9d89a commit e8286ee
Show file tree
Hide file tree
Showing 37 changed files with 87 additions and 1,077 deletions.
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
340 changes: 42 additions & 298 deletions CHANGELOG.md

Large diffs are not rendered by default.

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 @@ -245,9 +245,6 @@ defmodule PowPersistentSession.Plug.Cookie do
|> Plug.create(user, config)
end
end
# TODO: Remove by 1.1.0
defp fetch_and_auth_user(conn, user_id, config),
do: fetch_and_auth_user(conn, {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 @@ -275,7 +272,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 @@ -284,22 +281,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 cookie_id(config) do
uuid = UUID.generate()

Expand All @@ -322,17 +303,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
4 changes: 0 additions & 4 deletions lib/extensions/reset_password/ecto/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ defmodule PowResetPassword.Ecto.Context do
|> Schema.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
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
35 changes: 1 addition & 34 deletions lib/pow/ecto/schema/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ defmodule Pow.Ecto.Schema.Changeset do
|> maybe_validate_password_hash()
end

# TODO: Remove `confirm_password` support by 1.1.0
@doc """
Validates the confirm password field.
Expand All @@ -96,39 +95,7 @@ defmodule Pow.Ecto.Schema.Changeset do
`nil`.
"""
@spec confirm_password_changeset(Ecto.Schema.t() | Changeset.t(), map(), Config.t()) :: Changeset.t()
def confirm_password_changeset(user_or_changeset, %{confirm_password: password_confirmation} = params, _config) do
params =
params
|> Map.delete(:confirm_password)
|> Map.put(:password_confirmation, password_confirmation)

do_confirm_password_changeset(user_or_changeset, params)
end
def confirm_password_changeset(user_or_changeset, %{"confirm_password" => password_confirmation} = params, _config) do
params =
params
|> Map.delete("confirm_password")
|> Map.put("password_confirmation", password_confirmation)

convert_confirm_password_param(user_or_changeset, params)
end
def confirm_password_changeset(user_or_changeset, params, _config),
do: do_confirm_password_changeset(user_or_changeset, params)

# TODO: Remove by 1.1.0
defp convert_confirm_password_param(user_or_changeset, params) do
IO.warn("warning: passing `confirm_password` value to `#{inspect unquote(__MODULE__)}.confirm_password_changeset/3` has been deprecated, please use `password_confirmation` instead")

changeset = do_confirm_password_changeset(user_or_changeset, params)
errors = Enum.map(changeset.errors, fn
{:password_confirmation, error} -> {:confirm_password, error}
error -> error
end)

%{changeset | errors: errors}
end

defp do_confirm_password_changeset(user_or_changeset, params) do
def confirm_password_changeset(user_or_changeset, params, _config) do
changeset = Changeset.cast(user_or_changeset, params, [:password])

changeset
Expand Down
52 changes: 6 additions & 46 deletions lib/pow/extension/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ defmodule Pow.Extension.Base do
@moduledoc """
Used to set up extensions to enable parts of extension for auto-discovery.
This exists to prevent unnecessary `Code.ensure_compiled?/1` calls, and will
let the extension define what modules it has.
## Usage
defmodule MyCustomExtension do
Expand Down Expand Up @@ -51,59 +48,22 @@ defmodule Pow.Extension.Base do

@doc """
Checks whether an extension has a certain module.
If a base extension module doesn't exist, or is configured improperly,
`Code.ensure_compiled?/1` will be used instead to see whether the module
exists for the extension.
"""
@spec has?(atom(), [any()]) :: boolean()
def has?(extension, module_list) do
try do
has_extension_module?(extension, module_list)
rescue
# TODO: Remove or refactor by 1.1.0
_e in UndefinedFunctionError ->
IO.warn("no #{inspect extension} base module to check for #{inspect module_list} support found, please use #{inspect __MODULE__} to implement it")

[extension]
|> Kernel.++(module_list)
|> Module.concat()
|> Code.ensure_compiled?()
end
end

defp has_extension_module?(extension, ["Ecto", "Schema"]), do: extension.ecto_schema?()
defp has_extension_module?(extension, ["Phoenix", "ControllerCallbacks"]), do: extension.phoenix_controller_callbacks?()
defp has_extension_module?(extension, ["Phoenix", "Messages"]), do: extension.phoenix_messages?()
defp has_extension_module?(extension, ["Phoenix", "Router"]), do: extension.phoenix_router?()
def has?(extension, ["Ecto", "Schema"]), do: extension.ecto_schema?()
def has?(extension, ["Phoenix", "ControllerCallbacks"]), do: extension.phoenix_controller_callbacks?()
def has?(extension, ["Phoenix", "Messages"]), do: extension.phoenix_messages?()
def has?(extension, ["Phoenix", "Router"]), do: extension.phoenix_router?()

@doc """
Checks whether an extension has a certain module that has a `__using__/1`
macro.
This calls `has?/2` first, If a base extension module doesn't exist, or is
configured improperly, `Kernel.macro_exported?/3` will be used instead to
check if the module has a `__using__/1` macro.
"""
@spec use?(atom(), [any()]) :: boolean()
def use?(extension, module_list) do
case has?(extension, module_list) do
true ->
try do
use_extension_module?(extension, module_list)
rescue
# TODO: Remove or refactor by 1.1.0
_e in UndefinedFunctionError ->
IO.warn("#{inspect extension} has been configured improperly")

[extension]
|> Kernel.++(module_list)
|> Module.concat()
|> Kernel.macro_exported?(:__using__, 1)
end

false ->
false
true -> use_extension_module?(extension, module_list)
false -> false
end
end

Expand Down
Loading

0 comments on commit e8286ee

Please sign in to comment.