alias Pleroma.Web.Feed.FeedView
def feed(conn, params) do
- unless Pleroma.Config.restrict_unauthenticated_access?(:activities, :local) do
+ unless Config.restrict_unauthenticated_access?(:activities, :local) do
render_feed(conn, params)
else
render_error(conn, :not_found, "Not found")
end
end
- def render_feed(conn, %{"tag" => raw_tag} = params) do
+ defp render_feed(conn, %{"tag" => raw_tag} = params) do
{format, tag} = parse_tag(raw_tag)
activities =
end
end
- def render_feed(conn, %{"nickname" => nickname} = params) do
+ defp render_feed(conn, %{"nickname" => nickname} = params) do
format = get_format(conn)
format =
- if format in ["rss", "atom"] do
+ if format in ["atom", "rss"] do
format
else
"atom"
plug(Pleroma.Plugs.StaticFEPlug)
end
+ pipeline :ostatus_no_html do
+ plug(:accepts, ["xml", "rss", "atom", "activity+json", "json"])
+ end
+
pipeline :oembed do
plug(:accepts, ["json", "xml"])
end
scope "/", Pleroma.Web do
- pipe_through([:ostatus, :http_signature])
+ # Note: no authentication plugs, all endpoints below should only yield public objects
+ pipe_through(:ostatus)
get("/objects/:uuid", OStatus.OStatusController, :object)
get("/activities/:uuid", OStatus.OStatusController, :activity)
get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
+ end
+
+ scope "/", Pleroma.Web do
+ pipe_through(:ostatus_no_html)
get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
end
plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
plug(:assign_id)
- plug(Pleroma.Plugs.EnsureAuthenticatedPlug,
- unless_func: &Pleroma.Web.FederatingPlug.federating?/1
- )
-
@page_keys ["max_id", "min_id", "limit", "since_id", "order"]
- defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
- do: name
-
- defp get_title(%Object{data: %{"summary" => summary}}) when is_binary(summary),
- do: summary
-
- defp get_title(_), do: nil
-
- defp not_found(conn, message) do
- conn
- |> put_status(404)
- |> render("error.html", %{message: message, meta: ""})
- end
-
- defp get_counts(%Activity{} = activity) do
- %Object{data: data} = Object.normalize(activity)
-
- %{
- likes: data["like_count"] || 0,
- replies: data["repliesCount"] || 0,
- announces: data["announcement_count"] || 0
- }
- end
-
- defp represent(%Activity{} = activity), do: represent(activity, false)
-
- defp represent(%Activity{object: %Object{data: data}} = activity, selected) do
- {:ok, user} = User.get_or_fetch(activity.object.data["actor"])
-
- link =
- case user.local do
- true -> Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
- _ -> data["url"] || data["external_url"] || data["id"]
- end
-
- content =
- if data["content"] do
- data["content"]
- |> Pleroma.HTML.filter_tags()
- |> Pleroma.Emoji.Formatter.emojify(Map.get(data, "emoji", %{}))
- else
- nil
- end
-
- %{
- user: User.sanitize_html(user),
- title: get_title(activity.object),
- content: content,
- attachment: data["attachment"],
- link: link,
- published: data["published"],
- sensitive: data["sensitive"],
- selected: selected,
- counts: get_counts(activity),
- id: activity.id
- }
- end
-
+ @doc "Renders requested local public activity"
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
with %Activity{local: true} = activity <-
Activity.get_by_id_with_object(notice_id),
end
end
+ @doc "Renders public activities of requested user"
def show(%{assigns: %{username_or_id: username_or_id}} = conn, params) do
case User.get_cached_by_nickname_or_id(username_or_id) do
%User{} = user ->
timeline =
user
- |> ActivityPub.fetch_user_activities(nil, params)
+ |> ActivityPub.fetch_user_activities(_reading_user = nil, params)
|> Enum.map(&represent/1)
prev_page_id =
end
end
+ defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
+ do: name
+
+ defp get_title(%Object{data: %{"summary" => summary}}) when is_binary(summary),
+ do: summary
+
+ defp get_title(_), do: nil
+
+ defp not_found(conn, message) do
+ conn
+ |> put_status(404)
+ |> render("error.html", %{message: message, meta: ""})
+ end
+
+ defp get_counts(%Activity{} = activity) do
+ %Object{data: data} = Object.normalize(activity)
+
+ %{
+ likes: data["like_count"] || 0,
+ replies: data["repliesCount"] || 0,
+ announces: data["announcement_count"] || 0
+ }
+ end
+
+ defp represent(%Activity{} = activity), do: represent(activity, false)
+
+ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do
+ {:ok, user} = User.get_or_fetch(activity.object.data["actor"])
+
+ link =
+ case user.local do
+ true -> Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
+ _ -> data["url"] || data["external_url"] || data["id"]
+ end
+
+ content =
+ if data["content"] do
+ data["content"]
+ |> Pleroma.HTML.filter_tags()
+ |> Pleroma.Emoji.Formatter.emojify(Map.get(data, "emoji", %{}))
+ else
+ nil
+ end
+
+ %{
+ user: User.sanitize_html(user),
+ title: get_title(activity.object),
+ content: content,
+ attachment: data["attachment"],
+ link: link,
+ published: data["published"],
+ sensitive: data["sensitive"],
+ selected: selected,
+ counts: get_counts(activity),
+ id: activity.id
+ }
+ end
+
defp assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
do: assign(conn, :notice_id, notice_id)
defp json_response_and_validate_schema(conn, _status) do
flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")
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)
-
- Config.put([:instance, :federating], false)
-
- conn
- |> get(url)
- |> response(403)
-
- conn
- |> assign(:user, user)
- |> get(url)
- |> response(200)
-
- Config.put([:instance, :federating], true)
-
- conn
- |> get(url)
- |> response(200)
- end
end
end
setup do: clear_config([:instance, :federating], true)
+ defp ensure_federating_or_authenticated(conn, url, user) do
+ Config.put([:instance, :federating], false)
+
+ conn
+ |> get(url)
+ |> response(403)
+
+ conn
+ |> assign(:user, user)
+ |> get(url)
+ |> response(200)
+
+ Config.put([:instance, :federating], true)
+
+ conn
+ |> get(url)
+ |> response(200)
+ end
+
describe "/relay" do
setup do: clear_config([:instance, :allow_relay])
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- setup do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:static_fe, :enabled], false)
describe "feed" do
setup do: clear_config([:feed])
|> get(user_feed_path(conn, :feed, user.nickname))
|> response(404)
end
+
+ test "does not require authentication on non-federating instances", %{conn: conn} do
+ clear_config([:instance, :federating], false)
+ user = insert(:user)
+
+ conn
+ |> put_req_header("accept", "application/rss+xml")
+ |> get("/users/#{user.nickname}/feed.rss")
+ |> response(200)
+ end
end
# Note: see ActivityPubControllerTest for JSON format tests
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
:ok
end
- setup do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:static_fe, :enabled], false)
describe "Mastodon compatibility routes" do
setup %{conn: conn} do
assert response(conn, 404)
end
- test "it requires authentication if instance is NOT federating", %{
+ test "does not require authentication on non-federating instances", %{
conn: conn
} do
- user = insert(:user)
+ clear_config([:instance, :federating], false)
note_activity = insert(:note_activity)
- conn = put_req_header(conn, "accept", "text/html")
-
- ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user)
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{note_activity.id}")
+ |> response(200)
end
end
|> response(404)
end
- test "it requires authentication if instance is NOT federating", %{
+ test "does not require authentication on non-federating instances", %{
conn: conn,
note_activity: note_activity
} do
- user = insert(:user)
- conn = put_req_header(conn, "accept", "text/html")
+ clear_config([:instance, :federating], false)
- ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user)
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(200)
end
end
end
use Pleroma.Web.ConnCase
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
setup_all do: clear_config([:static_fe, :enabled], true)
- setup do: clear_config([:instance, :federating], true)
setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
refute html =~ ">test29<"
end
- test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
- ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
+ test "does not require authentication on non-federating instances", %{
+ conn: conn,
+ user: user
+ } do
+ clear_config([:instance, :federating], false)
+
+ conn = get(conn, "/users/#{user.nickname}")
+
+ assert html_response(conn, 200) =~ user.nickname
end
end
assert html_response(conn, 302) =~ "redirected"
end
- test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
+ test "does not require authentication on non-federating instances", %{
+ conn: conn,
+ user: user
+ } do
+ clear_config([:instance, :federating], false)
+
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
- ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
+ conn = get(conn, "/notice/#{activity.id}")
+
+ assert html_response(conn, 200) =~ "testing a thing!"
end
end
end