I am building an admin tool app for our system.
I want to record every action made by every user.
Here's what I did
defmodule AdminToolWeb.UserController do
use AdminToolWeb, :controller
...
def delete(conn, %{"id" => id}) do
current_user = Guardian.Plug.current_resource(conn)
with %User{} <- user = Accounts.get_user(id) do
Accounts.delete_user(user)
conn
|> put_flash(:info, "#{user.id} deleted.")
|> Activities.log(current_user)
|> redirect(to: Routes.user_path(conn, :index))
end
end
...
end
The problem is I have to pipe |> Activity.log(current_user)
in every action of every controller I have in my app.
Is there a way to implement something like this?
Controller -> (ActivityLogPlugOfSorts) -> View
using a custom plug and call it like this?
defmodule AdminToolWeb.UserController do
use AdminToolWeb, :controller
import AdminToolWeb.Plugs.Activities
plug :log
...
but It should be called between controller and view.
Or should I put a function inside a View module instead?
I hope there is a better way.
question from:
https://stackoverflow.com/questions/65884754/phoenix-callback-action-between-controller-and-view 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…