ActivityPub: Check inbox requests for valid signature.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub_controller.ex
1 defmodule Pleroma.Web.ActivityPub.ActivityPubController do
2 use Pleroma.Web, :controller
3 alias Pleroma.{User, Repo, Object}
4 alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
5 alias Pleroma.Web.ActivityPub.ActivityPub
6
7 def user(conn, %{"nickname" => nickname}) do
8 with %User{} = user <- User.get_cached_by_nickname(nickname),
9 {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
10 json(conn, UserView.render("user.json", %{user: user}))
11 end
12 end
13
14 def object(conn, %{"uuid" => uuid}) do
15 with ap_id <- o_status_url(conn, :object, uuid),
16 %Object{} = object <- Object.get_cached_by_ap_id(ap_id) do
17 json(conn, ObjectView.render("object.json", %{object: object}))
18 end
19 end
20
21 # TODO: Move signature failure halt into plug
22 def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
23 {:ok, activity} = ActivityPub.insert(params, false)
24 json(conn, "ok")
25 end
26 end