From 9c7bbc127b6e2a7cbfd97101f6d7946a7f65cc3f Mon Sep 17 00:00:00 2001 From: Luna D Date: Mon, 17 Feb 2020 12:21:19 -0500 Subject: [PATCH] fix assistants not being able to do user links --- lib/philomena/user_links.ex | 2 +- lib/philomena/users/ability.ex | 3 +++ lib/philomena_web/controllers/admin/user_link_controller.ex | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/philomena/user_links.ex b/lib/philomena/user_links.ex index 277ec21d..1fe30fbf 100644 --- a/lib/philomena/user_links.ex +++ b/lib/philomena/user_links.ex @@ -151,7 +151,7 @@ defmodule Philomena.UserLinks do end def count_user_links(user) do - if Canada.Can.can?(user, :index, UserLink) do + if Canada.Can.can?(user, :index, %UserLink{}) do UserLink |> where([ul], ul.aasm_state in ^["unverified", "link_verified", "contacted"]) |> Repo.aggregate(:count, :id) diff --git a/lib/philomena/users/ability.ex b/lib/philomena/users/ability.ex index 07a56d26..1e769724 100644 --- a/lib/philomena/users/ability.ex +++ b/lib/philomena/users/ability.ex @@ -253,6 +253,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do def can?(%User{role: "assistant", role_map: %{"UserLink" => "moderator"}}, :edit, %UserLink{}), do: true + def can?(%User{role: "assistant", role_map: %{"UserLink" => "moderator"}}, :index, %UserLink{}), + do: true + # View forums def can?(%User{role: "assistant"}, :show, %Forum{access_level: level}) when level in ["normal", "assistant"], diff --git a/lib/philomena_web/controllers/admin/user_link_controller.ex b/lib/philomena_web/controllers/admin/user_link_controller.ex index 11c5e717..36e04644 100644 --- a/lib/philomena_web/controllers/admin/user_link_controller.ex +++ b/lib/philomena_web/controllers/admin/user_link_controller.ex @@ -42,7 +42,7 @@ defmodule PhilomenaWeb.Admin.UserLinkController do end 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 false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) end