Fix user updating from AP.
This commit is contained in:
parent
cafa15131a
commit
40d9d2098c
|
@ -128,12 +128,17 @@ def upgrade_changeset(struct, params \\ %{}) do
|
||||||
params
|
params
|
||||||
|> Map.put(:last_refreshed_at, NaiveDateTime.utc_now())
|
|> Map.put(:last_refreshed_at, NaiveDateTime.utc_now())
|
||||||
|
|
||||||
|
info_cng =
|
||||||
|
struct.info
|
||||||
|
|> User.Info.user_upgrade(params[:info])
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|> cast(params, [:bio, :name, :info, :follower_address, :avatar, :last_refreshed_at])
|
|> cast(params, [:bio, :name, :follower_address, :avatar, :last_refreshed_at])
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
||||||
|> validate_length(:bio, max: 5000)
|
|> validate_length(:bio, max: 5000)
|
||||||
|> validate_length(:name, max: 100)
|
|> validate_length(:name, max: 100)
|
||||||
|
|> put_embed(:info, info_cng)
|
||||||
end
|
end
|
||||||
|
|
||||||
def password_update_changeset(struct, params) do
|
def password_update_changeset(struct, params) do
|
||||||
|
|
|
@ -90,4 +90,10 @@ def remote_user_creation(info, params) do
|
||||||
info
|
info
|
||||||
|> cast(params, [:source_data])
|
|> cast(params, [:source_data])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Receives data from user_data_from_user_object
|
||||||
|
def user_upgrade(info, params) do
|
||||||
|
info
|
||||||
|
|> cast(params, [:ap_enabled, :source_data, :banner, :locked])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -850,10 +850,6 @@ defp user_upgrade_task(user) do
|
||||||
def upgrade_user_from_ap_id(ap_id, async \\ true) do
|
def upgrade_user_from_ap_id(ap_id, async \\ true) do
|
||||||
with %User{local: false} = user <- User.get_by_ap_id(ap_id),
|
with %User{local: false} = user <- User.get_by_ap_id(ap_id),
|
||||||
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
|
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
|
||||||
data =
|
|
||||||
data
|
|
||||||
|> Map.put(:info, Map.merge(user.info, data[:info]))
|
|
||||||
|
|
||||||
already_ap = User.ap_enabled?(user)
|
already_ap = User.ap_enabled?(user)
|
||||||
|
|
||||||
{:ok, user} =
|
{:ok, user} =
|
||||||
|
|
|
@ -185,12 +185,14 @@ test "updates an existing user, if stale" do
|
||||||
local: false,
|
local: false,
|
||||||
nickname: "admin@mastodon.example.org",
|
nickname: "admin@mastodon.example.org",
|
||||||
ap_id: "http://mastodon.example.org/users/admin",
|
ap_id: "http://mastodon.example.org/users/admin",
|
||||||
last_refreshed_at: a_week_ago
|
last_refreshed_at: a_week_ago,
|
||||||
|
info: %{}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert orig_user.last_refreshed_at == a_week_ago
|
assert orig_user.last_refreshed_at == a_week_ago
|
||||||
|
|
||||||
user = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
user = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||||
|
assert user.info.source_data["endpoints"]
|
||||||
|
|
||||||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue