Skip to content

Commit

Permalink
Authorizer callback api change and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuprog committed Dec 15, 2020
1 parent 84f7949 commit ebeed6a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/assoc_list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ defmodule QueryBuilder.AssocList do
end

{join_type, auth_z_join_filters} =
case authorizer && authorizer.reject_unauthorized_assoc(source_schema, assoc_field) do
case authorizer && authorizer.reject_unauthorized_assoc(source_schema, {assoc_field, assoc_schema}) do
%{join: join, on: on, or_on: or_on} ->
{cond do
join == :left || join_type == :left -> :left
Expand Down
4 changes: 1 addition & 3 deletions lib/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ defimpl Inspect, for: QueryBuilder.Query do
end

defimpl Ecto.Queryable, for: QueryBuilder.Query do
@authorizer Application.get_env(:query_builder, :authorizer)

def to_query(%{ecto_query: ecto_query} = query) do
source_schema = QueryBuilder.Utils.root_schema(ecto_query)

Expand All @@ -43,7 +41,7 @@ defimpl Ecto.Queryable, for: QueryBuilder.Query do
[]
end

opts = [{:authorizer, @authorizer} | opts]
opts = [{:authorizer, authorizer()} | opts]

QueryBuilder.AssocList.build(source_schema, accumulated_assocs, assocs, opts)
end)
Expand Down
2 changes: 1 addition & 1 deletion test/query_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule QueryBuilderTest do

query =
User
|> QueryBuilder.where(id: 102)
|> QueryBuilder.where(id: 103)
|> QueryBuilder.preload(:authored_articles)

assert Repo.one!(query).authored_articles == []
Expand Down
2 changes: 1 addition & 1 deletion test/support/authorizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule QueryBuilder.Authorizer do
query
end

def reject_unauthorized_assoc(User, :authored_articles) do
def reject_unauthorized_assoc(User, {:authored_articles, Article}) do
grantors_for_user =
Acl
|> QueryBuilder.where(grantee_id: @current_user_id)
Expand Down

0 comments on commit ebeed6a

Please sign in to comment.