From cbcceeaaca153879e5d99d8eb8e5c1d70e79aef4 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 11 May 2022 16:41:53 -0400 Subject: [PATCH] Fix previous --- lib/philomena/workers/tag_change_revert_worker.ex | 14 ++++++++++++-- .../templates/profile/_admin_block.html.slime | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) 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