summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.formatter.exs2
-rw-r--r--CHANGELOG.md4
-rw-r--r--docs/API/pleroma_api.md1
-rw-r--r--lib/mix/tasks/pleroma/notification_settings.ex83
-rw-r--r--lib/mix/tasks/pleroma/user.ex6
-rw-r--r--lib/pleroma/application.ex1
-rw-r--r--lib/pleroma/html.ex232
-rw-r--r--lib/pleroma/notification.ex42
-rw-r--r--lib/pleroma/plugs/parsers_plug.ex21
-rw-r--r--lib/pleroma/user.ex26
-rw-r--r--lib/pleroma/user/notification_setting.ex40
-rw-r--r--lib/pleroma/web/endpoint.ex9
-rw-r--r--lib/pleroma/web/oauth/token/clean_worker.ex8
-rw-r--r--lib/pleroma/web/push/impl.ex27
-rw-r--r--lib/pleroma/workers/web_pusher_worker.ex2
-rw-r--r--priv/scrubbers/default.ex93
-rw-r--r--priv/scrubbers/links_only.ex27
-rw-r--r--priv/scrubbers/media_proxy.ex32
-rw-r--r--priv/scrubbers/twitter_text.ex57
-rw-r--r--test/notification_test.exs20
-rw-r--r--test/support/builders/user_builder.ex3
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/user/notification_setting_test.exs21
-rw-r--r--test/user_search_test.exs1
-rw-r--r--test/web/mastodon_api/controllers/notification_controller_test.exs194
-rw-r--r--test/web/mastodon_api/views/account_view_test.exs8
-rw-r--r--test/web/push/impl_test.exs47
-rw-r--r--test/web/twitter_api/util_controller_test.exs30
28 files changed, 699 insertions, 341 deletions
diff --git a/.formatter.exs b/.formatter.exs
index 7fa95a619..5799ac127 100644
--- a/.formatter.exs
+++ b/.formatter.exs
@@ -1,3 +1,3 @@
[
- inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}", "priv/repo/migrations/*.exs"]
+ inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}", "priv/repo/migrations/*.exs", "priv/scrubbers/*.ex"]
]
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d00097748..847dbe902 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Mark the direct conversation as read for the author when they send a new direct message
- Mastodon API, streaming: Add `pleroma.direct_conversation_id` to the `conversation` stream event payload.
- Admin API: Render whole status in grouped reports
+- Mastodon API: User timelines will now respect blocks, unless you are getting the user timeline of somebody you blocked (which would be empty otherwise).
</details>
### Added
@@ -48,6 +49,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mix task to list all users (`mix pleroma.user list`)
- Support for `X-Forwarded-For` and similar HTTP headers which used by reverse proxies to pass a real user IP address to the backend. Must not be enabled unless your instance is behind at least one reverse proxy (such as Nginx, Apache HTTPD or Varnish Cache).
- MRF: New module which handles incoming posts based on their age. By default, all incoming posts that are older than 2 days will be unlisted and not shown to their followers.
+- User notification settings: Add `privacy_option` option.
<details>
<summary>API Changes</summary>
@@ -82,6 +84,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Report emails now include functional links to profiles of remote user accounts
- Not being able to log in to some third-party apps when logged in to MastoFE
- MRF: `Delete` activities being exempt from MRF policies
+- OTP releases: Not being able to configure OAuth expired token cleanup interval
+- OTP releases: Not being able to configure HTML sanitization policy
<details>
<summary>API Changes</summary>
diff --git a/docs/API/pleroma_api.md b/docs/API/pleroma_api.md
index ad16d027e..7228d805b 100644
--- a/docs/API/pleroma_api.md
+++ b/docs/API/pleroma_api.md
@@ -302,6 +302,7 @@ See [Admin-API](admin_api.md)
* `follows`: BOOLEAN field, receives notifications from people the user follows
* `remote`: BOOLEAN field, receives notifications from people on remote instances
* `local`: BOOLEAN field, receives notifications from people on the local instance
+ * `privacy_option`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
* Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
## `/api/pleroma/healthcheck`
diff --git a/lib/mix/tasks/pleroma/notification_settings.ex b/lib/mix/tasks/pleroma/notification_settings.ex
new file mode 100644
index 000000000..7d65f0587
--- /dev/null
+++ b/lib/mix/tasks/pleroma/notification_settings.ex
@@ -0,0 +1,83 @@
+defmodule Mix.Tasks.Pleroma.NotificationSettings do
+ @shortdoc "Enable&Disable privacy option for push notifications"
+ @moduledoc """
+ Example:
+
+ > mix pleroma.notification_settings --privacy-option=false --nickname-users="parallel588" # set false only for parallel588 user
+ > mix pleroma.notification_settings --privacy-option=true # set true for all users
+
+ """
+
+ use Mix.Task
+ import Mix.Pleroma
+ import Ecto.Query
+
+ def run(args) do
+ start_pleroma()
+
+ {options, _, _} =
+ OptionParser.parse(
+ args,
+ strict: [
+ privacy_option: :boolean,
+ email_users: :string,
+ nickname_users: :string
+ ]
+ )
+
+ privacy_option = Keyword.get(options, :privacy_option)
+
+ if not is_nil(privacy_option) do
+ privacy_option
+ |> build_query(options)
+ |> Pleroma.Repo.update_all([])
+ end
+
+ shell_info("Done")
+ end
+
+ defp build_query(privacy_option, options) do
+ query =
+ from(u in Pleroma.User,
+ update: [
+ set: [
+ notification_settings:
+ fragment(
+ "jsonb_set(notification_settings, '{privacy_option}', ?)",
+ ^privacy_option
+ )
+ ]
+ ]
+ )
+
+ user_emails =
+ options
+ |> Keyword.get(:email_users, "")
+ |> String.split(",")
+ |> Enum.map(&String.trim(&1))
+ |> Enum.reject(&(&1 == ""))
+
+ query =
+ if length(user_emails) > 0 do
+ where(query, [u], u.email in ^user_emails)
+ else
+ query
+ end
+
+ user_nicknames =
+ options
+ |> Keyword.get(:nickname_users, "")
+ |> String.split(",")
+ |> Enum.map(&String.trim(&1))
+ |> Enum.reject(&(&1 == ""))
+
+ query =
+ if length(user_nicknames) > 0 do
+ where(query, [u], u.nickname in ^user_nicknames)
+ else
+ query
+ end
+
+ query
+ end
+end
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index bc8eacda8..0adb78fe3 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -373,9 +373,9 @@ defmodule Mix.Tasks.Pleroma.User do
users
|> Enum.each(fn user ->
shell_info(
- "#{user.nickname} moderator: #{user.info.is_moderator}, admin: #{user.info.is_admin}, locked: #{
- user.info.locked
- }, deactivated: #{user.info.deactivated}"
+ "#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
+ user.locked
+ }, deactivated: #{user.deactivated}"
)
end)
end)
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index 57462740c..5b844aa41 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -30,6 +30,7 @@ defmodule Pleroma.Application do
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
+ Pleroma.HTML.compile_scrubbers()
Pleroma.Config.DeprecationWarnings.warn()
setup_instrumenters()
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
index 71c53ce0e..2cae29f35 100644
--- a/lib/pleroma/html.ex
+++ b/lib/pleroma/html.ex
@@ -3,6 +3,25 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTML do
+ # Scrubbers are compiled on boot so they can be configured in OTP releases
+ # @on_load :compile_scrubbers
+
+ def compile_scrubbers do
+ dir = Path.join(:code.priv_dir(:pleroma), "scrubbers")
+
+ dir
+ |> File.ls!()
+ |> Enum.map(&Path.join(dir, &1))
+ |> Kernel.ParallelCompiler.compile()
+ |> case do
+ {:error, _errors, _warnings} ->
+ raise "Compiling scrubbers failed"
+
+ {:ok, _modules, _warnings} ->
+ :ok
+ end
+ end
+
defp get_scrubbers(scrubber) when is_atom(scrubber), do: [scrubber]
defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers
defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default]
@@ -99,216 +118,3 @@ defmodule Pleroma.HTML do
end)
end
end
-
-defmodule Pleroma.HTML.Scrubber.TwitterText do
- @moduledoc """
- An HTML scrubbing policy which limits to twitter-style text. Only
- paragraphs, breaks and links are allowed through the filter.
- """
-
- @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
-
- require FastSanitize.Sanitizer.Meta
- alias FastSanitize.Sanitizer.Meta
-
- Meta.strip_comments()
-
- # links
- Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
-
- Meta.allow_tag_with_this_attribute_values(:a, "class", [
- "hashtag",
- "u-url",
- "mention",
- "u-url mention",
- "mention u-url"
- ])
-
- Meta.allow_tag_with_this_attribute_values(:a, "rel", [
- "tag",
- "nofollow",
- "noopener",
- "noreferrer"
- ])
-
- Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
-
- # paragraphs and linebreaks
- Meta.allow_tag_with_these_attributes(:br, [])
- Meta.allow_tag_with_these_attributes(:p, [])
-
- # microformats
- Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
- Meta.allow_tag_with_these_attributes(:span, [])
-
- # allow inline images for custom emoji
- if Pleroma.Config.get([:markup, :allow_inline_images]) do
- # restrict img tags to http/https only, because of MediaProxy.
- Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
-
- Meta.allow_tag_with_these_attributes(:img, [
- "width",
- "height",
- "class",
- "title",
- "alt"
- ])
- end
-
- Meta.strip_everything_not_covered()
-end
-
-defmodule Pleroma.HTML.Scrubber.Default do
- @doc "The default HTML scrubbing policy: no "
-
- require FastSanitize.Sanitizer.Meta
- alias FastSanitize.Sanitizer.Meta
-
- # credo:disable-for-previous-line
- # No idea how to fix this one…
-
- @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
-
- Meta.strip_comments()
-
- Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
-
- Meta.allow_tag_with_this_attribute_values(:a, "class", [
- "hashtag",
- "u-url",
- "mention",
- "u-url mention",
- "mention u-url"
- ])
-
- Meta.allow_tag_with_this_attribute_values(:a, "rel", [
- "tag",
- "nofollow",
- "noopener",
- "noreferrer",
- "ugc"
- ])
-
- Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
-
- Meta.allow_tag_with_these_attributes(:abbr, ["title"])
-
- Meta.allow_tag_with_these_attributes(:b, [])
- Meta.allow_tag_with_these_attributes(:blockquote, [])
- Meta.allow_tag_with_these_attributes(:br, [])
- Meta.allow_tag_with_these_attributes(:code, [])
- Meta.allow_tag_with_these_attributes(:del, [])
- Meta.allow_tag_with_these_attributes(:em, [])
- Meta.allow_tag_with_these_attributes(:i, [])
- Meta.allow_tag_with_these_attributes(:li, [])
- Meta.allow_tag_with_these_attributes(:ol, [])
- Meta.allow_tag_with_these_attributes(:p, [])
- Meta.allow_tag_with_these_attributes(:pre, [])
- Meta.allow_tag_with_these_attributes(:strong, [])
- Meta.allow_tag_with_these_attributes(:sub, [])
- Meta.allow_tag_with_these_attributes(:sup, [])
- Meta.allow_tag_with_these_attributes(:u, [])
- Meta.allow_tag_with_these_attributes(:ul, [])
-
- Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
- Meta.allow_tag_with_these_attributes(:span, [])
-
- @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
-
- if @allow_inline_images do
- # restrict img tags to http/https only, because of MediaProxy.
- Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
-
- Meta.allow_tag_with_these_attributes(:img, [
- "width",
- "height",
- "class",
- "title",
- "alt"
- ])
- end
-
- if Pleroma.Config.get([:markup, :allow_tables]) do
- Meta.allow_tag_with_these_attributes(:table, [])
- Meta.allow_tag_with_these_attributes(:tbody, [])
- Meta.allow_tag_with_these_attributes(:td, [])
- Meta.allow_tag_with_these_attributes(:th, [])
- Meta.allow_tag_with_these_attributes(:thead, [])
- Meta.allow_tag_with_these_attributes(:tr, [])
- end
-
- if Pleroma.Config.get([:markup, :allow_headings]) do
- Meta.allow_tag_with_these_attributes(:h1, [])
- Meta.allow_tag_with_these_attributes(:h2, [])
- Meta.allow_tag_with_these_attributes(:h3, [])
- Meta.allow_tag_with_these_attributes(:h4, [])
- Meta.allow_tag_with_these_attributes(:h5, [])
- end
-
- if Pleroma.Config.get([:markup, :allow_fonts]) do
- Meta.allow_tag_with_these_attributes(:font, ["face"])
- end
-
- Meta.strip_everything_not_covered()
-end
-
-defmodule Pleroma.HTML.Transform.MediaProxy do
- @moduledoc "Transforms inline image URIs to use MediaProxy."
-
- alias Pleroma.Web.MediaProxy
-
- def before_scrub(html), do: html
-
- def scrub_attribute(:img, {"src", "http" <> target}) do
- media_url =
- ("http" <> target)
- |> MediaProxy.url()
-
- {"src", media_url}
- end
-
- def scrub_attribute(_tag, attribute), do: attribute
-
- def scrub({:img, attributes, children}) do
- attributes =
- attributes
- |> Enum.map(fn attr -> scrub_attribute(:img, attr) end)
- |> Enum.reject(&is_nil(&1))
-
- {:img, attributes, children}
- end
-
- def scrub({:comment, _text, _children}), do: ""
-
- def scrub({tag, attributes, children}), do: {tag, attributes, children}
- def scrub({_tag, children}), do: children
- def scrub(text), do: text
-end
-
-defmodule Pleroma.HTML.Scrubber.LinksOnly do
- @moduledoc """
- An HTML scrubbing policy which limits to links only.
- """
-
- @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
-
- require FastSanitize.Sanitizer.Meta
- alias FastSanitize.Sanitizer.Meta
-
- Meta.strip_comments()
-
- # links
- Meta.allow_tag_with_uri_attributes(:a, ["href"], @valid_schemes)
-
- Meta.allow_tag_with_this_attribute_values(:a, "rel", [
- "tag",
- "nofollow",
- "noopener",
- "noreferrer",
- "me",
- "ugc"
- ])
-
- Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
- Meta.strip_everything_not_covered()
-end
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 71423ce5e..8f3e46af9 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -121,10 +121,28 @@ defmodule Pleroma.Notification do
when is_list(visibility) do
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
query
+ |> join(:left, [n, a], mutated_activity in Pleroma.Activity,
+ on:
+ fragment("?->>'context'", a.data) ==
+ fragment("?->>'context'", mutated_activity.data) and
+ fragment("(?->>'type' = 'Like' or ?->>'type' = 'Announce')", a.data, a.data) and
+ fragment("?->>'type'", mutated_activity.data) == "Create",
+ as: :mutated_activity
+ )
|> where(
- [n, a],
+ [n, a, mutated_activity: mutated_activity],
not fragment(
- "activity_visibility(?, ?, ?) = ANY (?)",
+ """
+ CASE WHEN (?->>'type') = 'Like' or (?->>'type') = 'Announce'
+ THEN (activity_visibility(?, ?, ?) = ANY (?))
+ ELSE (activity_visibility(?, ?, ?) = ANY (?)) END
+ """,
+ a.data,
+ a.data,
+ mutated_activity.actor,
+ mutated_activity.recipients,
+ mutated_activity.data,
+ ^visibility,
a.actor,
a.recipients,
a.data,
@@ -139,17 +157,7 @@ defmodule Pleroma.Notification do
defp exclude_visibility(query, %{exclude_visibilities: visibility})
when visibility in @valid_visibilities do
- query
- |> where(
- [n, a],
- not fragment(
- "activity_visibility(?, ?, ?) = (?)",
- a.actor,
- a.recipients,
- a.data,
- ^visibility
- )
- )
+ exclude_visibility(query, [visibility])
end
defp exclude_visibility(query, %{exclude_visibilities: visibility})
@@ -347,7 +355,7 @@ defmodule Pleroma.Notification do
def skip?(
:followers,
activity,
- %{notification_settings: %{"followers" => false}} = user
+ %{notification_settings: %{followers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
@@ -357,14 +365,14 @@ defmodule Pleroma.Notification do
def skip?(
:non_followers,
activity,
- %{notification_settings: %{"non_followers" => false}} = user
+ %{notification_settings: %{non_followers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
!User.following?(follower, user)
end
- def skip?(:follows, activity, %{notification_settings: %{"follows" => false}} = user) do
+ def skip?(:follows, activity, %{notification_settings: %{follows: false}} = user) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
@@ -373,7 +381,7 @@ defmodule Pleroma.Notification do
def skip?(
:non_follows,
activity,
- %{notification_settings: %{"non_follows" => false}} = user
+ %{notification_settings: %{non_follows: false}} = user
) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
diff --git a/lib/pleroma/plugs/parsers_plug.ex b/lib/pleroma/plugs/parsers_plug.ex
new file mode 100644
index 000000000..2e493ce0e
--- /dev/null
+++ b/lib/pleroma/plugs/parsers_plug.ex
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.Parsers do
+ @moduledoc "Initializes Plug.Parsers with upload limit set at boot time"
+
+ @behaviour Plug
+
+ def init(_opts) do
+ Plug.Parsers.init(
+ parsers: [:urlencoded, :multipart, :json],
+ pass: ["*/*"],
+ json_decoder: Jason,
+ length: Pleroma.Config.get([:instance, :upload_limit]),
+ body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
+ )
+ end
+
+ defdelegate call(conn, opts), to: Plug.Parsers
+end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index b7f50e5ac..e2afc6de8 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -129,13 +129,10 @@ defmodule Pleroma.User do
field(:skip_thread_containment, :boolean, default: false)
field(:also_known_as, {:array, :string}, default: [])
- field(:notification_settings, :map,
- default: %{
- "followers" => true,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
- }
+ embeds_one(
+ :notification_settings,
+ Pleroma.User.NotificationSetting,
+ on_replace: :update
)
has_many(:notifications, Notification)
@@ -1221,20 +1218,9 @@ defmodule Pleroma.User do
end
def update_notification_settings(%User{} = user, settings) do
- settings =
- settings
- |> Enum.map(fn {k, v} -> {k, v in [true, "true", "True", "1"]} end)
- |> Map.new()
-
- notification_settings =
- user.notification_settings
- |> Map.merge(settings)
- |> Map.take(["followers", "follows", "non_follows", "non_followers"])
-
- params = %{notification_settings: notification_settings}
-
user
- |> cast(params, [:notification_settings])
+ |> cast(%{notification_settings: settings}, [])
+ |> cast_embed(:notification_settings)
|> validate_required([:notification_settings])
|> update_and_set_cache()
end
diff --git a/lib/pleroma/user/notification_setting.ex b/lib/pleroma/user/notification_setting.ex
new file mode 100644
index 000000000..f0899613e
--- /dev/null
+++ b/lib/pleroma/user/notification_setting.ex
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.User.NotificationSetting do
+ use Ecto.Schema
+ import Ecto.Changeset
+
+ @derive Jason.Encoder
+ @primary_key false
+
+ embedded_schema do
+ field(:followers, :boolean, default: true)
+ field(:follows, :boolean, default: true)
+ field(:non_follows, :boolean, default: true)
+ field(:non_followers, :boolean, default: true)
+ field(:privacy_option, :boolean, default: false)
+ end
+
+ def changeset(schema, params) do
+ schema
+ |> cast(prepare_attrs(params), [
+ :followers,
+ :follows,
+ :non_follows,
+ :non_followers,
+ :privacy_option
+ ])
+ end
+
+ defp prepare_attrs(params) do
+ Enum.reduce(params, %{}, fn
+ {k, v}, acc when is_binary(v) ->
+ Map.put(acc, k, String.downcase(v))
+
+ {k, v}, acc ->
+ Map.put(acc, k, v)
+ end)
+ end
+end
diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex
index 49735b5c2..bbea31682 100644
--- a/lib/pleroma/web/endpoint.ex
+++ b/lib/pleroma/web/endpoint.ex
@@ -61,14 +61,7 @@ defmodule Pleroma.Web.Endpoint do
plug(Plug.RequestId)
plug(Plug.Logger)
- plug(
- Plug.Parsers,
- parsers: [:urlencoded, :multipart, :json],
- pass: ["*/*"],
- json_decoder: Jason,
- length: Pleroma.Config.get([:instance, :upload_limit]),
- body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
- )
+ plug(Pleroma.Plugs.Parsers)
plug(Plug.MethodOverride)
plug(Plug.Head)
diff --git a/lib/pleroma/web/oauth/token/clean_worker.ex b/lib/pleroma/web/oauth/token/clean_worker.ex
index f639f9c6f..3c9c580d5 100644
--- a/lib/pleroma/web/oauth/token/clean_worker.ex
+++ b/lib/pleroma/web/oauth/token/clean_worker.ex
@@ -11,11 +11,6 @@ defmodule Pleroma.Web.OAuth.Token.CleanWorker do
@ten_seconds 10_000
@one_day 86_400_000
- @interval Pleroma.Config.get(
- [:oauth2, :clean_expired_tokens_interval],
- @one_day
- )
-
alias Pleroma.Web.OAuth.Token
alias Pleroma.Workers.BackgroundWorker
@@ -29,8 +24,9 @@ defmodule Pleroma.Web.OAuth.Token.CleanWorker do
@doc false
def handle_info(:perform, state) do
BackgroundWorker.enqueue("clean_expired_tokens", %{})
+ interval = Pleroma.Config.get([:oauth2, :clean_expired_tokens_interval], @one_day)
- Process.send_after(self(), :perform, @interval)
+ Process.send_after(self(), :perform, interval)
{:noreply, state}
end
diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex
index a6a924d02..34ec1d8d9 100644
--- a/lib/pleroma/web/push/impl.ex
+++ b/lib/pleroma/web/push/impl.ex
@@ -22,8 +22,8 @@ defmodule Pleroma.Web.Push.Impl do
@spec perform(Notification.t()) :: list(any) | :error
def perform(
%{
- activity: %{data: %{"type" => activity_type}, id: activity_id} = activity,
- user_id: user_id
+ activity: %{data: %{"type" => activity_type}} = activity,
+ user: %User{id: user_id}
} = notif
)
when activity_type in @types do
@@ -39,18 +39,17 @@ defmodule Pleroma.Web.Push.Impl do
for subscription <- fetch_subsriptions(user_id),
get_in(subscription.data, ["alerts", type]) do
%{
- title: format_title(notif),
access_token: subscription.token.token,
- body: format_body(notif, actor, object),
notification_id: notif.id,
notification_type: type,
icon: avatar_url,
preferred_locale: "en",
pleroma: %{
- activity_id: activity_id,
+ activity_id: notif.activity.id,
direct_conversation_id: direct_conversation_id
}
}
+ |> Map.merge(build_content(notif, actor, object))
|> Jason.encode!()
|> push_message(build_sub(subscription), gcm_api_key, subscription)
end
@@ -100,6 +99,24 @@ defmodule Pleroma.Web.Push.Impl do
}
end
+ def build_content(
+ %{
+ activity: %{data: %{"directMessage" => true}},
+ user: %{notification_settings: %{privacy_option: true}}
+ },
+ actor,
+ _
+ ) do
+ %{title: "New Direct Message", body: "@#{actor.nickname}"}
+ end
+
+ def build_content(notif, actor, object) do
+ %{
+ title: format_title(notif),
+ body: format_body(notif, actor, object)
+ }
+ end
+
def format_body(
%{activity: %{data: %{"type" => "Create"}}},
actor,
diff --git a/lib/pleroma/workers/web_pusher_worker.ex b/lib/pleroma/workers/web_pusher_worker.ex
index 61b451e3e..a978c4013 100644
--- a/lib/pleroma/workers/web_pusher_worker.ex
+++ b/lib/pleroma/workers/web_pusher_worker.ex
@@ -13,7 +13,7 @@ defmodule Pleroma.Workers.WebPusherWorker do
notification =
Notification
|> Repo.get(notification_id)
- |> Repo.preload([:activity])
+ |> Repo.preload([:activity, :user])
Pleroma.Web.Push.Impl.perform(notification)
end
diff --git a/priv/scrubbers/default.ex b/priv/scrubbers/default.ex
new file mode 100644
index 000000000..ea0480dcd
--- /dev/null
+++ b/priv/scrubbers/default.ex
@@ -0,0 +1,93 @@
+defmodule Pleroma.HTML.Scrubber.Default do
+ @doc "The default HTML scrubbing policy: no "
+
+ require FastSanitize.Sanitizer.Meta
+ alias FastSanitize.Sanitizer.Meta
+
+ # credo:disable-for-previous-line
+ # No idea how to fix this one…
+
+ @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
+
+ Meta.strip_comments()
+
+ Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
+
+ Meta.allow_tag_with_this_attribute_values(:a, "class", [
+ "hashtag",
+ "u-url",
+ "mention",
+ "u-url mention",
+ "mention u-url"
+ ])
+
+ Meta.allow_tag_with_this_attribute_values(:a, "rel", [
+ "tag",
+ "nofollow",
+ "noopener",
+ "noreferrer",
+ "ugc"
+ ])
+
+ Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
+
+ Meta.allow_tag_with_these_attributes(:abbr, ["title"])
+
+ Meta.allow_tag_with_these_attributes(:b, [])
+ Meta.allow_tag_with_these_attributes(:blockquote, [])
+ Meta.allow_tag_with_these_attributes(:br, [])
+ Meta.allow_tag_with_these_attributes(:code, [])
+ Meta.allow_tag_with_these_attributes(:del, [])
+ Meta.allow_tag_with_these_attributes(:em, [])
+ Meta.allow_tag_with_these_attributes(:i, [])
+ Meta.allow_tag_with_these_attributes(:li, [])
+ Meta.allow_tag_with_these_attributes(:ol, [])
+ Meta.allow_tag_with_these_attributes(:p, [])
+ Meta.allow_tag_with_these_attributes(:pre, [])
+ Meta.allow_tag_with_these_attributes(:strong, [])
+ Meta.allow_tag_with_these_attributes(:sub, [])
+ Meta.allow_tag_with_these_attributes(:sup, [])
+ Meta.allow_tag_with_these_attributes(:u, [])
+ Meta.allow_tag_with_these_attributes(:ul, [])
+
+ Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
+ Meta.allow_tag_with_these_attributes(:span, [])
+
+ @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
+
+ if @allow_inline_images do
+ # restrict img tags to http/https only, because of MediaProxy.
+ Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
+
+ Meta.allow_tag_with_these_attributes(:img, [
+ "width",
+ "height",
+ "class",
+ "title",
+ "alt"
+ ])
+ end
+
+ if Pleroma.Config.get([:markup, :allow_tables]) do
+ Meta.allow_tag_with_these_attributes(:table, [])
+ Meta.allow_tag_with_these_attributes(:tbody, [])
+ Meta.allow_tag_with_these_attributes(:td, [])
+ Meta.allow_tag_with_these_attributes(:th, [])
+ Meta.allow_tag_with_these_attributes(:thead, [])
+ Meta.allow_tag_with_these_attributes(:tr, [])
+ end
+
+ if Pleroma.Config.get([:markup, :allow_headings]) do
+ Meta.allow_tag_with_these_attributes(:h1, [])
+ Meta.allow_tag_with_these_attributes(:h2, [])
+ Meta.allow_tag_with_these_attributes(:h3, [])
+ Meta.allow_tag_with_these_attributes(:h4, [])
+ Meta.allow_tag_with_these_attributes(:h5, [])
+ end
+
+ if Pleroma.Config.get([:markup, :allow_fonts]) do
+ Meta.allow_tag_with_these_attributes(:font, ["face"])
+ end
+
+ Meta.strip_everything_not_covered()
+end
diff --git a/priv/scrubbers/links_only.ex b/priv/scrubbers/links_only.ex
new file mode 100644
index 000000000..b30a00589
--- /dev/null
+++ b/priv/scrubbers/links_only.ex
@@ -0,0 +1,27 @@
+defmodule Pleroma.HTML.Scrubber.LinksOnly do
+ @moduledoc """
+ An HTML scrubbing policy which limits to links only.
+ """
+
+ @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
+
+ require FastSanitize.Sanitizer.Meta
+ alias FastSanitize.Sanitizer.Meta
+
+ Meta.strip_comments()
+
+ # links
+ Meta.allow_tag_with_uri_attributes(:a, ["href"], @valid_schemes)
+
+ Meta.allow_tag_with_this_attribute_values(:a, "rel", [
+ "tag",
+ "nofollow",
+ "noopener",
+ "noreferrer",
+ "me",
+ "ugc"
+ ])
+
+ Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
+ Meta.strip_everything_not_covered()
+end
diff --git a/priv/scrubbers/media_proxy.ex b/priv/scrubbers/media_proxy.ex
new file mode 100644
index 000000000..5dbe57666
--- /dev/null
+++ b/priv/scrubbers/media_proxy.ex
@@ -0,0 +1,32 @@
+defmodule Pleroma.HTML.Transform.MediaProxy do
+ @moduledoc "Transforms inline image URIs to use MediaProxy."
+
+ alias Pleroma.Web.MediaProxy
+
+ def before_scrub(html), do: html
+
+ def scrub_attribute(:img, {"src", "http" <> target}) do
+ media_url =
+ ("http" <> target)
+ |> MediaProxy.url()
+
+ {"src", media_url}
+ end
+
+ def scrub_attribute(_tag, attribute), do: attribute
+
+ def scrub({:img, attributes, children}) do
+ attributes =
+ attributes
+ |> Enum.map(fn attr -> scrub_attribute(:img, attr) end)
+ |> Enum.reject(&is_nil(&1))
+
+ {:img, attributes, children}
+ end
+
+ def scrub({:comment, _text, _children}), do: ""
+
+ def scrub({tag, attributes, children}), do: {tag, attributes, children}
+ def scrub({_tag, children}), do: children
+ def scrub(text), do: text
+end
diff --git a/priv/scrubbers/twitter_text.ex b/priv/scrubbers/twitter_text.ex
new file mode 100644
index 000000000..c4e796cad
--- /dev/null
+++ b/priv/scrubbers/twitter_text.ex
@@ -0,0 +1,57 @@
+defmodule Pleroma.HTML.Scrubber.TwitterText do
+ @moduledoc """
+ An HTML scrubbing policy which limits to twitter-style text. Only
+ paragraphs, breaks and links are allowed through the filter.
+ """
+
+ @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
+
+ require FastSanitize.Sanitizer.Meta
+ alias FastSanitize.Sanitizer.Meta
+
+ Meta.strip_comments()
+
+ # links
+ Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
+
+ Meta.allow_tag_with_this_attribute_values(:a, "class", [
+ "hashtag",
+ "u-url",
+ "mention",
+ "u-url mention",
+ "mention u-url"
+ ])
+
+ Meta.allow_tag_with_this_attribute_values(:a, "rel", [
+ "tag",
+ "nofollow",
+ "noopener",
+ "noreferrer"
+ ])
+
+ Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
+
+ # paragraphs and linebreaks
+ Meta.allow_tag_with_these_attributes(:br, [])
+ Meta.allow_tag_with_these_attributes(:p, [])
+
+ # microformats
+ Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
+ Meta.allow_tag_with_these_attributes(:span, [])
+
+ # allow inline images for custom emoji
+ if Pleroma.Config.get([:markup, :allow_inline_images]) do
+ # restrict img tags to http/https only, because of MediaProxy.
+ Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
+
+ Meta.allow_tag_with_these_attributes(:img, [
+ "width",
+ "height",
+ "class",
+ "title",
+ "alt"
+ ])
+ end
+
+ Meta.strip_everything_not_covered()
+end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 827ac4f06..ffa3d4b8c 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -136,7 +136,10 @@ defmodule Pleroma.NotificationTest do
test "it disables notifications from followers" do
follower = insert(:user)
- followed = insert(:user, notification_settings: %{"followers" => false})
+
+ followed =
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
+
User.follow(follower, followed)
{:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
@@ -144,13 +147,20 @@ defmodule Pleroma.NotificationTest do
test "it disables notifications from non-followers" do
follower = insert(:user)
- followed = insert(:user, notification_settings: %{"non_followers" => false})
+
+ followed =
+ insert(:user,
+ notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
+ )
+
{:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
end
test "it disables notifications from people the user follows" do
- follower = insert(:user, notification_settings: %{"follows" => false})
+ follower =
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
+
followed = insert(:user)
User.follow(follower, followed)
follower = Repo.get(User, follower.id)
@@ -159,7 +169,9 @@ defmodule Pleroma.NotificationTest do
end
test "it disables notifications from people the user does not follow" do
- follower = insert(:user, notification_settings: %{"non_follows" => false})
+ follower =
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
+
followed = insert(:user)
{:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
refute Notification.create_notification(activity, follower)
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 6da16f71a..fcfea666f 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -10,7 +10,8 @@ defmodule Pleroma.Builders.UserBuilder do
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: "A tester.",
ap_id: "some id",
- last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
+ last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
+ notification_settings: %Pleroma.User.NotificationSetting{}
}
Map.merge(user, data)
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 35ba523a1..314f26ec9 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -31,7 +31,8 @@ defmodule Pleroma.Factory do
nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"),
- last_digest_emailed_at: NaiveDateTime.utc_now()
+ last_digest_emailed_at: NaiveDateTime.utc_now(),
+ notification_settings: %Pleroma.User.NotificationSetting{}
}
%{
diff --git a/test/user/notification_setting_test.exs b/test/user/notification_setting_test.exs
new file mode 100644
index 000000000..4744d7b4a
--- /dev/null
+++ b/test/user/notification_setting_test.exs
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.User.NotificationSettingTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.User.NotificationSetting
+
+ describe "changeset/2" do
+ test "sets valid privacy option" do
+ changeset =
+ NotificationSetting.changeset(
+ %NotificationSetting{},
+ %{"privacy_option" => true}
+ )
+
+ assert %Ecto.Changeset{valid?: true} = changeset
+ end
+ end
+end
diff --git a/test/user_search_test.exs b/test/user_search_test.exs
index 98841dbbd..821858476 100644
--- a/test/user_search_test.exs
+++ b/test/user_search_test.exs
@@ -174,6 +174,7 @@ defmodule Pleroma.UserSearchTest do
|> Map.put(:search_rank, nil)
|> Map.put(:search_type, nil)
|> Map.put(:last_digest_emailed_at, nil)
+ |> Map.put(:notification_settings, nil)
assert user == expected
end
diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs
index f6d4ab9f0..6635ea7a2 100644
--- a/test/web/mastodon_api/controllers/notification_controller_test.exs
+++ b/test/web/mastodon_api/controllers/notification_controller_test.exs
@@ -137,55 +137,151 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
end
- test "filters notifications using exclude_visibilities", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, public_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "public"})
-
- {:ok, direct_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
-
- {:ok, unlisted_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "unlisted"})
-
- {:ok, private_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
-
- conn = assign(conn, :user, user)
-
- conn_res =
- get(conn, "/api/v1/notifications", %{
- exclude_visibilities: ["public", "unlisted", "private"]
- })
-
- assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
- assert id == direct_activity.id
-
- conn_res =
- get(conn, "/api/v1/notifications", %{
- exclude_visibilities: ["public", "unlisted", "direct"]
- })
-
- assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
- assert id == private_activity.id
-
- conn_res =
- get(conn, "/api/v1/notifications", %{
- exclude_visibilities: ["public", "private", "direct"]
- })
-
- assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
- assert id == unlisted_activity.id
-
- conn_res =
- get(conn, "/api/v1/notifications", %{
- exclude_visibilities: ["unlisted", "private", "direct"]
- })
-
- assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
- assert id == public_activity.id
+ describe "exclude_visibilities" do
+ test "filters notifications for mentions", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, public_activity} =
+ CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "public"})
+
+ {:ok, direct_activity} =
+ CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
+
+ {:ok, unlisted_activity} =
+ CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "unlisted"})
+
+ {:ok, private_activity} =
+ CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
+
+ conn = assign(conn, :user, user)
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{
+ exclude_visibilities: ["public", "unlisted", "private"]
+ })
+
+ assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
+ assert id == direct_activity.id
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{
+ exclude_visibilities: ["public", "unlisted", "direct"]
+ })
+
+ assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
+ assert id == private_activity.id
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{
+ exclude_visibilities: ["public", "private", "direct"]
+ })
+
+ assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
+ assert id == unlisted_activity.id
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{
+ exclude_visibilities: ["unlisted", "private", "direct"]
+ })
+
+ assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
+ assert id == public_activity.id
+ end
+
+ test "filters notifications for Like activities", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, public_activity} =
+ CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
+
+ {:ok, direct_activity} =
+ CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
+
+ {:ok, unlisted_activity} =
+ CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
+
+ {:ok, private_activity} =
+ CommonAPI.post(other_user, %{"status" => ".", "visibility" => "private"})
+
+ {:ok, _, _} = CommonAPI.favorite(public_activity.id, user)
+ {:ok, _, _} = CommonAPI.favorite(direct_activity.id, user)
+ {:ok, _, _} = CommonAPI.favorite(unlisted_activity.id, user)
+ {:ok, _, _} = CommonAPI.favorite(private_activity.id, user)
+
+ activity_ids =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/notifications", %{exclude_visibilities: ["direct"]})
+ |> json_response(200)
+ |> Enum.map(& &1["status"]["id"])
+
+ assert public_activity.id in activity_ids
+ assert unlisted_activity.id in activity_ids
+ assert private_activity.id in activity_ids
+ refute direct_activity.id in activity_ids
+
+ activity_ids =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
+ |> json_response(200)
+ |> Enum.map(& &1["status"]["id"])
+
+ assert public_activity.id in activity_ids
+ refute unlisted_activity.id in activity_ids
+ assert private_activity.id in activity_ids
+ assert direct_activity.id in activity_ids
+
+ activity_ids =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/notifications", %{exclude_visibilities: ["private"]})
+ |> json_response(200)
+ |> Enum.map(& &1["status"]["id"])
+
+ assert public_activity.id in activity_ids
+ assert unlisted_activity.id in activity_ids
+ refute private_activity.id in activity_ids
+ assert direct_activity.id in activity_ids
+
+ activity_ids =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/notifications", %{exclude_visibilities: ["public"]})
+ |> json_response(200)
+ |> Enum.map(& &1["status"]["id"])
+
+ refute public_activity.id in activity_ids
+ assert unlisted_activity.id in activity_ids
+ assert private_activity.id in activity_ids
+ assert direct_activity.id in activity_ids
+ end
+
+ test "filters notifications for Announce activities", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, public_activity} =
+ CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
+
+ {:ok, unlisted_activity} =
+ CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
+
+ {:ok, _, _} = CommonAPI.repeat(public_activity.id, user)
+ {:ok, _, _} = CommonAPI.repeat(unlisted_activity.id, user)
+
+ activity_ids =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
+ |> json_response(200)
+ |> Enum.map(& &1["status"]["id"])
+
+ assert public_activity.id in activity_ids
+ refute unlisted_activity.id in activity_ids
+ end
end
test "filters notifications using exclude_types", %{conn: conn} do
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index ed6f2ecbd..5e297d129 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -92,13 +92,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "Represent the user account for the account owner" do
user = insert(:user)
- notification_settings = %{
- "followers" => true,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
- }
-
+ notification_settings = %Pleroma.User.NotificationSetting{}
privacy = user.default_scope
assert %{
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 9b554601d..acae7a734 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
alias Pleroma.Object
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
@@ -182,4 +183,50 @@ defmodule Pleroma.Web.Push.ImplTest do
assert Impl.format_title(%{activity: activity}) ==
"New Direct Message"
end
+
+ describe "build_content/3" do
+ test "returns info content for direct message with enabled privacy option" do
+ user = insert(:user, nickname: "Bob")
+ user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "status" => "<Lorem ipsum dolor sit amet."
+ })
+
+ notif = insert(:notification, user: user2, activity: activity)
+
+ actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
+ object = Object.normalize(activity)
+
+ assert Impl.build_content(notif, actor, object) == %{
+ body: "@Bob",
+ title: "New Direct Message"
+ }
+ end
+
+ test "returns regular content for direct message with disabled privacy option" do
+ user = insert(:user, nickname: "Bob")
+ user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "status" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ notif = insert(:notification, user: user2, activity: activity)
+
+ actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
+ object = Object.normalize(activity)
+
+ assert Impl.build_content(notif, actor, object) == %{
+ body:
+ "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini...",
+ title: "New Direct Message"
+ }
+ end
+ end
end
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 986ee01f3..734cd2211 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -159,11 +159,31 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = Repo.get(User, user.id)
- assert %{
- "followers" => false,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
+ assert %Pleroma.User.NotificationSetting{
+ followers: false,
+ follows: true,
+ non_follows: true,
+ non_followers: true,
+ privacy_option: false
+ } == user.notification_settings
+ end
+
+ test "it update notificatin privacy option", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
+ |> json_response(:ok)
+
+ user = refresh_record(user)
+
+ assert %Pleroma.User.NotificationSetting{
+ followers: true,
+ follows: true,
+ non_follows: true,
+ non_followers: true,
+ privacy_option: true
} == user.notification_settings
end
end