mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
staff page
This commit is contained in:
parent
d2e7afb3c7
commit
c047f0af6d
6 changed files with 129 additions and 1 deletions
|
@ -40,7 +40,7 @@
|
||||||
"Help & Information": [
|
"Help & Information": [
|
||||||
{
|
{
|
||||||
"title": "Changelog",
|
"title": "Changelog",
|
||||||
"url": "/changelog",
|
"url": "https://github.com/derpibooru/philomena/commits/master",
|
||||||
"bold": true
|
"bold": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
24
lib/philomena_web/controllers/staff_controller.ex
Normal file
24
lib/philomena_web/controllers/staff_controller.ex
Normal 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
|
|
@ -130,6 +130,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
resources "/adverts", AdvertController, only: [:show]
|
resources "/adverts", AdvertController, only: [:show]
|
||||||
resources "/pages", PageController, only: [:show]
|
resources "/pages", PageController, only: [:show]
|
||||||
resources "/dnp", DnpEntryController, only: [:index, :show]
|
resources "/dnp", DnpEntryController, only: [:index, :show]
|
||||||
|
resources "/staff", StaffController, only: [:index]
|
||||||
|
|
||||||
get "/:id", ImageController, :show
|
get "/:id", ImageController, :show
|
||||||
# get "/:forum_id", ForumController, :show # impossible to do without constraints
|
# get "/:forum_id", ForumController, :show # impossible to do without constraints
|
||||||
|
|
12
lib/philomena_web/templates/staff/index.html.slime
Normal file
12
lib/philomena_web/templates/staff/index.html.slime
Normal 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
|
3
lib/philomena_web/views/staff_view.ex
Normal file
3
lib/philomena_web/views/staff_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule PhilomenaWeb.StaffView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
end
|
88
test/philomena_web/controllers/staff_controller_test.exs
Normal file
88
test/philomena_web/controllers/staff_controller_test.exs
Normal 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
|
Loading…
Reference in a new issue