staff page

This commit is contained in:
byte[] 2019-11-29 17:01:54 -05:00
parent d2e7afb3c7
commit c047f0af6d
6 changed files with 129 additions and 1 deletions

View file

@ -40,7 +40,7 @@
"Help & Information": [
{
"title": "Changelog",
"url": "/changelog",
"url": "https://github.com/derpibooru/philomena/commits/master",
"bold": true
},
{

View file

@ -0,0 +1,24 @@
defmodule PhilomenaWeb.StaffController do
use PhilomenaWeb, :controller
alias Philomena.Users.User
alias Philomena.Repo
import Ecto.Query
def index(conn, _params) do
users =
User
|> where([u], u.role in ["admin", "moderator", "assistant"])
|> order_by(asc: :name)
|> Repo.all()
categories = %{
"Administrators" => Enum.filter(users, & &1.role == "admin"),
"Technical Team" => Enum.filter(users, & &1.role != "admin" and &1.secondary_role not in [nil, ""]),
"Moderators" => Enum.filter(users, & &1.role != "admin" and &1.secondary_role in [nil, ""]),
"Assistants" => Enum.filter(users, & &1.role == "assistant" and &1.secondary_role in [nil, ""])
}
render(conn, "index.html", categories: categories)
end
end

View file

@ -130,6 +130,7 @@ defmodule PhilomenaWeb.Router do
resources "/adverts", AdvertController, only: [:show]
resources "/pages", PageController, only: [:show]
resources "/dnp", DnpEntryController, only: [:index, :show]
resources "/staff", StaffController, only: [:index]
get "/:id", ImageController, :show
# get "/:forum_id", ForumController, :show # impossible to do without constraints

View file

@ -0,0 +1,12 @@
h1 Staff
.staff-block
= for {header, users} <- @categories do
= if Enum.any?(users) do
h4 = header
= for user <- users do
a.profile-block href=Routes.profile_path(@conn, :show, user)
= render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: user}, class: "avatar--125px"
b
=> user.name

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.StaffView do
use PhilomenaWeb, :view
end

View file

@ -0,0 +1,88 @@
defmodule PhilomenaWeb.StaffControllerTest do
use PhilomenaWeb.ConnCase
alias Philomena.Staffs
@create_attrs %{}
@update_attrs %{}
@invalid_attrs %{}
def fixture(:staff) do
{:ok, staff} = Staffs.create_staff(@create_attrs)
staff
end
describe "index" do
test "lists all staffs", %{conn: conn} do
conn = get(conn, Routes.staff_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Staffs"
end
end
describe "new staff" do
test "renders form", %{conn: conn} do
conn = get(conn, Routes.staff_path(conn, :new))
assert html_response(conn, 200) =~ "New Staff"
end
end
describe "create staff" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, Routes.staff_path(conn, :create), staff: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.staff_path(conn, :show, id)
conn = get(conn, Routes.staff_path(conn, :show, id))
assert html_response(conn, 200) =~ "Show Staff"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.staff_path(conn, :create), staff: @invalid_attrs)
assert html_response(conn, 200) =~ "New Staff"
end
end
describe "edit staff" do
setup [:create_staff]
test "renders form for editing chosen staff", %{conn: conn, staff: staff} do
conn = get(conn, Routes.staff_path(conn, :edit, staff))
assert html_response(conn, 200) =~ "Edit Staff"
end
end
describe "update staff" do
setup [:create_staff]
test "redirects when data is valid", %{conn: conn, staff: staff} do
conn = put(conn, Routes.staff_path(conn, :update, staff), staff: @update_attrs)
assert redirected_to(conn) == Routes.staff_path(conn, :show, staff)
conn = get(conn, Routes.staff_path(conn, :show, staff))
assert html_response(conn, 200)
end
test "renders errors when data is invalid", %{conn: conn, staff: staff} do
conn = put(conn, Routes.staff_path(conn, :update, staff), staff: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Staff"
end
end
describe "delete staff" do
setup [:create_staff]
test "deletes chosen staff", %{conn: conn, staff: staff} do
conn = delete(conn, Routes.staff_path(conn, :delete, staff))
assert redirected_to(conn) == Routes.staff_path(conn, :index)
assert_error_sent 404, fn ->
get(conn, Routes.staff_path(conn, :show, staff))
end
end
end
defp create_staff(_) do
staff = fixture(:staff)
{:ok, staff: staff}
end
end