Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI to revert tag changes one-by-one #202

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/philomena/workers/tag_change_revert_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ defmodule Philomena.TagChangeRevertWorker do
end

defp revert_all(queryable, attributes) do
Batch.query_batches(queryable, [batch_size: 100], fn queryable ->
batch_size = attributes["batch_size"] || 100
attributes = Map.delete(attributes, "batch_size")

Batch.query_batches(queryable, [batch_size: batch_size], fn queryable ->
ids = Repo.all(select(queryable, [tc], tc.id))
TagChanges.mass_revert(ids, cast_ip(atomify_keys(attributes)))
end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ defmodule PhilomenaWeb.TagChange.FullRevertController do
plug :verify_authorized
plug PhilomenaWeb.UserAttributionPlug

def create(conn, params) do
attributes = conn.assigns.attributes

def create(%{assigns: %{attributes: attributes}} = conn, params) do
attributes = %{
ip: to_string(attributes[:ip]),
fingerprint: attributes[:fingerprint],
referrer: attributes[:referrer],
user_agent: attributes[:referrer],
user_id: attributes[:user].id
user_id: attributes[:user].id,
batch_size: attributes[:batch_size] || 100
}

case params do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint, batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]

h4 Observed users
table.table
Expand Down
1 change: 1 addition & 0 deletions lib/philomena_web/templates/ip_profile/show.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip)]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip), batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]

h4 Observed users
table.table
Expand Down
Loading