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

Allow using Loader with Permit.Ecto.Resolver #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olafbado
Copy link
Contributor

No description provided.

@olafbado olafbado linked an issue Feb 29, 2024 that may be closed by this pull request
@vincentvanbush
Copy link
Contributor

I think it could be good to add resolver tests for this.

lib/permit_ecto/resolver.ex Outdated Show resolved Hide resolved
:unauthorized

nil ->
raise Ecto.NoResultsError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a library that depends on Ecto, this is acceptable, but it's possible that it could have a different behaviour since we're not actually firing any query explicitly here. (Related to #1)

authorization_module,
resource_module,
action,
%{use_loader?: true} = meta,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be possible to not have to use an additional use_loader? option if permit_phoenix/controller.ex allows differentiating between nil and a function at plug level. (line 365)


with {_, true} <-
{:pre_auth, authorized?(subject, authorization_module, resource_module, action)},
resource <- meta[:loader].(params_for_loader),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If in permit_phoenix the loader/1 function is defined as such:

def loader(resolution_context) do
  case unquote(opts)[:loader] do
    nil -> nil
    loader -> {:loader, unquote(__MODULE__).loader(resolution_context, unquote(opts))}
  end
end

you could check here whether loader was not given at all, or it returned nil

@olafbado olafbado force-pushed the 2-allow-using-loader-with-permitectoresolver branch from d4876a4 to 0181070 Compare March 1, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using Loader with Permit.Ecto.Resolver
2 participants