[KeywordPolicy] Preliminary work

This commit is contained in:
Hécate 2019-02-10 01:33:41 +01:00
parent 7daa9a8c42
commit 2d9b5a0403
6 changed files with 53 additions and 10 deletions

View File

@ -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
),

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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)

View File

@ -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