admin badge user list

This commit is contained in:
byte[] 2019-12-23 09:23:25 -05:00
parent 991cab61bf
commit 1435149d32
4 changed files with 62 additions and 1 deletions

View file

@ -0,0 +1,31 @@
defmodule PhilomenaWeb.Admin.Badge.UserController do
use PhilomenaWeb, :controller
alias Philomena.Users.User
alias Philomena.Badges.Badge
alias Philomena.Repo
import Ecto.Query
plug :verify_authorized
plug :load_resource, model: Badge, id_name: "badge_id", persisted: true
def index(conn, _params) do
badge = conn.assigns.badge
users =
User
|> join(:inner, [u], _ in assoc(u, :awards))
|> where([_u, a], a.badge_id == ^badge.id)
|> order_by([u, _a], asc: u.name)
|> Repo.paginate(conn.assigns.pagination)
render(conn, "index.html", title: "Users with badge #{badge.title}", users: users)
end
defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :index, Badge) do
true -> conn
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
end
end
end

View file

@ -230,7 +230,9 @@ defmodule PhilomenaWeb.Router do
resources "/adverts", AdvertController, except: [:show]
resources "/forums", ForumController, except: [:show, :delete]
resources "/badges", BadgeController, except: [:show, :delete]
resources "/badges", BadgeController, except: [:show, :delete] do
resources "/users", Badge.UserController, only: [:index]
end
resources "/mod_notes", ModNoteController, except: [:show]
resources "/users", UserController, only: [:index, :edit, :update] do
resources "/avatar", User.AvatarController, only: [:delete], singleton: true

View file

@ -0,0 +1,25 @@
h1
' Users with
=> @badge.title
' badge
- route = fn p -> Routes.admin_badge_user_path(@conn, :index, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @users, route: route, conn: @conn
.block
.block__header
= pagination
.block__content
table.table
thead
tr
th User
tbody
= for user <- @users do
tr
td
= link user.name, to: Routes.profile_path(@conn, :show, user)
.block__header.block__header--light
= pagination

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.Admin.Badge.UserView do
use PhilomenaWeb, :view
end