-
Notifications
You must be signed in to change notification settings - Fork 56
Scaffold Staff Interface #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b5615f
Add styles from source-academy2
indocomsoft 2c7f56b
Add admin check pipeline
indocomsoft 177ba1c
Add admin interface
indocomsoft 3ddc4a7
Add tests
indocomsoft d9e6aaa
Fix moduledoc for CadetWeb.Plug.CheckAdmin
indocomsoft 85a4517
Add more tests
indocomsoft f08205d
Refactor into EnsureRoles
indocomsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,35 @@ | ||
.sa-admin-navbar { | ||
position: fixed; | ||
top: 50px; | ||
left: 0px; | ||
width: 100%; | ||
z-index: 1; | ||
background: $sa-gray3; | ||
|
||
a { | ||
color: $sa-dark-blue; | ||
font-weight: 500; | ||
text-transform: uppercase; | ||
padding: 5px; | ||
} | ||
|
||
.first-row, .second-row { | ||
padding: 0px 20px; | ||
} | ||
|
||
.first-row a { | ||
font-size: 1.1em; | ||
} | ||
|
||
.second-row a { | ||
font-size: 0.85em; | ||
} | ||
|
||
.second-row { | ||
background: $sa-gray4; | ||
} | ||
|
||
a.pt-button::after { | ||
display: none !important; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
@import 'layout'; | ||
@import 'session'; | ||
|
||
@import 'admin'; |
This file contains hidden or 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,7 @@ | ||
defmodule CadetWeb.AdminController do | ||
use CadetWeb, :controller | ||
|
||
def index(conn, _) do | ||
render(conn, "index.html") | ||
end | ||
end |
This file contains hidden or 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,25 @@ | ||
defmodule CadetWeb.Plug.EnsureRoles do | ||
@moduledoc """ | ||
Ensures that :current_user's role is inside a list provided as option. | ||
If the user is not inside the list, HTTP 403 response will be sent. | ||
""" | ||
|
||
import Plug.Conn | ||
|
||
def init(opts), do: opts | ||
|
||
def call(conn, %{roles: roles}) do | ||
if conn.assigns[:current_user].role in roles do | ||
conn | ||
else | ||
body = | ||
roles | ||
|> Enum.map(&to_string/1) | ||
|> Enum.join("/") | ||
conn | ||
|> put_resp_content_type("text/html") | ||
|> send_resp(:forbidden, "Not #{body}") | ||
|> halt() | ||
end | ||
end | ||
end |
This file contains hidden or 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 hidden or 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,24 @@ | ||
<div class="sa-admin-navbar"> | ||
<div class="first-row"> | ||
<div class="container"> | ||
<div class="pt-button-group pt-minimal"> | ||
<%= link "Announcements", to: "#", class: "pt-button" %> | ||
<%= link "Assessments", to: "#", class: "pt-button" %> | ||
<%= link "My Students", to: "#", class: "pt-button" %> | ||
<%= link "Gradings", to: "#", class: "pt-button" %> | ||
<%= link "Path Submissions", to: "#", class: "pt-button" %> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="second-row"> | ||
<div class="container"> | ||
<div class="pt-button-group pt-minimal"> | ||
<%= link "Achievements", to: "#", class: "pt-button" %> | ||
<%= link "Materials", to: "#", class: "pt-button" %> | ||
<%= link "Discussion Groups", to: "#", class: "pt-button" %> | ||
<%= link "Students", to: "#", class: "pt-button" %> | ||
<%= link "Libraries", to: "#", class: "pt-button" %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains hidden or 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 hidden or 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,3 @@ | ||
defmodule CadetWeb.AdminView do | ||
use CadetWeb, :view | ||
end |
This file contains hidden or 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 hidden or 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,26 @@ | ||
defmodule CadetWeb.AdminControllerTest do | ||
use CadetWeb.ConnCase | ||
|
||
describe "Unauthenticated User" do | ||
test "GET /admin", %{conn: conn} do | ||
conn = get(conn, "/admin") | ||
assert html_response(conn, 401) =~ "unauthenticated" | ||
end | ||
end | ||
|
||
@tag authenticate: :student | ||
describe "Authenticated Student" do | ||
test "GET /admin", %{conn: conn} do | ||
conn = get(conn, "/admin") | ||
assert html_response(conn, 403) =~ "Not admin" | ||
end | ||
end | ||
|
||
@tag authenticate: :admin | ||
describe "Authenticated Admin" do | ||
test "GET /admin", %{conn: conn} do | ||
conn = get(conn, "/admin") | ||
assert html_response(conn, 200) =~ "Admin" | ||
end | ||
end | ||
end |
This file contains hidden or 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,32 @@ | ||
defmodule CadetWeb.Plug.EnsureRolesTest do | ||
use CadetWeb.ConnCase | ||
|
||
alias CadetWeb.Plug.AssignCurrentUser | ||
alias CadetWeb.Plug.EnsureRoles | ||
|
||
test "init" do | ||
EnsureRoles.init(%{}) | ||
# nothing to test | ||
end | ||
|
||
@tag authenticate: :student | ||
test "logged in as student", %{conn: conn} do | ||
conn = AssignCurrentUser.call(conn, %{}) | ||
conn = EnsureRoles.call(conn, %{roles: [:admin, :staff]}) | ||
assert html_response(conn, 403) =~ "Not admin/staff" | ||
end | ||
|
||
@tag authenticate: :staff | ||
test "logged in as staff", %{conn: conn} do | ||
conn = AssignCurrentUser.call(conn, %{}) | ||
conn = EnsureRoles.call(conn, %{roles: [:admin, :staff]}) | ||
refute conn.status # conn.status is not set yet | ||
end | ||
|
||
@tag authenticate: :admin | ||
test "logged in as admin", %{conn: conn} do | ||
conn = AssignCurrentUser.call(conn, %{}) | ||
conn = EnsureRoles.call(conn, %{roles: [:admin, :staff]}) | ||
refute conn.status # conn.status is not set yet | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement the test. I just fixed Coveralls