fix assistants not being able to do user links

This commit is contained in:
Luna D 2020-02-17 12:21:19 -05:00
parent 79e25bfd6b
commit 9c7bbc127b
No known key found for this signature in database
GPG key ID: D0F46C94720BAA4B
3 changed files with 5 additions and 2 deletions

View file

@ -151,7 +151,7 @@ defmodule Philomena.UserLinks do
end end
def count_user_links(user) do def count_user_links(user) do
if Canada.Can.can?(user, :index, UserLink) do if Canada.Can.can?(user, :index, %UserLink{}) do
UserLink UserLink
|> where([ul], ul.aasm_state in ^["unverified", "link_verified", "contacted"]) |> where([ul], ul.aasm_state in ^["unverified", "link_verified", "contacted"])
|> Repo.aggregate(:count, :id) |> Repo.aggregate(:count, :id)

View file

@ -253,6 +253,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
def can?(%User{role: "assistant", role_map: %{"UserLink" => "moderator"}}, :edit, %UserLink{}), def can?(%User{role: "assistant", role_map: %{"UserLink" => "moderator"}}, :edit, %UserLink{}),
do: true do: true
def can?(%User{role: "assistant", role_map: %{"UserLink" => "moderator"}}, :index, %UserLink{}),
do: true
# View forums # View forums
def can?(%User{role: "assistant"}, :show, %Forum{access_level: level}) def can?(%User{role: "assistant"}, :show, %Forum{access_level: level})
when level in ["normal", "assistant"], when level in ["normal", "assistant"],

View file

@ -42,7 +42,7 @@ defmodule PhilomenaWeb.Admin.UserLinkController do
end end
defp verify_authorized(conn, _opts) do defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :index, UserLink) do case Canada.Can.can?(conn.assigns.current_user, :index, %UserLink{}) do
true -> conn true -> conn
false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
end end