fix: Fix regression in followers_live.ex

This commit is contained in:
Ro 2024-11-24 10:18:35 -06:00
parent 9ad0c9b3fd
commit dc7c855095
Signed by: ro
GPG key ID: 5B5AD5A568CDABF9
4 changed files with 46 additions and 8 deletions

View file

@ -0,0 +1,20 @@
defmodule Postland.Permissions do
@filters [
:actor_domain,
:object_domain,
:domain_match
]
def permitted?(%{"type" => type} = params) when type in ["Create", "Update", "Delete"] do
actor_domain = host_from(params["actor"])
object_domain = host_from(params["object"])
actor_domain && object_domain && String.ends_with?(object_domain, actor_domain)
end
def permitted?(_), do: true
defp host_from(nil), do: nil
defp host_from(%{"id" => id}), do: URI.parse(id).host
defp host_from(id) when is_binary(id), do: URI.parse(id).host
end

View file

@ -21,7 +21,7 @@ defmodule PostlandWeb.CoreComponents do
use Gettext, backend: PostlandWeb.Gettext
def profile_card(assigns) do
%{host: host} = URI.parse(assigns.account["id"])
%{host: host} = URI.parse(assigns.account["id"] || "")
assigns = Map.put(assigns, :host, host)
@ -30,7 +30,7 @@ defmodule PostlandWeb.CoreComponents do
<div class="flex-shrink-0 relative">
<img
class="h-16 w-16 rounded-full drop-shadow-lg"
src={@account["icon"] || url(~p"/images/avatar.png")}
src={get_in(@account, ["icon", "url"]) || url(~p"/images/avatar.png")}
alt=""
/>
</div>

View file

@ -7,7 +7,8 @@ defmodule PostlandWeb.InboxController do
alias Postland.Activities
def post(conn, params) do
if Headers.verify(conn.method, conn.request_path, conn.req_headers, conn.assigns.raw_body) do
if Headers.verify(conn.method, conn.request_path, conn.req_headers, conn.assigns.raw_body) &&
Postland.Permissions.permitted?(params) do
case Activities.process_activity(params) do
{:ok, _activity} ->
send_resp(conn, 200, Jason.encode!(params))

View file

@ -8,11 +8,19 @@ defmodule PostlandWeb.FollowersLive do
~H"""
<div class="py-4">
<h3 class="text-base font-semibold">Followers</h3>
<p :if={@accounts == []} class="text-gray-400">
<p :if={@count == 0} class="text-gray-400">
No one follows you.
</p>
<div :for={acct <- @accounts} class="mt-2">
<.profile_card account={acct} />
<div
:for={{dom_id, %{confirmed: confirmed, account: account}} <- @streams.accounts}
class="mt-2"
>
<.profile_card
id={dom_id}
dom_id={dom_id}
account={account}
status={if confirmed, do: :follower_confirmed, else: :follower_pending}
/>
</div>
</div>
"""
@ -20,8 +28,17 @@ defmodule PostlandWeb.FollowersLive do
def mount(_params, _session, socket) do
followers =
Follows.all_followers() |> Enum.map(fn follow -> Actors.actor(follow.follower) end)
Follows.all_followers()
|> Enum.map(fn follow ->
%{
id: follow.follower,
confirmed: !!follow.confirmed_at,
account: Actors.actor(follow.follower)
}
end)
{:ok, assign(socket, :accounts, followers)}
account_count = Enum.count(followers)
{:ok, socket |> stream(:accounts, followers) |> assign(count: account_count)}
end
end