[KeywordPolicy] Preliminary work
This commit is contained in:
parent
7daa9a8c42
commit
2d9b5a0403
|
@ -26,6 +26,11 @@ defmodule Pleroma.Application do
|
|||
|
||||
Pleroma.Config.DeprecationWarnings.warn()
|
||||
|
||||
default_settings = [ default_ttl: 25000,
|
||||
ttl_interval: 1000,
|
||||
limit: 2500
|
||||
]
|
||||
|
||||
# Define workers and child supervisors to be supervised
|
||||
children =
|
||||
[
|
||||
|
@ -33,6 +38,11 @@ defmodule Pleroma.Application do
|
|||
supervisor(Pleroma.Repo, []),
|
||||
worker(Pleroma.Emoji, []),
|
||||
worker(Pleroma.Captcha, []),
|
||||
worker(Cachex,
|
||||
[
|
||||
:keyword_policy_cache,
|
||||
default_settings
|
||||
])
|
||||
worker(
|
||||
Cachex,
|
||||
[
|
||||
|
@ -47,11 +57,7 @@ defmodule Pleroma.Application do
|
|||
Cachex,
|
||||
[
|
||||
:user_cache,
|
||||
[
|
||||
default_ttl: 25000,
|
||||
ttl_interval: 1000,
|
||||
limit: 2500
|
||||
]
|
||||
default_settings
|
||||
],
|
||||
id: :cachex_user
|
||||
),
|
||||
|
@ -59,11 +65,7 @@ defmodule Pleroma.Application do
|
|||
Cachex,
|
||||
[
|
||||
:object_cache,
|
||||
[
|
||||
default_ttl: 25000,
|
||||
ttl_interval: 1000,
|
||||
limit: 2500
|
||||
]
|
||||
default_settings
|
||||
],
|
||||
id: :cachex_object
|
||||
),
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Pleroma.Web.ActivityPub.MRF.KeywordPolicy.Schema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
|
||||
schema "keyword_policies" do
|
||||
field :federated_timeline_removal, {:array, :string}
|
||||
field :reject, {:array, :string}
|
||||
field :replace, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(schema, attrs) do
|
||||
schema
|
||||
|> cast(attrs, [:reject, :federated_timeline_removal, :replace])
|
||||
|> validate_required([:reject, :federated_timeline_removal, :replace])
|
||||
end
|
||||
end
|
|
@ -25,4 +25,5 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||
defp get_policies(policy) when is_atom(policy), do: [policy]
|
||||
defp get_policies(policies) when is_list(policies), do: policies
|
||||
defp get_policies(_), do: []
|
||||
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
defp string_matches?(string, pattern) when is_binary(pattern) do
|
||||
String.contains?(string, pattern)
|
||||
end
|
||||
|
@ -59,6 +60,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
|||
|> put_in(["object", "summary"], summary)}
|
||||
end
|
||||
|
||||
def save_keyword_policy(keyword_policy) do
|
||||
Pleroma.Config.put(:mrf_keyword, keyword_policy)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(%{"object" => %{"content" => nil}} = message) do
|
||||
{:ok, message}
|
||||
|
|
|
@ -183,6 +183,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
|> json(token.token)
|
||||
end
|
||||
|
||||
@doc "Add another MRF Keyword Policy rule"
|
||||
def add_keyword_policy(conn, %{"keyword_policy" => %{"pattern" => pattern, "replacement" => replacement}}) when is_binary(pattern) and
|
||||
is_binary(replacement) do
|
||||
|
||||
end
|
||||
|
||||
|
||||
def errors(conn, {:param_cast, _}) do
|
||||
conn
|
||||
|> put_status(400)
|
||||
|
|
|
@ -158,6 +158,10 @@ defmodule Pleroma.Web.Router do
|
|||
post("/email_invite", AdminAPIController, :email_invite)
|
||||
|
||||
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)
|
||||
get("/mrf/keyword_policy/list", AdminAPIController, :list_keyword_policy)
|
||||
end
|
||||
|
||||
scope "/", Pleroma.Web.TwitterAPI do
|
||||
|
|
Loading…
Reference in New Issue