@@ -4,6 +4,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
alias Mobilizon.Events.{Event, Comment}
|
||||
alias MobilizonWeb.ActivityPub.{ObjectView, ActorView}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Service.Federator
|
||||
|
||||
require Logger
|
||||
@@ -46,7 +47,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
true <- event.public do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ObjectView.render("event.json", %{event: event}))
|
||||
|> json(ObjectView.render("event.json", %{event: event |> Utils.make_event_data()}))
|
||||
else
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
@@ -60,7 +61,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
# true <- comment.public do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ObjectView.render("comment.json", %{comment: comment}))
|
||||
|> json(ObjectView.render("comment.json", %{comment: comment |> Utils.make_comment_data()}))
|
||||
else
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
@@ -137,11 +138,11 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
headers = Enum.into(conn.req_headers, %{})
|
||||
|
||||
if String.contains?(headers["signature"], params["actor"]) do
|
||||
Logger.info(
|
||||
Logger.error(
|
||||
"Signature validation error for: #{params["actor"]}, make sure you are forwarding the HTTP Host header!"
|
||||
)
|
||||
|
||||
Logger.info(inspect(conn.req_headers))
|
||||
Logger.error(inspect(conn.req_headers))
|
||||
end
|
||||
|
||||
json(conn, "error")
|
||||
|
||||
@@ -24,7 +24,7 @@ defmodule MobilizonWeb.Guardian do
|
||||
try do
|
||||
case Integer.parse(uid_str) do
|
||||
{uid, ""} ->
|
||||
{:ok, Actors.get_user_with_actor!(uid)}
|
||||
{:ok, Actors.get_user_with_actors!(uid)}
|
||||
|
||||
_ ->
|
||||
{:error, :invalid_id}
|
||||
|
||||
@@ -18,34 +18,31 @@ defmodule MobilizonWeb.HTTPSignaturePlug do
|
||||
end
|
||||
|
||||
def call(conn, _opts) do
|
||||
user = conn.params["actor"]
|
||||
actor = conn.params["actor"]
|
||||
|
||||
Logger.debug(fn ->
|
||||
"Checking sig for #{user}"
|
||||
"Checking sig for #{actor}"
|
||||
end)
|
||||
|
||||
with [signature | _] <- get_req_header(conn, "signature") do
|
||||
cond do
|
||||
signature && String.contains?(signature, user) ->
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header(
|
||||
"(request-target)",
|
||||
String.downcase("#{conn.method}") <> " #{conn.request_path}"
|
||||
)
|
||||
[signature | _] = get_req_header(conn, "signature")
|
||||
|
||||
assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
|
||||
|
||||
signature ->
|
||||
Logger.debug("Signature not from actor")
|
||||
assign(conn, :valid_signature, false)
|
||||
|
||||
true ->
|
||||
Logger.debug("No signature header!")
|
||||
cond do
|
||||
# Dialyzer doesn't like this line
|
||||
signature && String.contains?(signature, actor) ->
|
||||
conn =
|
||||
conn
|
||||
end
|
||||
else
|
||||
_ ->
|
||||
|> put_req_header(
|
||||
"(request-target)",
|
||||
String.downcase("#{conn.method}") <> " #{conn.request_path}"
|
||||
)
|
||||
|
||||
assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
|
||||
|
||||
signature ->
|
||||
Logger.debug("Signature not from actor")
|
||||
assign(conn, :valid_signature, false)
|
||||
|
||||
true ->
|
||||
Logger.debug("No signature header!")
|
||||
conn
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||
Find an user by it's ID
|
||||
"""
|
||||
def find_user(_parent, %{id: id}, _resolution) do
|
||||
Actors.get_user_with_actor(id)
|
||||
Actors.get_user_with_actors(id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -13,11 +13,15 @@ defmodule MobilizonWeb.Router do
|
||||
plug(:accepts, ["json", "jrd-json"])
|
||||
end
|
||||
|
||||
pipeline :activity_pub do
|
||||
pipeline :activity_pub_signature do
|
||||
plug(:accepts, ["activity-json", "html"])
|
||||
plug(MobilizonWeb.HTTPSignaturePlug)
|
||||
end
|
||||
|
||||
pipeline :activity_pub do
|
||||
plug(:accepts, ["activity-json", "html"])
|
||||
end
|
||||
|
||||
pipeline :browser do
|
||||
plug(:accepts, ["html"])
|
||||
plug(:fetch_session)
|
||||
@@ -56,6 +60,10 @@ defmodule MobilizonWeb.Router do
|
||||
get("/@:name/followers", ActivityPubController, :followers)
|
||||
get("/events/:uuid", ActivityPubController, :event)
|
||||
get("/comments/:uuid", ActivityPubController, :comment)
|
||||
end
|
||||
|
||||
scope "/", MobilizonWeb do
|
||||
pipe_through(:activity_pub_signature)
|
||||
post("/@:name/inbox", ActivityPubController, :inbox)
|
||||
post("/inbox", ActivityPubController, :inbox)
|
||||
end
|
||||
|
||||
@@ -309,10 +309,10 @@ defmodule MobilizonWeb.Schema do
|
||||
resolve(&Resolvers.User.change_default_actor/3)
|
||||
end
|
||||
|
||||
@desc "Upload a picture"
|
||||
field :upload_picture, :picture do
|
||||
arg(:file, non_null(:upload))
|
||||
resolve(&Resolvers.Upload.upload_picture/3)
|
||||
end
|
||||
# @desc "Upload a picture"
|
||||
# field :upload_picture, :picture do
|
||||
# arg(:file, non_null(:upload))
|
||||
# resolve(&Resolvers.Upload.upload_picture/3)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,11 +97,11 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||
|
||||
{activities, total} = ActivityPub.fetch_public_activities_for_actor(actor, page)
|
||||
|
||||
collection =
|
||||
Enum.map(activities, fn act ->
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(act.data)
|
||||
data
|
||||
end)
|
||||
# collection =
|
||||
# Enum.map(activities, fn act ->
|
||||
# {:ok, data} = Transmogrifier.prepare_outgoing(act.data)
|
||||
# data
|
||||
# end)
|
||||
|
||||
iri = "#{actor.url}/outbox"
|
||||
|
||||
@@ -127,9 +127,9 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||
end
|
||||
end
|
||||
|
||||
def render("activity.json", %{activity: %Activity{local: local} = activity}) do
|
||||
def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do
|
||||
%{
|
||||
"id" => activity.data.url <> "/activity",
|
||||
"id" => data["id"],
|
||||
"type" =>
|
||||
if local do
|
||||
"Create"
|
||||
@@ -139,14 +139,14 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||
"actor" => activity.actor,
|
||||
# Not sure if needed since this is used into outbox
|
||||
"published" => Timex.now(),
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"to" => activity.recipients,
|
||||
"object" =>
|
||||
case activity.type do
|
||||
:Event ->
|
||||
render_one(activity.data, ObjectView, "event.json", as: :event)
|
||||
case data["type"] do
|
||||
"Event" ->
|
||||
render_one(data, ObjectView, "event.json", as: :event)
|
||||
|
||||
:Comment ->
|
||||
render_one(activity.data, ObjectView, "comment.json", as: :comment)
|
||||
"Note" ->
|
||||
render_one(data, ObjectView, "comment.json", as: :comment)
|
||||
end
|
||||
}
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
|
||||
@@ -7,13 +7,14 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do
|
||||
def render("event.json", %{event: event}) do
|
||||
event = %{
|
||||
"type" => "Event",
|
||||
"id" => event.url,
|
||||
"name" => event.title,
|
||||
"category" => render_one(event.category, ObjectView, "category.json", as: :category),
|
||||
"content" => event.description,
|
||||
"mediaType" => "text/html",
|
||||
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
|
||||
"updated" => Timex.format!(event.updated_at, "{ISO:Extended}")
|
||||
"actor" => event["actor"],
|
||||
"id" => event["id"],
|
||||
"name" => event["title"],
|
||||
"category" => render_one(event["category"], ObjectView, "category.json", as: :category),
|
||||
"content" => event["summary"],
|
||||
"mediaType" => "text/html"
|
||||
# "published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
|
||||
# "updated" => Timex.format!(event.updated_at, "{ISO:Extended}")
|
||||
}
|
||||
|
||||
Map.merge(event, Utils.make_json_ld_header())
|
||||
@@ -21,16 +22,16 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do
|
||||
|
||||
def render("comment.json", %{comment: comment}) do
|
||||
comment = %{
|
||||
"actor" => comment.actor.url,
|
||||
"uuid" => comment.uuid,
|
||||
"actor" => comment["actor"],
|
||||
"uuid" => comment["uuid"],
|
||||
# The activity should have attributedTo, not the comment itself
|
||||
# "attributedTo" => comment.attributed_to,
|
||||
"type" => "Note",
|
||||
"id" => comment.url,
|
||||
"content" => comment.text,
|
||||
"mediaType" => "text/html",
|
||||
"published" => Timex.format!(comment.inserted_at, "{ISO:Extended}"),
|
||||
"updated" => Timex.format!(comment.updated_at, "{ISO:Extended}")
|
||||
"id" => comment["id"],
|
||||
"content" => comment["content"],
|
||||
"mediaType" => "text/html"
|
||||
# "published" => Timex.format!(comment.inserted_at, "{ISO:Extended}"),
|
||||
# "updated" => Timex.format!(comment.updated_at, "{ISO:Extended}")
|
||||
}
|
||||
|
||||
Map.merge(comment, Utils.make_json_ld_header())
|
||||
|
||||
Reference in New Issue
Block a user