mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Fix previous
This commit is contained in:
parent
ea1bae56ed
commit
cbcceeaaca
2 changed files with 13 additions and 3 deletions
|
@ -2,6 +2,7 @@ defmodule Philomena.TagChangeRevertWorker do
|
||||||
alias Philomena.TagChanges.TagChange
|
alias Philomena.TagChanges.TagChange
|
||||||
alias Philomena.TagChanges
|
alias Philomena.TagChanges
|
||||||
alias Philomena.Batch
|
alias Philomena.Batch
|
||||||
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def perform(%{"user_id" => user_id, "attributes" => attributes}) do
|
def perform(%{"user_id" => user_id, "attributes" => attributes}) do
|
||||||
|
@ -23,8 +24,17 @@ defmodule Philomena.TagChangeRevertWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp revert_all(queryable, attributes) do
|
defp revert_all(queryable, attributes) do
|
||||||
Batch.query_batches(queryable, [batch_size: 100], fn ids ->
|
Batch.query_batches(queryable, [batch_size: 100], fn queryable ->
|
||||||
TagChanges.mass_revert(ids, attributes)
|
ids = Repo.all(select(queryable, [tc], tc.id))
|
||||||
|
TagChanges.mass_revert(ids, cast_ip(atomify_keys(attributes)))
|
||||||
end)
|
end)
|
||||||
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
|
end
|
||||||
|
|
|
@ -171,7 +171,7 @@ a.label.label--primary.label--block href="#" data-click-toggle=".js-admin__optio
|
||||||
i.fa.fa-fw.fa-arrow-down
|
i.fa.fa-fw.fa-arrow-down
|
||||||
span.admin__button Remove All Downvotes
|
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
|
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
|
= 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
|
i.fa.fa-fw.fa-tag
|
||||||
|
|
Loading…
Reference in a new issue