refactor save_keyword_policy and list_keyword_policy to be just save and list as they are already under KeywordPolicy module

This commit is contained in:
rinpatch 2019-04-05 11:40:14 +03:00
parent b14446d878
commit b7994e674f
4 changed files with 8 additions and 8 deletions

View File

@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|> put_in(["object", "summary"], summary)}
end
def save_keyword_policy(%{
def save(%{
federated_timeline_removal: ftr,
reject: reject,
replace: replace
@ -100,7 +100,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
end
end
def list_keyword_policy do
def list do
config = Pleroma.Config.get(:mrf_keyword, %{})
Enum.reduce(config, %{}, fn {key, value}, acc ->

View File

@ -243,7 +243,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
@doc "List this instance's keyword policy"
def list_keyword_policy(conn, _params) do
mrf_keyword = KeywordPolicy.list_keyword_policy()
mrf_keyword = KeywordPolicy.list()
conn
|> put_status(200)
@ -255,7 +255,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
result =
policy
|> Poison.decode!(keys: :atoms!)
|> KeywordPolicy.save_keyword_policy()
|> KeywordPolicy.save()
case result do
:ok ->
@ -272,7 +272,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
@doc "Reset the keyword policy"
def reset_keyword_policy(conn, _params) do
KeywordPolicy.save_keyword_policy(%{
KeywordPolicy.save(%{
federated_timeline_removal: [],
reject: [],
replace: %{}

View File

@ -45,7 +45,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
Application.get_env(:pleroma, :mrf_simple)
|> Enum.into(%{})
mrf_keyword = KeywordPolicy.list_keyword_policy()
mrf_keyword = KeywordPolicy.list()
mrf_policies =
MRF.get_policies()

View File

@ -14,13 +14,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
describe "managing keyword policies" do
test "save a new valid keyword policy" do
config = Pleroma.Config.get(:mrf_keyword)
result = KeywordPolicy.save_keyword_policy(%{config | replace: %{"toot" => "jort"}})
result = KeywordPolicy.save(%{config | replace: %{"toot" => "jort"}})
assert result == :ok
end
test "save a new invalid keyword policy" do
config = Pleroma.Config.get(:mrf_keyword)
result = KeywordPolicy.save_keyword_policy(%{config | replace: %{3 => "jort"}})
result = KeywordPolicy.save(%{config | replace: %{3 => "jort"}})
assert {:error, _} = result
end
end