curiosum-dev / permit

An uniform authorization library for Elixir. Supports Plug and Phoenix LiveView, aims for much more.
109 stars 0 forks source link

Preloading accessible records in non-singular resource actions (e.g. :index) - LiveView #5

Closed vincentvanbush closed 1 year ago

vincentvanbush commented 2 years ago

LiveViews should be able to use stuff developed as part of https://github.com/curiosum-dev/permit/issues/2 (querying accessible records for a subject) to get and execute Ecto queries preloading accessible records in :index and similar live_actions.

Example usage:

defmodule Permit.FakeApp.SomeLiveView do
  use Phoenix.LiveView, namespace: Permit

  use Permit.LiveViewAuthorization,
    authorization_module: Authorization,
    resource_module: Item

  @impl true
  def mount(_params, _session, %{assigns: %{live_action: :index}} = socket) do
    # socket.assigns.loaded_resources is present
    {:ok, socket}
  end

  def handle_params(_params, _url, %{assigns: %{live_action: :index}} = socket) do
    # socket.assigns.loaded_resources is present
   {:noreply, socket}
  end
end
vincentvanbush commented 1 year ago

Closed via #21 .