[KeywordPolicy] Implement the 'reset' action on Keyword Policies
This commit is contained in:
parent
8f8ef607a0
commit
b8ac215524
|
@ -60,14 +60,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
|||
|> put_in(["object", "summary"], summary)}
|
||||
end
|
||||
|
||||
def save_keyword_policy(keyword_policy=%{"federated_timeline_removal" => ftr,
|
||||
"reject" => reject,
|
||||
"replace" => replace}) do
|
||||
def save_keyword_policy(%{"federated_timeline_removal" => ftr,
|
||||
"reject" => reject,
|
||||
"replace" => replace}) do
|
||||
with true <- Enum.all?(ftr, &String.valid?(&1)),
|
||||
true <- Enum.all?(reject, &String.valid?(&1)),
|
||||
true <- Enum.all?(Map.keys(replace), &String.valid?(&1)),
|
||||
true <- Enum.all?(Map.values(replace), &String.valid?(&1)) do
|
||||
Pleroma.Config.put(:mrf_keyword, keyword_policy)
|
||||
Pleroma.Config.put(:mrf_keyword, %{federated_timeline_removal: ftr,
|
||||
reject: reject,
|
||||
replace: replace
|
||||
})
|
||||
:ok
|
||||
else
|
||||
false -> {:error, "All elements must be valid strings"}
|
||||
|
|
|
@ -196,8 +196,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
@doc "Add another MRF Keyword Policy rule"
|
||||
def add_keyword_policy(conn, %{"policy" => policy}) do
|
||||
result = policy
|
||||
|> Poison.decode! #FIXME: Better handling of invalid JSON
|
||||
|> IO.inspect()
|
||||
|> Poison.decode!
|
||||
|> KeywordPolicy.save_keyword_policy()
|
||||
|
||||
case result do
|
||||
|
@ -211,7 +210,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
|> json(%{status: "error", message: msg})
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@doc "Reset the keyword policy"
|
||||
def reset_keyword_policy(conn, _params) do
|
||||
KeywordPolicy.save_keyword_policy(%{"federated_timeline_removal" => [],
|
||||
"reject" => [],
|
||||
"replace" => %{}
|
||||
})
|
||||
conn
|
||||
|> put_status(200)
|
||||
|> json(%{status: "success", message: "Keyword Policy has been successfully reset"})
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ defmodule Pleroma.Web.Router do
|
|||
get("/password_reset", AdminAPIController, :get_password_reset)
|
||||
|
||||
post("/mrf/keyword_policy/add", AdminAPIController, :add_keyword_policy)
|
||||
delete("/mrf/keyword_policy/delete", AdminAPIController, :delete_keyword_policy)
|
||||
delete("/mrf/keyword_policy/reset", AdminAPIController, :reset_keyword_policy)
|
||||
get("/mrf/keyword_policy/list", AdminAPIController, :list_keyword_policy)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue