Skip to content

Commit

Permalink
Fix Ecto deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Aug 5, 2023
1 parent 239d9ab commit 91a62bf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions lib/ex_oauth2_provider/access_grants/access_grant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_oauth2_provider/access_tokens/access_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions lib/ex_oauth2_provider/applications/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 10 additions & 7 deletions lib/ex_oauth2_provider/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
25 changes: 19 additions & 6 deletions lib/mix/ex_oauth2_provider/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, %{}}
Expand Down

0 comments on commit 91a62bf

Please sign in to comment.