ash_policy_authorizer v0.1.4 AshPolicyAuthorizer.Authorizer.Policy.Checks.AuthorizeIf View Source

Link to this section Summary

Functions

If the check is true, the request is authorized, otherwise run remaining checks.

Link to this section Functions

Link to this macro

authorize_if(check, opts \\ [])

View Source (macro)

If the check is true, the request is authorized, otherwise run remaining checks.

Examples

authorize_if logged_in()
authorize_if actor_attribute_matches_record(:group, :group)

Arguments

  • :check - A check is a tuple of {module, keyword}.

The module must implement the AshPolicyAuthorizer.Check behaviour. Generally, you won't be passing {module, opts}, but will use one of the provided functions that return that, like always() or user_attribute_matches_record(:foo, :bar). To make custom ones define a module that implements the AshPolicyAuthorizer.Check behaviour, put a convenience function in that module that returns {module, opts}, and import that into your resource.

defmodule MyResource do
  use Ash.Resource, authorizers: [AshPolicyAuthorizer.Authorizer]

  import MyCustomCheck

  policies do
    ...
    policy do
      authorize_if my_custom_check(:foo)
    end
  end
end

Options

  • :name - false A short name or description for the check, used when explaining authorization results