Add an authenticated fetch route for members

If the member is remote, it redirects to original instance

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-08-19 11:28:23 +02:00
parent b4c624de23
commit bdb4350624
7 changed files with 130 additions and 3 deletions

View File

@@ -4,7 +4,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
"""
alias Mobilizon.{Actors, Discussions, Events, Posts, Resources, Todos, Tombstone}
alias Mobilizon.Actors.Actor
alias Mobilizon.Actors.{Actor, Member}
alias Mobilizon.Discussions.{Comment, Discussion}
alias Mobilizon.Events.Event
alias Mobilizon.Federation.ActivityPub.Relay
@@ -174,6 +174,23 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
end)
end
@doc """
Gets a member by its UUID, with all associations loaded.
"""
@spec get_member_by_uuid_with_preload(String.t()) ::
{:commit, Todo.t()} | {:ignore, nil}
def get_member_by_uuid_with_preload(uuid) do
Cachex.fetch(@cache, "member_" <> uuid, fn "member_" <> uuid ->
case Actors.get_member(uuid) do
%Member{} = member ->
{:commit, member}
nil ->
{:ignore, nil}
end
end)
end
@doc """
Gets a relay.
"""

View File

@@ -24,6 +24,7 @@ defmodule Mobilizon.Web.Cache do
defdelegate get_resource_by_uuid_with_preload(uuid), to: ActivityPub
defdelegate get_todo_list_by_uuid_with_preload(uuid), to: ActivityPub
defdelegate get_todo_by_uuid_with_preload(uuid), to: ActivityPub
defdelegate get_member_by_uuid_with_preload(uuid), to: ActivityPub
defdelegate get_post_by_slug_with_preload(slug), to: ActivityPub
defdelegate get_discussion_by_slug_with_preload(slug), to: ActivityPub
defdelegate get_relay, to: ActivityPub