Update the Oban Dashboard to show only for admin users.

dev
KKlochko 2 months ago
parent 14b0b78e15
commit f4c2207a80

@ -0,0 +1,21 @@
defmodule DecentralisedBookIndexWeb.Plugs.RequireAdmin do
import Plug.Conn
import Phoenix.Controller
alias DecentralisedBookIndex.Accounts.Role
def init(default), do: default
def call(conn, _opts) do
current_user = conn.assigns[:current_user]
if current_user && Role.can_administrate?(current_user.role) do
conn
else
conn
|> put_flash(:error, "Unauthorized")
|> redirect(to: "/")
|> halt()
end
end
end

@ -23,6 +23,10 @@ defmodule DecentralisedBookIndexWeb.Router do
plug :set_actor, :user
end
pipeline :admin_authenticated_routes do
plug DecentralisedBookIndexWeb.Plugs.RequireAdmin
end
scope "/api/v1/json" do
pipe_through [:api]
@ -90,6 +94,12 @@ defmodule DecentralisedBookIndexWeb.Router do
end
end
scope "/" do
pipe_through [:browser, :admin_authenticated_routes]
oban_dashboard("/oban")
end
scope "/", DecentralisedBookIndexWeb do
pipe_through :browser
@ -135,11 +145,5 @@ defmodule DecentralisedBookIndexWeb.Router do
live_dashboard "/dashboard", metrics: DecentralisedBookIndexWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
scope "/" do
pipe_through :browser
oban_dashboard("/oban")
end
end
end

Loading…
Cancel
Save