mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
poll votes admin
This commit is contained in:
parent
2427d8d87c
commit
bf5158b60e
4 changed files with 48 additions and 20 deletions
|
@ -7,15 +7,15 @@ defmodule PhilomenaWeb.Topic.Poll.VoteController do
|
|||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :verify_authorized when action in [:index, :delete]
|
||||
plug PhilomenaWeb.FilterBannedUsersPlug when action in [:create]
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, index: :show, create: :show, delete: :show
|
||||
plug :load_and_authorize_resource, model: Forum, id_name: "forum_id", id_field: "short_name", persisted: true
|
||||
|
||||
plug PhilomenaWeb.LoadTopicPlug
|
||||
plug PhilomenaWeb.LoadPollPlug
|
||||
|
||||
plug :verify_authorized when action in [:index, :delete]
|
||||
|
||||
def index(conn, _params) do
|
||||
poll = conn.assigns.poll
|
||||
|
||||
|
@ -24,6 +24,7 @@ defmodule PhilomenaWeb.Topic.Poll.VoteController do
|
|||
|> where(poll_id: ^poll.id)
|
||||
|> preload(poll_votes: :user)
|
||||
|> Repo.all()
|
||||
|> Enum.filter(& &1.vote_count > 0)
|
||||
|
||||
render(conn, "index.html", layout: false, options: options)
|
||||
end
|
||||
|
@ -57,7 +58,7 @@ defmodule PhilomenaWeb.Topic.Poll.VoteController do
|
|||
end
|
||||
|
||||
defp verify_authorized(conn, _opts) do
|
||||
case Canada.Can.can?(conn.assigns.current_user, :index, PollVote) do
|
||||
case Canada.Can.can?(conn.assigns.current_user, :hide, conn.assigns.topic) do
|
||||
true -> conn
|
||||
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
||||
end
|
||||
|
|
|
@ -1,19 +1,31 @@
|
|||
= cond do
|
||||
- @poll.hidden_from_users ->
|
||||
.walloftext
|
||||
.block.block--fixed.block--warning
|
||||
h1 This poll has been deleted
|
||||
p
|
||||
' Reason:
|
||||
strong
|
||||
= @poll.deletion_reason || "Unknown (likely deleted in error). Please contact a moderator."
|
||||
.block__header.block__header--js-tabbed
|
||||
= link "Voting", to: "#", class: "selected", data: [click_tab: "voting"]
|
||||
|
||||
- not @voted and not is_nil(@conn.assigns.current_user) ->
|
||||
.poll
|
||||
.poll-area
|
||||
= render PhilomenaWeb.Topic.PollView, "_vote_form.html", assigns
|
||||
= if can?(@conn, :hide, @topic) do
|
||||
= link "Voters", to: "#", data: [click_tab: "voters", load_tab: Routes.forum_topic_poll_vote_path(@conn, :index, @forum, @topic)]
|
||||
|
||||
- true ->
|
||||
.poll
|
||||
.poll-area
|
||||
= render PhilomenaWeb.Topic.PollView, "_results.html", assigns
|
||||
.block__tab data-tab="voting"
|
||||
= cond do
|
||||
- @poll.hidden_from_users ->
|
||||
.walloftext
|
||||
.block.block--fixed.block--warning
|
||||
h1 This poll has been deleted
|
||||
p
|
||||
' Reason:
|
||||
strong
|
||||
= @poll.deletion_reason || "Unknown (likely deleted in error). Please contact a moderator."
|
||||
|
||||
- not @voted and not is_nil(@conn.assigns.current_user) ->
|
||||
.poll
|
||||
.poll-area
|
||||
= render PhilomenaWeb.Topic.PollView, "_vote_form.html", assigns
|
||||
|
||||
- true ->
|
||||
.poll
|
||||
.poll-area
|
||||
= render PhilomenaWeb.Topic.PollView, "_results.html", assigns
|
||||
|
||||
|
||||
= if can?(@conn, :hide, @topic) do
|
||||
.block__tab.hidden data-tab="voters"
|
||||
p Loading…
|
||||
|
|
12
lib/philomena_web/templates/topic/poll/vote/index.html.slime
Normal file
12
lib/philomena_web/templates/topic/poll/vote/index.html.slime
Normal file
|
@ -0,0 +1,12 @@
|
|||
= if Enum.any?(@options) do
|
||||
= for option <- @options do
|
||||
h5 = option.label
|
||||
|
||||
= for vote <- option.poll_votes do
|
||||
span.interaction-user-list-item
|
||||
=> link vote.user.name, to: Routes.profile_path(@conn, :show, vote.user)
|
||||
/= link "(x)", to: Routes.forum_topic_poll_vote_path(@conn, :delete, @forum, @topic, vote)
|
||||
|
||||
- else
|
||||
p
|
||||
em No votes to display
|
3
lib/philomena_web/views/topic/poll/vote_view.ex
Normal file
3
lib/philomena_web/views/topic/poll/vote_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.Topic.Poll.VoteView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
Loading…
Reference in a new issue