hides, vote tampering

This commit is contained in:
byte[] 2019-12-30 07:50:02 -05:00
parent dfaee1e34d
commit 4342978483
4 changed files with 46 additions and 4 deletions

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Image.FavoriteController do
defp load_votes_if_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :hide, conn.assigns.image) do
true ->
image = Repo.preload(conn.assigns.image, upvotes: :user, downvotes: :user)
image = Repo.preload(conn.assigns.image, upvotes: :user, downvotes: :user, hides: :user)
conn
|> assign(:image, image)

View file

@ -0,0 +1,29 @@
defmodule PhilomenaWeb.Image.TamperController do
use PhilomenaWeb, :controller
alias Philomena.Users.User
alias Philomena.Images.Image
alias Philomena.Images
alias Philomena.ImageVotes
alias Philomena.Repo
plug PhilomenaWeb.CanaryMapPlug, create: :hide
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
plug :load_resource, model: User, id_name: "user_id", persisted: true
def create(conn, _params) do
image = conn.assigns.image
user = conn.assigns.user
{:ok, _result} =
ImageVotes.delete_vote_transaction(image, user)
|> Repo.isolated_transaction(:serializable)
Images.reindex_image(image)
conn
|> put_flash(:info, "Vote removed.")
|> redirect(to: Routes.image_path(conn, :show, conn.assigns.image))
end
end

View file

@ -138,6 +138,7 @@ defmodule PhilomenaWeb.Router do
end
resources "/delete", Image.DeleteController, only: [:create, :delete], singleton: true
resources "/tamper", Image.TamperController, only: [:create], singleton: true
resources "/hash", Image.HashController, only: [:delete], singleton: true
resources "/source_history", Image.SourceHistoryController, only: [:delete], singleton: true
resources "/repair", Image.RepairController, only: [:create], singleton: true

View file

@ -10,10 +10,12 @@ h5
h5
' Upvoted by
=> @image.upvotes_count
= pluralize("user", "users", @image.faves_count)
= pluralize("user", "users", @image.upvotes_count)
= for upvote <- Enum.sort_by(@image.upvotes, & &1.user.name) do
=> link upvote.user.name, to: Routes.profile_path(@conn, :show, upvote.user), class: "interaction-user-list-item"
span.interaction-user-list-item
=> link upvote.user.name, to: Routes.profile_path(@conn, :show, upvote.user)
=> link "(x)", to: Routes.image_tamper_path(@conn, :create, @image, user_id: upvote.user_id), method: "post"
h5
' Downvoted by
@ -21,4 +23,14 @@ h5
= pluralize("user", "users", @image.downvotes_count)
= for downvote <- Enum.sort_by(@image.downvotes, & &1.user.name) do
=> link downvote.user.name, to: Routes.profile_path(@conn, :show, downvote.user), class: "interaction-user-list-item"
span.interaction-user-list-item
=> link downvote.user.name, to: Routes.profile_path(@conn, :show, downvote.user)
=> link "(x)", to: Routes.image_tamper_path(@conn, :create, @image, user_id: downvote.user_id), method: "post"
h5
' Hidden by
=> @image.hides_count
= pluralize("user", "users", @image.hides_count)
= for hide <- Enum.sort_by(@image.hides, & &1.user.name) do
=> link hide.user.name, to: Routes.profile_path(@conn, :show, hide.user), class: "interaction-user-list-item"