mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
use canary mapper
This commit is contained in:
parent
f99b11db1d
commit
664822dbd2
5 changed files with 23 additions and 0 deletions
|
@ -64,6 +64,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
|||
when action in [:show, :index],
|
||||
do: true
|
||||
|
||||
# Vote on images they can see
|
||||
def can?(user, :vote, image), do: can?(user, :show, image)
|
||||
|
||||
# View non-deleted comments
|
||||
def can?(_user, :show, %Comment{hidden_from_users: false}), do: true
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule PhilomenaWeb.Image.FaveController do
|
|||
alias Ecto.Multi
|
||||
|
||||
plug PhilomenaWeb.Plugs.FilterBannedUsers
|
||||
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote
|
||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||
|
||||
def create(conn, _params) do
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule PhilomenaWeb.Image.HideController do
|
|||
alias Ecto.Multi
|
||||
|
||||
plug PhilomenaWeb.Plugs.FilterBannedUsers
|
||||
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote
|
||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||
|
||||
def create(conn, _params) do
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule PhilomenaWeb.Image.VoteController do
|
|||
alias Ecto.Multi
|
||||
|
||||
plug PhilomenaWeb.Plugs.FilterBannedUsers
|
||||
plug PhilomenaWeb.Plugs.CanaryMapPlug, create: :vote, delete: :vote
|
||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||
|
||||
def create(conn, params) do
|
||||
|
|
17
lib/philomena_web/plugs/canary_map_plug.ex
Normal file
17
lib/philomena_web/plugs/canary_map_plug.ex
Normal file
|
@ -0,0 +1,17 @@
|
|||
defmodule PhilomenaWeb.Plugs.CanaryMapPlug do
|
||||
import Plug.Conn
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
def call(conn, opts) do
|
||||
phx_action = conn.private.phoenix_action
|
||||
canary_action =
|
||||
case Keyword.fetch(opts, phx_action) do
|
||||
{:ok, action} -> action
|
||||
_ -> phx_action
|
||||
end
|
||||
|
||||
conn
|
||||
|> assign(:canary_action, canary_action)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue