-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route for admin dashboard w/ tests and auth
- Loading branch information
1 parent
72b782d
commit 4b0b189
Showing
9 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Heimdall.Admin do | ||
@moduledoc """ | ||
Admin-related tasks | ||
""" | ||
|
||
@doc """ | ||
Returns Heimdall stats using given parameters | ||
""" | ||
@spec stats(map()) :: map() | ||
def stats(params) do | ||
params | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/heimdall_web/controllers/admin/dashboard_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule HeimdallWeb.Admin.DashboardController do | ||
use HeimdallWeb, :controller | ||
|
||
alias Heimdall.Admin | ||
|
||
def index(conn, params) do | ||
stats = Admin.stats(params) | ||
render(conn, :index, stats: stats) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule HeimdallWeb.Admin.DashboardHTML do | ||
use HeimdallWeb, :html | ||
|
||
embed_templates "dashboard_html/*" | ||
end |
1 change: 1 addition & 0 deletions
1
lib/heimdall_web/controllers/admin/dashboard_html/index.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Admin Dashboard: TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
alias Heimdall.Repo | ||
41 changes: 41 additions & 0 deletions
41
test/heimdall_web/controllers/admin/dashboard_controller_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule HeimdallWeb.Admin.DashboardControllerTest do | ||
use HeimdallWeb.ConnCase | ||
|
||
describe "index/2 (GET /admin)" do | ||
test "doesn't allow view page without user and password", %{conn: conn} do | ||
conn = get(conn, ~p"/admin") | ||
|
||
assert conn.status == 401 | ||
end | ||
|
||
test "shows dashboard if authenticated", %{conn: conn} do | ||
conn = add_admin_auth(conn) | ||
|
||
conn = get(conn, ~p"/admin") | ||
|
||
refute conn.status == 401 | ||
end | ||
end | ||
|
||
defp add_admin_auth(conn) do | ||
basic_auth = | ||
Plug.BasicAuth.encode_basic_auth( | ||
admin_user(), | ||
admin_password() | ||
) | ||
|
||
put_req_header( | ||
conn, | ||
"authorization", | ||
basic_auth | ||
) | ||
end | ||
|
||
defp admin_user do | ||
Application.get_env(:heimdall, :admin_user) | ||
end | ||
|
||
defp admin_password do | ||
Application.get_env(:heimdall, :admin_password) | ||
end | ||
end |