Fix previous

This commit is contained in:
byte[] 2022-05-11 16:41:53 -04:00
parent ea1bae56ed
commit cbcceeaaca
2 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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