diff --git a/lib/philomena_web/controllers/topic/poll/vote_controller.ex b/lib/philomena_web/controllers/topic/poll/vote_controller.ex index 9151f754..3e272100 100644 --- a/lib/philomena_web/controllers/topic/poll/vote_controller.ex +++ b/lib/philomena_web/controllers/topic/poll/vote_controller.ex @@ -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 diff --git a/lib/philomena_web/templates/topic/poll/_display.html.slime b/lib/philomena_web/templates/topic/poll/_display.html.slime index 39ddefb3..9d655847 100644 --- a/lib/philomena_web/templates/topic/poll/_display.html.slime +++ b/lib/philomena_web/templates/topic/poll/_display.html.slime @@ -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… diff --git a/lib/philomena_web/templates/topic/poll/vote/index.html.slime b/lib/philomena_web/templates/topic/poll/vote/index.html.slime new file mode 100644 index 00000000..5b71a100 --- /dev/null +++ b/lib/philomena_web/templates/topic/poll/vote/index.html.slime @@ -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 diff --git a/lib/philomena_web/views/topic/poll/vote_view.ex b/lib/philomena_web/views/topic/poll/vote_view.ex new file mode 100644 index 00000000..ea77e8cc --- /dev/null +++ b/lib/philomena_web/views/topic/poll/vote_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.Topic.Poll.VoteView do + use PhilomenaWeb, :view +end