diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/bbs/handler.ex | 3 | ||||
| -rw-r--r-- | lib/pleroma/html.ex | 143 | ||||
| -rw-r--r-- | lib/pleroma/moderation_log.ex | 76 | ||||
| -rw-r--r-- | lib/pleroma/user.ex | 7 | ||||
| -rw-r--r-- | lib/pleroma/user/query.ex | 1 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 3 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/relay.ex | 6 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 1 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 46 | ||||
| -rw-r--r-- | lib/pleroma/web/admin_api/admin_api_controller.ex | 12 | ||||
| -rw-r--r-- | lib/pleroma/web/admin_api/report.ex | 5 | ||||
| -rw-r--r-- | lib/pleroma/web/rel_me.ex | 14 | ||||
| -rw-r--r-- | lib/pleroma/web/streamer/worker.ex | 2 | 
13 files changed, 229 insertions, 90 deletions
| diff --git a/lib/pleroma/bbs/handler.ex b/lib/pleroma/bbs/handler.ex index b0e9ebbd0..054d422b0 100644 --- a/lib/pleroma/bbs/handler.ex +++ b/lib/pleroma/bbs/handler.ex @@ -5,6 +5,7 @@  defmodule Pleroma.BBS.Handler do    use Sshd.ShellHandler    alias Pleroma.Activity +  alias Pleroma.HTML    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.CommonAPI @@ -44,7 +45,7 @@ defmodule Pleroma.BBS.Handler do    def puts_activity(activity) do      status = Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{activity: activity})      IO.puts("-- #{status.id} by #{status.account.display_name} (#{status.account.acct})") -    IO.puts(HtmlSanitizeEx.strip_tags(status.content)) +    IO.puts(HTML.strip_tags(status.content))      IO.puts("")    end diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 937bafed5..997e965f0 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -3,8 +3,6 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.HTML do -  alias HtmlSanitizeEx.Scrubber -    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] @@ -24,9 +22,13 @@ defmodule Pleroma.HTML do      end)    end -  def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber) +  def filter_tags(html, scrubber) do +    {:ok, content} = FastSanitize.Sanitizer.scrub(html, scrubber) +    content +  end +    def filter_tags(html), do: filter_tags(html, nil) -  def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags) +  def strip_tags(html), do: filter_tags(html, FastSanitize.Sanitizer.StripTags)    def get_cached_scrubbed_html_for_activity(          content, @@ -46,7 +48,7 @@ defmodule Pleroma.HTML do    def get_cached_stripped_html_for_activity(content, activity, key) do      get_cached_scrubbed_html_for_activity(        content, -      HtmlSanitizeEx.Scrubber.StripTags, +      FastSanitize.Sanitizer.StripTags,        activity,        key,        &HtmlEntities.decode/1 @@ -106,16 +108,15 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do    @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], []) -  require HtmlSanitizeEx.Scrubber.Meta -  alias HtmlSanitizeEx.Scrubber.Meta +  require FastSanitize.Sanitizer.Meta +  alias FastSanitize.Sanitizer.Meta -  Meta.remove_cdata_sections_before_scrub()    Meta.strip_comments()    # links -  Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) +  Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes) -  Meta.allow_tag_with_this_attribute_values("a", "class", [ +  Meta.allow_tag_with_this_attribute_values(:a, "class", [      "hashtag",      "u-url",      "mention", @@ -123,29 +124,29 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do      "mention u-url"    ]) -  Meta.allow_tag_with_this_attribute_values("a", "rel", [ +  Meta.allow_tag_with_this_attribute_values(:a, "rel", [      "tag",      "nofollow",      "noopener",      "noreferrer"    ]) -  Meta.allow_tag_with_these_attributes("a", ["name", "title"]) +  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", []) +  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", []) +  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_uri_attributes(:img, ["src"], ["http", "https"]) -    Meta.allow_tag_with_these_attributes("img", [ +    Meta.allow_tag_with_these_attributes(:img, [        "width",        "height",        "class", @@ -160,19 +161,18 @@ end  defmodule Pleroma.HTML.Scrubber.Default do    @doc "The default HTML scrubbing policy: no " -  require HtmlSanitizeEx.Scrubber.Meta -  alias HtmlSanitizeEx.Scrubber.Meta +  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.remove_cdata_sections_before_scrub()    Meta.strip_comments() -  Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) +  Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes) -  Meta.allow_tag_with_this_attribute_values("a", "class", [ +  Meta.allow_tag_with_this_attribute_values(:a, "class", [      "hashtag",      "u-url",      "mention", @@ -180,7 +180,7 @@ defmodule Pleroma.HTML.Scrubber.Default do      "mention u-url"    ]) -  Meta.allow_tag_with_this_attribute_values("a", "rel", [ +  Meta.allow_tag_with_this_attribute_values(:a, "rel", [      "tag",      "nofollow",      "noopener", @@ -188,37 +188,37 @@ defmodule Pleroma.HTML.Scrubber.Default do      "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", []) +  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_uri_attributes(:img, ["src"], ["http", "https"]) -    Meta.allow_tag_with_these_attributes("img", [ +    Meta.allow_tag_with_these_attributes(:img, [        "width",        "height",        "class", @@ -228,24 +228,24 @@ defmodule Pleroma.HTML.Scrubber.Default do    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", []) +    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", []) +    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"]) +    Meta.allow_tag_with_these_attributes(:font, ["face"])    end    Meta.strip_everything_not_covered() @@ -258,7 +258,7 @@ defmodule Pleroma.HTML.Transform.MediaProxy do    def before_scrub(html), do: html -  def scrub_attribute("img", {"src", "http" <> target}) do +  def scrub_attribute(:img, {"src", "http" <> target}) do      media_url =        ("http" <> target)        |> MediaProxy.url() @@ -268,16 +268,16 @@ defmodule Pleroma.HTML.Transform.MediaProxy do    def scrub_attribute(_tag, attribute), do: attribute -  def scrub({"img", attributes, children}) do +  def scrub({:img, attributes, children}) do      attributes =        attributes -      |> Enum.map(fn attr -> scrub_attribute("img", attr) end) +      |> Enum.map(fn attr -> scrub_attribute(:img, attr) end)        |> Enum.reject(&is_nil(&1)) -    {"img", attributes, children} +    {:img, attributes, children}    end -  def scrub({:comment, _children}), do: "" +  def scrub({:comment, _text, _children}), do: ""    def scrub({tag, attributes, children}), do: {tag, attributes, children}    def scrub({_tag, children}), do: children @@ -291,16 +291,15 @@ defmodule Pleroma.HTML.Scrubber.LinksOnly do    @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], []) -  require HtmlSanitizeEx.Scrubber.Meta -  alias HtmlSanitizeEx.Scrubber.Meta +  require FastSanitize.Sanitizer.Meta +  alias FastSanitize.Sanitizer.Meta -  Meta.remove_cdata_sections_before_scrub()    Meta.strip_comments()    # links -  Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) +  Meta.allow_tag_with_uri_attributes(:a, ["href"], @valid_schemes) -  Meta.allow_tag_with_this_attribute_values("a", "rel", [ +  Meta.allow_tag_with_this_attribute_values(:a, "rel", [      "tag",      "nofollow",      "noopener", @@ -309,6 +308,6 @@ defmodule Pleroma.HTML.Scrubber.LinksOnly do      "ugc"    ]) -  Meta.allow_tag_with_these_attributes("a", ["name", "title"]) +  Meta.allow_tag_with_these_attributes(:a, ["name", "title"])    Meta.strip_everything_not_covered()  end diff --git a/lib/pleroma/moderation_log.ex b/lib/pleroma/moderation_log.ex index e8884e6e8..9dc4a94c9 100644 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@ -374,6 +374,24 @@ defmodule Pleroma.ModerationLog do          data: %{            "actor" => %{"nickname" => actor_nickname},            "action" => "activate", +          "subject" => user +        } +      }) +      when is_map(user) do +    get_log_entry_message(%ModerationLog{ +      data: %{ +        "actor" => %{"nickname" => actor_nickname}, +        "action" => "activate", +        "subject" => [user] +      } +    }) +  end + +  @spec get_log_entry_message(ModerationLog) :: String.t() +  def get_log_entry_message(%ModerationLog{ +        data: %{ +          "actor" => %{"nickname" => actor_nickname}, +          "action" => "activate",            "subject" => users          }        }) do @@ -385,6 +403,24 @@ defmodule Pleroma.ModerationLog do          data: %{            "actor" => %{"nickname" => actor_nickname},            "action" => "deactivate", +          "subject" => user +        } +      }) +      when is_map(user) do +    get_log_entry_message(%ModerationLog{ +      data: %{ +        "actor" => %{"nickname" => actor_nickname}, +        "action" => "deactivate", +        "subject" => [user] +      } +    }) +  end + +  @spec get_log_entry_message(ModerationLog) :: String.t() +  def get_log_entry_message(%ModerationLog{ +        data: %{ +          "actor" => %{"nickname" => actor_nickname}, +          "action" => "deactivate",            "subject" => users          }        }) do @@ -424,6 +460,26 @@ defmodule Pleroma.ModerationLog do          data: %{            "actor" => %{"nickname" => actor_nickname},            "action" => "grant", +          "subject" => user, +          "permission" => permission +        } +      }) +      when is_map(user) do +    get_log_entry_message(%ModerationLog{ +      data: %{ +        "actor" => %{"nickname" => actor_nickname}, +        "action" => "grant", +        "subject" => [user], +        "permission" => permission +      } +    }) +  end + +  @spec get_log_entry_message(ModerationLog) :: String.t() +  def get_log_entry_message(%ModerationLog{ +        data: %{ +          "actor" => %{"nickname" => actor_nickname}, +          "action" => "grant",            "subject" => users,            "permission" => permission          } @@ -436,6 +492,26 @@ defmodule Pleroma.ModerationLog do          data: %{            "actor" => %{"nickname" => actor_nickname},            "action" => "revoke", +          "subject" => user, +          "permission" => permission +        } +      }) +      when is_map(user) do +    get_log_entry_message(%ModerationLog{ +      data: %{ +        "actor" => %{"nickname" => actor_nickname}, +        "action" => "revoke", +        "subject" => [user], +        "permission" => permission +      } +    }) +  end + +  @spec get_log_entry_message(ModerationLog) :: String.t() +  def get_log_entry_message(%ModerationLog{ +        data: %{ +          "actor" => %{"nickname" => actor_nickname}, +          "action" => "revoke",            "subject" => users,            "permission" => permission          } diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 40171620e..f8c2db1e1 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1095,7 +1095,12 @@ defmodule Pleroma.User do    def deactivate(%User{} = user, status) do      with {:ok, user} <- set_activation_status(user, status) do        Enum.each(get_followers(user), &invalidate_cache/1) -      Enum.each(get_friends(user), &update_follower_count/1) + +      # Only update local user counts, remote will be update during the next pull. +      user +      |> get_friends() +      |> Enum.filter(& &1.local) +      |> Enum.each(&update_follower_count/1)        {:ok, user}      end diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex index 2eda454bc..364bc1c89 100644 --- a/lib/pleroma/user/query.ex +++ b/lib/pleroma/user/query.ex @@ -175,6 +175,7 @@ defmodule Pleroma.User.Query do        [u, following: f, relationships: r],        u.ap_id in ^to or (f.follower_address in ^to and r.state == "accept")      ) +    |> distinct(true)    end    defp compose_query({:order_by, key}, query) do diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 093ee8fcd..51a9c6169 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -503,7 +503,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do      with flag_data <- make_flag_data(params, additional),           {:ok, activity} <- insert(flag_data, local), -         :ok <- maybe_federate(activity) do +         {:ok, stripped_activity} <- strip_report_status_data(activity), +         :ok <- maybe_federate(stripped_activity) do        Enum.each(User.all_superusers(), fn superuser ->          superuser          |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content) diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index f90d75a8a..fc2619680 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -11,13 +11,17 @@ defmodule Pleroma.Web.ActivityPub.Relay do    def get_actor do      actor = -      "#{Pleroma.Web.Endpoint.url()}/relay" +      relay_ap_id()        |> User.get_or_create_service_actor_by_ap_id()      {:ok, actor} = User.set_invisible(actor, true)      actor    end +  def relay_ap_id do +    "#{Pleroma.Web.Endpoint.url()}/relay" +  end +    @spec follow(String.t()) :: {:ok, Activity.t()} | {:error, any()}    def follow(target_instance) do      with %User{} = local_user <- get_actor(), diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 3c27b0d46..91a164eff 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -507,6 +507,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do            })          {:user_locked, true} -> +          {:ok, _relationship} = FollowingRelationship.update(follower, followed, "pending")            :noop        end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 699d5162f..d812fd734 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -12,6 +12,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do    alias Pleroma.User    alias Pleroma.Web    alias Pleroma.Web.ActivityPub.Visibility +  alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.Endpoint    alias Pleroma.Web.Router.Helpers @@ -21,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do    require Pleroma.Constants    @supported_object_types ["Article", "Note", "Video", "Page", "Question", "Answer", "Audio"] +  @strip_status_report_states ~w(closed resolved)    @supported_report_states ~w(open closed resolved)    @valid_visibilities ~w(public unlisted private direct) @@ -614,10 +616,24 @@ defmodule Pleroma.Web.ActivityPub.Utils do    defp build_flag_object(%{account: account, statuses: statuses} = _) do      [account.ap_id] ++ -      Enum.map(statuses || [], fn -        %Activity{} = act -> act.data["id"] -        act when is_map(act) -> act["id"] -        act when is_binary(act) -> act +      Enum.map(statuses || [], fn act -> +        id = +          case act do +            %Activity{} = act -> act.data["id"] +            act when is_map(act) -> act["id"] +            act when is_binary(act) -> act +          end + +        activity = Activity.get_by_ap_id_with_object(id) +        actor = User.get_by_ap_id(activity.object.data["actor"]) + +        %{ +          "type" => "Note", +          "id" => activity.data["id"], +          "content" => activity.object.data["content"], +          "published" => activity.object.data["published"], +          "actor" => AccountView.render("show.json", %{user: actor}) +        }        end)    end @@ -664,6 +680,20 @@ defmodule Pleroma.Web.ActivityPub.Utils do    #### Report-related helpers +  def update_report_state(%Activity{} = activity, state) +      when state in @strip_status_report_states do +    {:ok, stripped_activity} = strip_report_status_data(activity) + +    new_data = +      activity.data +      |> Map.put("state", state) +      |> Map.put("object", stripped_activity.data["object"]) + +    activity +    |> Changeset.change(data: new_data) +    |> Repo.update() +  end +    def update_report_state(%Activity{} = activity, state) when state in @supported_report_states do      new_data = Map.put(activity.data, "state", state) @@ -674,6 +704,14 @@ defmodule Pleroma.Web.ActivityPub.Utils do    def update_report_state(_, _), do: {:error, "Unsupported state"} +  def strip_report_status_data(activity) do +    [actor | reported_activities] = activity.data["object"] +    stripped_activities = Enum.map(reported_activities, & &1["id"]) +    new_data = put_in(activity.data, ["object"], [actor | stripped_activities]) + +    {:ok, %{activity | data: new_data}} +  end +    def update_activity_visibility(activity, visibility) when visibility in @valid_visibilities do      [to, cc, recipients] =        activity diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 7ffbb23e7..b47618bde 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -334,6 +334,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do      }      with {:ok, users, count} <- Search.user(Map.merge(search_params, filters)), +         {:ok, users, count} <- filter_relay_user(users, count),           do:             conn             |> json( @@ -345,6 +346,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do             )    end +  defp filter_relay_user(users, count) do +    filtered_users = Enum.reject(users, &relay_user?/1) +    count = if Enum.any?(users, &relay_user?/1), do: length(filtered_users), else: count + +    {:ok, filtered_users, count} +  end + +  defp relay_user?(user) do +    user.ap_id == Relay.relay_ap_id() +  end +    @filters ~w(local external active deactivated is_admin is_moderator)    @spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{} diff --git a/lib/pleroma/web/admin_api/report.ex b/lib/pleroma/web/admin_api/report.ex index c751dc2be..9c3468570 100644 --- a/lib/pleroma/web/admin_api/report.ex +++ b/lib/pleroma/web/admin_api/report.ex @@ -13,8 +13,9 @@ defmodule Pleroma.Web.AdminAPI.Report do      account = User.get_cached_by_ap_id(account_ap_id)      statuses = -      Enum.map(status_ap_ids, fn ap_id -> -        Activity.get_by_ap_id_with_object(ap_id) +      Enum.map(status_ap_ids, fn +        act when is_map(act) -> Activity.get_by_ap_id_with_object(act["id"]) +        act when is_binary(act) -> Activity.get_by_ap_id_with_object(act)        end)      %{report: report, user: user, account: account, statuses: statuses} diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex index d376e2069..16b1a53d2 100644 --- a/lib/pleroma/web/rel_me.ex +++ b/lib/pleroma/web/rel_me.ex @@ -25,13 +25,13 @@ defmodule Pleroma.Web.RelMe do    def parse(_), do: {:error, "No URL provided"}    defp parse_url(url) do -    {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options) - -    data = -      Floki.attribute(html, "link[rel~=me]", "href") ++ -        Floki.attribute(html, "a[rel~=me]", "href") - -    {:ok, data} +    with {:ok, %Tesla.Env{body: html, status: status}} when status in 200..299 <- +           Pleroma.HTTP.get(url, [], adapter: @hackney_options), +         data <- +           Floki.attribute(html, "link[rel~=me]", "href") ++ +             Floki.attribute(html, "a[rel~=me]", "href") do +      {:ok, data} +    end    rescue      e -> {:error, "Parsing error: #{inspect(e)}"}    end diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex index c2ee9e1f5..33b24840d 100644 --- a/lib/pleroma/web/streamer/worker.ex +++ b/lib/pleroma/web/streamer/worker.ex @@ -136,7 +136,7 @@ defmodule Pleroma.Web.Streamer.Worker do      recipients = MapSet.new(item.recipients)      domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks) -    with parent when not is_nil(parent) <- Object.normalize(item), +    with parent <- Object.normalize(item) || item,           true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),           true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)),           true <- MapSet.disjoint?(recipients, recipient_blocks), | 
