fix: Fix regression in followers_live.ex
This commit is contained in:
parent
9ad0c9b3fd
commit
dc7c855095
4 changed files with 46 additions and 8 deletions
20
lib/postland/permissions.ex
Normal file
20
lib/postland/permissions.ex
Normal 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
|
||||||
|
|
@ -21,7 +21,7 @@ defmodule PostlandWeb.CoreComponents do
|
||||||
use Gettext, backend: PostlandWeb.Gettext
|
use Gettext, backend: PostlandWeb.Gettext
|
||||||
|
|
||||||
def profile_card(assigns) do
|
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)
|
assigns = Map.put(assigns, :host, host)
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule PostlandWeb.CoreComponents do
|
||||||
<div class="flex-shrink-0 relative">
|
<div class="flex-shrink-0 relative">
|
||||||
<img
|
<img
|
||||||
class="h-16 w-16 rounded-full drop-shadow-lg"
|
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=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ defmodule PostlandWeb.InboxController do
|
||||||
alias Postland.Activities
|
alias Postland.Activities
|
||||||
|
|
||||||
def post(conn, params) do
|
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
|
case Activities.process_activity(params) do
|
||||||
{:ok, _activity} ->
|
{:ok, _activity} ->
|
||||||
send_resp(conn, 200, Jason.encode!(params))
|
send_resp(conn, 200, Jason.encode!(params))
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,19 @@ defmodule PostlandWeb.FollowersLive do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="py-4">
|
<div class="py-4">
|
||||||
<h3 class="text-base font-semibold">Followers</h3>
|
<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.
|
No one follows you.
|
||||||
</p>
|
</p>
|
||||||
<div :for={acct <- @accounts} class="mt-2">
|
<div
|
||||||
<.profile_card account={acct} />
|
: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>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
@ -20,8 +28,17 @@ defmodule PostlandWeb.FollowersLive do
|
||||||
|
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
followers =
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue