Non-admin users can now submit beacons but they are held in an unapproved state until an admin approves them. Only approved beacons appear in the public list; pending submissions are shown in a separate admin-only section on /beacons with Approve and Delete actions. The show page surfaces a pending badge and an admin-only Approve button when viewing an unapproved beacon. Also formats EIRP (mW) on the index page without scientific notation.
127 lines
3.8 KiB
Elixir
127 lines
3.8 KiB
Elixir
defmodule MicrowavepropWeb.Router do
|
|
use MicrowavepropWeb, :router
|
|
|
|
import MicrowavepropWeb.UserAuth
|
|
import Phoenix.LiveDashboard.Router
|
|
|
|
pipeline :browser do
|
|
plug :accepts, ["html"]
|
|
plug :fetch_session
|
|
plug :store_remote_ip
|
|
plug :fetch_live_flash
|
|
plug :put_root_layout, html: {MicrowavepropWeb.Layouts, :root}
|
|
plug :protect_from_forgery
|
|
plug :put_secure_browser_headers
|
|
plug :fetch_current_scope_for_user
|
|
end
|
|
|
|
defp store_remote_ip(conn, _opts) do
|
|
ip_str = conn.remote_ip |> :inet.ntoa() |> to_string()
|
|
Plug.Conn.put_session(conn, :remote_ip, ip_str)
|
|
end
|
|
|
|
pipeline :api do
|
|
plug :accepts, ["json"]
|
|
end
|
|
|
|
# Health check — no pipeline, minimal overhead
|
|
get "/health", MicrowavepropWeb.HealthController, :check, log: false
|
|
|
|
# Authenticated (non-admin) and admin-only routes must come first so that
|
|
# literal segments like `/beacons/new` are registered before the public
|
|
# `/beacons/:id`.
|
|
scope "/", MicrowavepropWeb do
|
|
pipe_through [:browser, :require_authenticated_user]
|
|
|
|
live_session :authenticated, on_mount: [{MicrowavepropWeb.UserAuth, :default}] do
|
|
live "/beacons/new", BeaconLive.Form, :new
|
|
end
|
|
|
|
live_session :admin, on_mount: [{MicrowavepropWeb.UserAuth, :require_admin}] do
|
|
live "/beacons/:id/edit", BeaconLive.Form, :edit
|
|
|
|
live "/users", UserManagementLive.Index, :index
|
|
live "/users/:id/edit", UserManagementLive.Edit, :edit
|
|
end
|
|
end
|
|
|
|
scope "/", MicrowavepropWeb do
|
|
pipe_through :browser
|
|
|
|
get "/", PageController, :home
|
|
|
|
live_session :public, on_mount: [{MicrowavepropWeb.UserAuth, :default}] do
|
|
live "/submit", SubmitLive
|
|
live "/map", MapLive
|
|
live "/weather", WeatherMapLive
|
|
live "/contacts", ContactLive.Index
|
|
live "/contacts/map", ContactMapLive
|
|
live "/contacts/:id", ContactLive.Show
|
|
live "/path", PathLive
|
|
live "/rover", RoverLive
|
|
live "/algo", AlgoLive
|
|
live "/about", AboutLive
|
|
live "/backfill", BackfillLive
|
|
|
|
# Beacons: read-only public views
|
|
live "/beacons", BeaconLive.Index, :index
|
|
live "/beacons/:id", BeaconLive.Show, :show
|
|
end
|
|
|
|
# Redirect old /qsos routes
|
|
get "/qsos", PageController, :redirect_contacts
|
|
get "/qsos/:id", PageController, :redirect_contact
|
|
end
|
|
|
|
# Other scopes may use custom stacks.
|
|
# scope "/api", MicrowavepropWeb do
|
|
# pipe_through :api
|
|
# end
|
|
|
|
scope "/" do
|
|
pipe_through :browser
|
|
|
|
live_dashboard "/dashboard",
|
|
metrics: MicrowavepropWeb.Telemetry,
|
|
ecto_repos: [Microwaveprop.Repo],
|
|
ecto_psql_extras_options: [long_running_queries: [threshold: "200 milliseconds"]]
|
|
end
|
|
|
|
# Enable Swoosh mailbox preview in development
|
|
if Application.compile_env(:microwaveprop, :dev_routes) do
|
|
scope "/dev" do
|
|
pipe_through :browser
|
|
|
|
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
|
end
|
|
end
|
|
|
|
## Authentication routes
|
|
|
|
scope "/", MicrowavepropWeb do
|
|
pipe_through [:browser, :redirect_if_user_is_authenticated]
|
|
|
|
get "/users/register", UserRegistrationController, :new
|
|
post "/users/register", UserRegistrationController, :create
|
|
end
|
|
|
|
scope "/", MicrowavepropWeb do
|
|
pipe_through [:browser, :require_authenticated_user]
|
|
|
|
get "/users/settings", UserSettingsController, :edit
|
|
put "/users/settings", UserSettingsController, :update
|
|
get "/users/settings/confirm-email/:token", UserSettingsController, :confirm_email
|
|
|
|
post "/users/beacon-monitors", BeaconMonitorController, :create
|
|
delete "/users/beacon-monitors/:id", BeaconMonitorController, :delete
|
|
end
|
|
|
|
scope "/", MicrowavepropWeb do
|
|
pipe_through [:browser]
|
|
|
|
get "/users/log-in", UserSessionController, :new
|
|
get "/users/confirm/:token", UserSessionController, :confirm
|
|
post "/users/log-in", UserSessionController, :create
|
|
delete "/users/log-out", UserSessionController, :delete
|
|
end
|
|
end
|