From e7cd6e97394a80ed3ef794e801183cc0635f8a15 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 18 Nov 2018 19:33:43 +0100 Subject: [PATCH] Fix setting of keys. --- lib/pleroma/user/info.ex | 10 +++++++++- lib/pleroma/web/web_finger/web_finger.ex | 14 +++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 619e58b16..39a1291dd 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -15,7 +15,7 @@ defmodule Pleroma.User.Info do field(:no_rich_text, :boolean, default: false) field(:ap_enabled, :boolean, default: false) field(:is_moderator, :boolean, default: false) - field(:keys, :map, default: %{}) + field(:keys, :string, default: nil) end def set_activation_status(info, deactivated) do @@ -61,4 +61,12 @@ def add_to_block(info, blocked) do def remove_from_block(info, blocked) do set_blocks(info, List.delete(info.blocks, blocked)) end + + def set_keys(info, keys) do + params = %{keys: keys} + + info + |> cast(params, [:keys]) + |> validate_required([:keys]) + end end diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 9f554d286..18cdc057e 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -113,16 +113,20 @@ def represent_user(user, "XML") do # This seems a better fit in Salmon def ensure_keys_present(user) do - info = user.info || %{} + info = user.info - if info["keys"] do + if info.keys do {:ok, user} else {:ok, pem} = Salmon.generate_rsa_pem() - info = Map.put(info, "keys", pem) - Ecto.Changeset.change(user, info: info) - |> User.update_and_set_cache() + info_cng = info + |> Pleroma.User.Info.set_keys(pem) + + cng = Ecto.Changeset.change(user) + |> Ecto.Changeset.put_embed(:info, info_cng) + + User.update_and_set_cache(cng) end end