diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f7e82b..0c06009c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Requires Elixir 1.11+. * Permit native application redirect uri +* Separate Ecto migration and field options to resolve ecto 3.8 deprecation ## v0.5.6 (2020-01-07) diff --git a/lib/ex_oauth2_provider/access_grants/access_grant.ex b/lib/ex_oauth2_provider/access_grants/access_grant.ex index 6f26d59c..d3071bbf 100644 --- a/lib/ex_oauth2_provider/access_grants/access_grant.ex +++ b/lib/ex_oauth2_provider/access_grants/access_grant.ex @@ -23,9 +23,9 @@ defmodule ExOauth2Provider.AccessGrants.AccessGrant do @doc false def attrs() do [ - {:token, :string, null: false}, - {:expires_in, :integer, null: false}, - {:redirect_uri, :string, null: false}, + {:token, :string, [], null: false}, + {:expires_in, :integer, [], null: false}, + {:redirect_uri, :string, [], null: false}, {:revoked_at, :utc_datetime}, {:scopes, :string} ] diff --git a/lib/ex_oauth2_provider/access_tokens/access_token.ex b/lib/ex_oauth2_provider/access_tokens/access_token.ex index 49242a3e..e44a49d1 100644 --- a/lib/ex_oauth2_provider/access_tokens/access_token.ex +++ b/lib/ex_oauth2_provider/access_tokens/access_token.ex @@ -24,12 +24,12 @@ defmodule ExOauth2Provider.AccessTokens.AccessToken do @doc false def attrs() do [ - {:token, :string, null: false}, + {:token, :string, [], null: false}, {:refresh_token, :string}, {:expires_in, :integer}, {:revoked_at, :utc_datetime}, {:scopes, :string}, - {:previous_refresh_token, :string, null: false, default: ""} + {:previous_refresh_token, :string, [default: ""], null: false} ] end diff --git a/lib/ex_oauth2_provider/applications/application.ex b/lib/ex_oauth2_provider/applications/application.ex index 4f342201..217d7236 100644 --- a/lib/ex_oauth2_provider/applications/application.ex +++ b/lib/ex_oauth2_provider/applications/application.ex @@ -42,11 +42,11 @@ defmodule ExOauth2Provider.Applications.Application do @doc false def attrs() do [ - {:name, :string, null: false}, - {:uid, :string, null: false}, - {:secret, :string, null: false, default: ""}, - {:redirect_uri, :string, null: false}, - {:scopes, :string, null: false, default: ""}, + {:name, :string, [], null: false}, + {:uid, :string, [], null: false}, + {:secret, :string, [default: ""], null: false}, + {:redirect_uri, :string, [], null: false}, + {:scopes, :string, [default: ""], null: false}, ] end diff --git a/lib/ex_oauth2_provider/schema.ex b/lib/ex_oauth2_provider/schema.ex index ad9419d1..20c30593 100644 --- a/lib/ex_oauth2_provider/schema.ex +++ b/lib/ex_oauth2_provider/schema.ex @@ -18,9 +18,12 @@ defmodule ExOauth2Provider.Schema do {name, type} -> field(name, type) - {name, type, defaults} -> - field(name, type, defaults) - end) + {name, type, field_options} -> + field(name, type, field_options) + + {name, type, field_options, _migration_options} -> + field(name, type, field_options) + end) unquote(module).assocs() |> unquote(__MODULE__).__assocs_with_queryable__(@config) @@ -29,14 +32,14 @@ defmodule ExOauth2Provider.Schema do {:belongs_to, name, queryable} -> belongs_to(name, queryable) - {:belongs_to, name, queryable, defaults} -> - belongs_to(name, queryable, defaults) + {:belongs_to, name, queryable, options} -> + belongs_to(name, queryable, options) {:has_many, name, queryable} -> has_many(name, queryable) - {:has_many, name, queryable, defaults} -> - has_many(name, queryable, defaults) + {:has_many, name, queryable, options} -> + has_many(name, queryable, options) end) end end diff --git a/lib/mix/ex_oauth2_provider/migration.ex b/lib/mix/ex_oauth2_provider/migration.ex index 76e876c3..7c106c3e 100644 --- a/lib/mix/ex_oauth2_provider/migration.ex +++ b/lib/mix/ex_oauth2_provider/migration.ex @@ -98,10 +98,11 @@ defmodule Mix.ExOauth2Provider.Migration do end defp schema(module, table, namespace, %{binary_id: binary_id}) do - attrs = + attrs = module.attrs() |> Kernel.++(attrs_from_assocs(module.assocs(), namespace)) |> migration_attrs() + defaults = defaults(attrs) {assocs, attrs} = partition_attrs(attrs) table = "#{namespace}_#{table}" @@ -139,13 +140,25 @@ defmodule Mix.ExOauth2Provider.Migration do defp to_migration_attr({name, type}) do {name, type, ""} end - defp to_migration_attr({name, type, []}) do - to_migration_attr({name, type}) + defp to_migration_attr({name, type, field_options}) do + to_migration_attr({name, type, field_options, []}) end - defp to_migration_attr({name, type, defaults}) do - defaults = Enum.map_join(defaults, ", ", fn {k, v} -> "#{k}: #{inspect v}" end) + defp to_migration_attr({name, type, field_options, migration_options}) do + field_options + |> Keyword.get(:default) + |> case do + nil -> migration_options ++ [] + default -> migration_options ++ [default: default] + end + |> case do + [] -> + to_migration_attr({name, type}) + + options -> + options = Enum.map_join(options, ", ", fn {k, v} -> "#{k}: #{inspect v}" end) - {name, type, ", #{defaults}"} + {name, type, ", #{options}"} + end end defp defaults(attrs) do diff --git a/test/ex_oauth2_provider/oauth2/token/strategy/revoke_test.exs b/test/ex_oauth2_provider/oauth2/token/strategy/revoke_test.exs index dc8ad79b..a51ff8da 100644 --- a/test/ex_oauth2_provider/oauth2/token/strategy/revoke_test.exs +++ b/test/ex_oauth2_provider/oauth2/token/strategy/revoke_test.exs @@ -49,7 +49,7 @@ defmodule ExOauth2Provider.Token.Strategy.RevokeTest do end test "#revoke/2 when access token owned by another client", %{valid_request: valid_request, access_token: access_token} do - new_application = Fixtures.application(uid: "new_app", client_secret: "new") + new_application = Fixtures.application(uid: "new_app", secret: "new") QueryHelpers.change!(access_token, application_id: new_application.id) assert Token.revoke(valid_request, otp_app: :ex_oauth2_provider) == {:ok, %{}}