Introduce registerPerson mutation

To register a profile from an unactivated user

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

👤 Fix Person interface use

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Change host function for data property

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-01-29 11:02:32 +01:00
parent c55ae19f84
commit 681653e035
13 changed files with 519 additions and 172 deletions

View File

@@ -103,6 +103,8 @@ defmodule Mobilizon.Actors.Actor do
:user_id
])
|> build_urls()
# Needed because following constraint can't work for domain null values (local)
|> unique_username_validator()
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|> unique_constraint(:url, name: :actors_url_index)
|> validate_required([:preferred_username, :keys, :suspended, :url, :type])
@@ -177,6 +179,16 @@ defmodule Mobilizon.Actors.Actor do
|> put_change(:local, true)
end
def unique_username_validator(
%Ecto.Changeset{changes: %{preferred_username: username}} = changeset
) do
if Actors.get_local_actor_by_name(username) do
changeset |> add_error(:preferred_username, "Username is already taken")
else
changeset
end
end
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
defp build_urls(changeset, type \\ :Person)