ex_admin
ex_admin copied to clipboard
Any ideas about CRUD actions journal?
I need to journal of crud actions in admin panel. I could use after_filter method, but it isn't provided after unsuccessful create and update. Is there any way to hook after action events without modifying ex_admin source?
I suppose you could create your own resource controller with the same actions at ExAdmin.AdminResourceController and setup your router to call it. From your controller, you could all the actions on ExAdmin.AdminResourceContrller and take action before returning the conn.
Actually, you might only need to route the create and update actions to your own controller...
I would also be open to a RP that provides a hood in handle_changeset_error. Between the after filter and this new hook, you should have what you need.
There might be a third option, but I've never tried it. You might be able to create a plug that you place in your endpoint, after the call to the router plug. However, I believe that plugs stop being called once the conn is hauled, so this might now work. It would be quick to test.
@smpallen99 I suppose provides a hood means provides a hook :)
The second case
Maybe we can update ExAdmin.AdminResourceContrller with new hook this way
case ExAdmin.Repo.insert(changeset) do
{:error, changeset} ->
conn
# new hook handle_after_error_filter, maybe pattern matched handle_after_filter be better?
|> handle_after_error_filter(:create, defn, params, changeset, resource)
|> handle_changeset_error(defn, changeset, params)
resource ->
{conn, _, resource} = handle_after_filter(conn, :create, defn, params, resource)
put_flash(conn, :notice, (gettext "%{model_name} was successfully created.", model_name: (model |> base_name |> titleize) ))
|> redirect(to: admin_resource_path(resource, :show))
end
The third case works for plug in Endpoint
plug App.Router
plug App.Journal
and
defmodule App.Journal do
@moduledoc false
import Plug.Conn
def init(_) do
end
def call(conn, _opts \\ %{}) do
IO.inspect conn.assigns[:changeset]
IO.inspect conn.assigns[:resource]
IO.inspect conn.params
conn
end
end