Ensure local users have collection addresses
This commit is contained in:
parent
698f39d7de
commit
057d977f5a
3 changed files with 53 additions and 1 deletions
|
|
@ -407,6 +407,12 @@ defmodule Pleroma.User do
|
|||
def generate_ap_id(%{nickname: nickname}) when nickname != nil,
|
||||
do: "#{Endpoint.url()}/users/#{nickname}"
|
||||
|
||||
@spec generate_ap_inbox(%{ap_id: String.t()}) :: String.t()
|
||||
def generate_ap_inbox(%{ap_id: ap_id}) when ap_id != nil, do: "#{ap_id}/inbox"
|
||||
|
||||
@spec generate_ap_outbox(%{ap_id: String.t()}) :: String.t()
|
||||
def generate_ap_outbox(%{ap_id: ap_id}) when ap_id != nil, do: "#{ap_id}/outbox"
|
||||
|
||||
@spec generate_ap_followers(%{ap_id: String.t()}) :: String.t()
|
||||
def generate_ap_followers(%{ap_id: ap_id}) when ap_id != nil, do: "#{ap_id}/followers"
|
||||
|
||||
|
|
@ -789,6 +795,7 @@ defmodule Pleroma.User do
|
|||
|> validate_format(:nickname, local_nickname_regex())
|
||||
|> put_ap_id()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_in_and_outbox()
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
|> put_private_key()
|
||||
end
|
||||
|
|
@ -851,6 +858,7 @@ defmodule Pleroma.User do
|
|||
|> put_password_hash
|
||||
|> put_ap_id()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_in_and_outbox()
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
|> put_private_key()
|
||||
end
|
||||
|
|
@ -871,6 +879,17 @@ defmodule Pleroma.User do
|
|||
|
||||
defp put_ap_id(%{valid?: false} = changeset), do: changeset
|
||||
|
||||
defp put_in_and_outbox(%{valid?: true, changes: initdata} = changeset) do
|
||||
inbox = generate_ap_inbox(initdata)
|
||||
outbox = generate_ap_inbox(initdata)
|
||||
|
||||
changeset
|
||||
|> put_change(:inbox, inbox)
|
||||
|> put_change(:outbox, outbox)
|
||||
end
|
||||
|
||||
defp put_in_and_outbox(%{valid?: false} = changeset), do: changeset
|
||||
|
||||
defp put_following_and_follower_and_featured_address(
|
||||
%{valid?: true, changes: initdata} = changeset
|
||||
) do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
defmodule Pleroma.Repo.Migrations.EnsureLocalUsersHaveAPCollections do
|
||||
use Ecto.Migration
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
defp update_for(target, suffix) do
|
||||
from(
|
||||
u in Pleroma.User,
|
||||
where: u.local and is_nil(field(u, ^target)),
|
||||
update: [set: [{^target, fragment("? || ?::text", u.ap_id, ^suffix)}]]
|
||||
)
|
||||
|> Pleroma.Repo.update_all([])
|
||||
end
|
||||
|
||||
def up() do
|
||||
# Suffixes are copied from contemporary generate_* functions in User module
|
||||
|
||||
# note: up until now local users _always_ had a nil inbox and outbox
|
||||
update_for(:inbox, "/inbox")
|
||||
update_for(:outbox, "/outbox")
|
||||
|
||||
update_for(:featured_address, "/collections/featured")
|
||||
|
||||
update_for(:follower_address, "/followers")
|
||||
update_for(:following_address, "/following")
|
||||
end
|
||||
|
||||
def down() do
|
||||
# no need to revert
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
@ -91,7 +91,8 @@ defmodule Pleroma.Factory do
|
|||
|
||||
%{
|
||||
ap_id: ap_id,
|
||||
inbox: User.generate_ap_id(user) <> "/inbox",
|
||||
inbox: User.generate_ap_inbox(user),
|
||||
outbox: User.generate_ap_outbox(user),
|
||||
follower_address: User.generate_ap_followers(user),
|
||||
following_address: User.generate_ap_following(user),
|
||||
featured_address: User.generate_ap_featured_collection(user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue