Fix setting of keys.
This commit is contained in:
parent
fc3bcf335e
commit
e7cd6e9739
|
@ -15,7 +15,7 @@ defmodule Pleroma.User.Info do
|
||||||
field(:no_rich_text, :boolean, default: false)
|
field(:no_rich_text, :boolean, default: false)
|
||||||
field(:ap_enabled, :boolean, default: false)
|
field(:ap_enabled, :boolean, default: false)
|
||||||
field(:is_moderator, :boolean, default: false)
|
field(:is_moderator, :boolean, default: false)
|
||||||
field(:keys, :map, default: %{})
|
field(:keys, :string, default: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_activation_status(info, deactivated) do
|
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
|
def remove_from_block(info, blocked) do
|
||||||
set_blocks(info, List.delete(info.blocks, blocked))
|
set_blocks(info, List.delete(info.blocks, blocked))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_keys(info, keys) do
|
||||||
|
params = %{keys: keys}
|
||||||
|
|
||||||
|
info
|
||||||
|
|> cast(params, [:keys])
|
||||||
|
|> validate_required([:keys])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -113,16 +113,20 @@ def represent_user(user, "XML") do
|
||||||
|
|
||||||
# This seems a better fit in Salmon
|
# This seems a better fit in Salmon
|
||||||
def ensure_keys_present(user) do
|
def ensure_keys_present(user) do
|
||||||
info = user.info || %{}
|
info = user.info
|
||||||
|
|
||||||
if info["keys"] do
|
if info.keys do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
{:ok, pem} = Salmon.generate_rsa_pem()
|
{:ok, pem} = Salmon.generate_rsa_pem()
|
||||||
info = Map.put(info, "keys", pem)
|
|
||||||
|
|
||||||
Ecto.Changeset.change(user, info: info)
|
info_cng = info
|
||||||
|> User.update_and_set_cache()
|
|> 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue