diff --git a/lib/philomena/workers/tag_change_revert_worker.ex b/lib/philomena/workers/tag_change_revert_worker.ex index 7822dc15..69433e95 100644 --- a/lib/philomena/workers/tag_change_revert_worker.ex +++ b/lib/philomena/workers/tag_change_revert_worker.ex @@ -2,6 +2,7 @@ defmodule Philomena.TagChangeRevertWorker do alias Philomena.TagChanges.TagChange alias Philomena.TagChanges alias Philomena.Batch + alias Philomena.Repo import Ecto.Query def perform(%{"user_id" => user_id, "attributes" => attributes}) do @@ -23,8 +24,17 @@ defmodule Philomena.TagChangeRevertWorker do end defp revert_all(queryable, attributes) do - Batch.query_batches(queryable, [batch_size: 100], fn ids -> - TagChanges.mass_revert(ids, attributes) + Batch.query_batches(queryable, [batch_size: 100], fn queryable -> + ids = Repo.all(select(queryable, [tc], tc.id)) + TagChanges.mass_revert(ids, cast_ip(atomify_keys(attributes))) end) end + + defp atomify_keys(map) do + Map.new(map, fn {k, v} -> {String.to_existing_atom(k), v} end) + end + + defp cast_ip(attributes) do + %{attributes | ip: elem(EctoNetwork.INET.cast(attributes[:ip]), 1)} + end end diff --git a/lib/philomena_web/templates/profile/_admin_block.html.slime b/lib/philomena_web/templates/profile/_admin_block.html.slime index 44c0fe4f..187772d2 100644 --- a/lib/philomena_web/templates/profile/_admin_block.html.slime +++ b/lib/philomena_web/templates/profile/_admin_block.html.slime @@ -171,7 +171,7 @@ a.label.label--primary.label--block href="#" data-click-toggle=".js-admin__optio i.fa.fa-fw.fa-arrow-down span.admin__button Remove All Downvotes - = if can?(@conn, :revert, Philomena.TagChanges.TagChange) do + = if @user.role == "user" and can?(@conn, :revert, Philomena.TagChanges.TagChange) do li = link to: Routes.tag_change_full_revert_path(@conn, :create, [user_id: @user.id]), data: [confirm: "Are you really, really sure?", method: "create"] do i.fa.fa-fw.fa-tag