Merge branch 'develop' into openapi/account
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 27 Apr 2020 10:33:00 +0000 (14:33 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 27 Apr 2020 10:33:00 +0000 (14:33 +0400)
1  2 
docs/API/differences_in_mastoapi_responses.md
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/api_spec/operations/app_operation.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/support/conn_case.ex

index fab67e784b030c18b43365e747db5c0dc207a17c,61a4960a0801501e66a70e7dbb3d69999c9f604a..1f4a093702053b1a82e5adc66328b5d4939db728
@@@ -1077,9 -1048,44 +1048,44 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      )
    end
  
+   defp restrict_replies(query, %{
+          "reply_filtering_user" => user,
+          "reply_visibility" => "self"
+        }) do
+     from(
+       [activity, object] in query,
+       where:
+         fragment(
+           "?->>'inReplyTo' is null OR ? = ANY(?)",
+           object.data,
+           ^user.ap_id,
+           activity.recipients
+         )
+     )
+   end
+   defp restrict_replies(query, %{
+          "reply_filtering_user" => user,
+          "reply_visibility" => "following"
+        }) do
+     from(
+       [activity, object] in query,
+       where:
+         fragment(
+           "?->>'inReplyTo' is null OR ? && array_remove(?, ?) OR ? = ?",
+           object.data,
+           ^[user.ap_id | User.get_cached_user_friends_ap_ids(user)],
+           activity.recipients,
+           activity.actor,
+           activity.actor,
+           ^user.ap_id
+         )
+     )
+   end
    defp restrict_replies(query, _), do: query
  
 -  defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do
 +  defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val in [true, "true", "1"] do
      from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
    end
  
index 36ce372c29f6394c31a50c5af0870f79375df4f3,78162247697cd546cf79d6bc7694ced847fb4b06..8099461cc3cdb6dc7f5096da614707fcc3b5a922
@@@ -51,11 -51,42 +51,47 @@@ defmodule Pleroma.Web.ConnCase d
          %{user: user, token: token, conn: conn}
        end
  
 +      defp request_content_type(%{conn: conn}) do
 +        conn = put_req_header(conn, "content-type", "multipart/form-data")
 +        [conn: conn]
 +      end
 +
+       defp json_response_and_validate_schema(conn, status \\ nil) do
+         content_type =
+           conn
+           |> Plug.Conn.get_resp_header("content-type")
+           |> List.first()
+           |> String.split(";")
+           |> List.first()
+         status = status || conn.status
+         %{private: %{open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}}} =
+           conn
+         schema = lookup[op_id].responses[status].content[content_type].schema
+         json = json_response(conn, status)
+         case OpenApiSpex.cast_value(json, schema, spec) do
+           {:ok, _data} ->
+             json
+           {:error, errors} ->
+             errors =
+               Enum.map(errors, fn error ->
+                 message = OpenApiSpex.Cast.Error.message(error)
+                 path = OpenApiSpex.Cast.Error.path_to_string(error)
+                 "#{message} at #{path}"
+               end)
+             flunk(
+               "Response does not conform to schema of #{op_id} operation: #{
+                 Enum.join(errors, "\n")
+               }\n#{inspect(json)}"
+             )
+         end
+       end
        defp ensure_federating_or_authenticated(conn, url, user) do
          initial_setting = Config.get([:instance, :federating])
          on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)