Skip to content

Commit 4cbb243

Browse files
committed
add oban live dashboard and configure it for admins only
1 parent e09215e commit 4cbb243

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

lib/algora_web/router.ex

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule AlgoraWeb.Router do
33

44
import AlgoraWeb.UserAuth, only: [fetch_current_user: 2]
55
import AlgoraWeb.VisitorCountry, only: [fetch_current_country: 2]
6+
import Phoenix.LiveDashboard.Router, only: [live_dashboard: 2]
67

78
pipeline :browser do
89
plug :accepts, ["html"]
@@ -53,10 +54,24 @@ defmodule AlgoraWeb.Router do
5354

5455
get "/tip", TipController, :create
5556

56-
live_session :admin,
57-
layout: {AlgoraWeb.Layouts, :user},
58-
on_mount: [{AlgoraWeb.UserAuth, :ensure_authenticated}, AlgoraWeb.User.Nav] do
59-
live "/admin/analytics", Admin.CompanyAnalyticsLive
57+
58+
scope "/admin" do
59+
live_session :admin,
60+
layout: {AlgoraWeb.Layouts, :user},
61+
on_mount: [
62+
{AlgoraWeb.UserAuth, :ensure_authenticated},
63+
{AlgoraWeb.UserAuth, :ensure_admin}, AlgoraWeb.User.Nav] do
64+
live "/analytics", Admin.CompanyAnalyticsLive
65+
end
66+
67+
live_dashboard "/dashboard",
68+
metrics: AlgoraWeb.Telemetry,
69+
additional_pages: [oban: Oban.LiveDashboard],
70+
layout: {AlgoraWeb.Layouts, :user},
71+
on_mount: [
72+
{AlgoraWeb.UserAuth, :ensure_authenticated},
73+
{AlgoraWeb.UserAuth, :ensure_admin}, AlgoraWeb.User.Nav
74+
]
6075
end
6176

6277
live_session :community,
@@ -137,19 +152,12 @@ defmodule AlgoraWeb.Router do
137152
# pipe_through :api
138153
# end
139154

140-
# Enable LiveDashboard and Swoosh mailbox preview in development
155+
# Enable Swoosh mailbox preview in development
141156
if Application.compile_env(:algora, :dev_routes) do
142-
# If you want to use the LiveDashboard in production, you should put
143-
# it behind authentication and allow only admins to access it.
144-
# If your application does not have an admins-only section yet,
145-
# you can use Plug.BasicAuth to set up some basic authentication
146-
# as long as you are also using SSL (which you should anyway).
147-
import Phoenix.LiveDashboard.Router
148157

149158
scope "/dev" do
150159
pipe_through :browser
151160

152-
live_dashboard "/dashboard", metrics: AlgoraWeb.Telemetry
153161
forward "/mailbox", Plug.Swoosh.MailboxPreview
154162
end
155163
end

mix.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ defmodule Algora.MixProject do
8080
{:ex_aws, "~> 2.1"},
8181
{:ex_aws_s3, "~> 2.0"},
8282
{:hackney, "~> 1.9"},
83+
# monitoring, logging
8384
{:appsignal_phoenix, "~> 2.6"},
84-
{:logfmt_ex, "~> 0.4"}
85+
{:logfmt_ex, "~> 0.4"},
86+
{:oban_live_dashboard, "~> 0.1.0"}
8587
]
8688
end
8789

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"nodejs": {:hex, :nodejs, "3.1.2", "a4dc114102782dcdc5fc13989398d19e594dd4e3a69181c8a8d54d08f4f950a4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.7", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "7b01eee72c16d919b122f7096918abe9d6062d3cc299afe694e72412bbe90c92"},
5353
"number": {:hex, :number, "1.0.5", "d92136f9b9382aeb50145782f116112078b3465b7be58df1f85952b8bb399b0f", [:mix], [{:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "c0733a0a90773a66582b9e92a3f01290987f395c972cb7d685f51dd927cd5169"},
5454
"oban": {:hex, :oban, "2.18.3", "1608c04f8856c108555c379f2f56bc0759149d35fa9d3b825cb8a6769f8ae926", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "36ca6ca84ef6518f9c2c759ea88efd438a3c81d667ba23b02b062a0aa785475e"},
55+
"oban_live_dashboard": {:hex, :oban_live_dashboard, "0.1.1", "8aa4ceaf381c818f7d5c8185cc59942b8ac82ef0cf559881aacf8d3f8ac7bdd3", [:mix], [{:oban, "~> 2.15", [hex: :oban, repo: "hexpm", optional: false]}, {:phoenix_live_dashboard, "~> 0.7", [hex: :phoenix_live_dashboard, repo: "hexpm", optional: false]}], "hexpm", "16dc4ce9c9a95aa2e655e35ed4e675652994a8def61731a18af85e230e1caa63"},
5556
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
5657
"phoenix": {:hex, :phoenix, "1.7.18", "5310c21443514be44ed93c422e15870aef254cf1b3619e4f91538e7529d2b2e4", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "1797fcc82108442a66f2c77a643a62980f342bfeb63d6c9a515ab8294870004e"},
5758
"phoenix_ecto": {:hex, :phoenix_ecto, "4.6.3", "f686701b0499a07f2e3b122d84d52ff8a31f5def386e03706c916f6feddf69ef", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "909502956916a657a197f94cc1206d9a65247538de8a5e186f7537c895d95764"},

0 commit comments

Comments
 (0)