refactor: Remove the registerPerson GraphQL query
- The first profile is now created after the user email validation - NavBar is correctly updated when a user is connected but without any profile - Always fetch identities from the server at login (no cache) - NoIdentitiesException is thrown again - Refactor EditIdentity to create the first profile - Translations updated - Tests updated Fixes #1762
This commit is contained in:
@@ -296,58 +296,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
This function is used to register a person afterwards the user has been created (but not activated)
|
||||
"""
|
||||
@spec register_person(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Actor.t()} | {:error, String.t()}
|
||||
def register_person(_parent, args, %{context: context}) do
|
||||
current_ip = Map.get(context, :ip)
|
||||
user_agent = Map.get(context, :user_agent, "")
|
||||
|
||||
# When registering, email is assumed confirmed (unlike changing email)
|
||||
case Users.get_user_by_email(args.email, unconfirmed: false) do
|
||||
{:ok, %User{} = user} ->
|
||||
if is_nil(Users.get_actor_for_user(user)) do
|
||||
# No profile yet, we can create one
|
||||
with {:spam, :ham} <-
|
||||
{:spam,
|
||||
AntiSpam.service().check_profile(
|
||||
args.preferred_username,
|
||||
args.summary,
|
||||
args.email,
|
||||
current_ip,
|
||||
user_agent
|
||||
)},
|
||||
args when is_map(args) <- prepare_args(args, user) do
|
||||
Actors.new_person(args, true)
|
||||
else
|
||||
{:error, :file_too_large} ->
|
||||
{:error, dgettext("errors", "The provided picture is too heavy")}
|
||||
|
||||
{:error, _err} ->
|
||||
{:error, dgettext("errors", "Error while uploading pictures")}
|
||||
|
||||
{:spam, _} ->
|
||||
{:error, dgettext("errors", "Your profile was detected as spam.")}
|
||||
end
|
||||
else
|
||||
{:error, dgettext("errors", "You already have a profile for this user")}
|
||||
end
|
||||
|
||||
{:error, :user_not_found} ->
|
||||
{:error, dgettext("errors", "No user with this email was found")}
|
||||
end
|
||||
end
|
||||
|
||||
@spec prepare_args(map(), User.t()) :: map() | {:error, any()}
|
||||
defp prepare_args(args, %User{} = user) do
|
||||
args
|
||||
|> Map.update(:preferred_username, "", &String.downcase/1)
|
||||
|> Map.put(:user_id, user.id)
|
||||
|> save_attached_pictures()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the participations, optionally restricted to an event
|
||||
"""
|
||||
|
||||
@@ -299,37 +299,6 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||
|
||||
resolve(&Person.delete_person/3)
|
||||
end
|
||||
|
||||
@desc "Register a first profile on registration"
|
||||
field :register_person, :person do
|
||||
arg(:preferred_username, non_null(:string), description: "The username for the profile")
|
||||
|
||||
arg(:name, :string,
|
||||
description: "The displayed name for the new profile",
|
||||
default_value: ""
|
||||
)
|
||||
|
||||
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
||||
arg(:email, non_null(:string), description: "The email from the user previously created")
|
||||
|
||||
arg(:avatar, :media_input,
|
||||
description:
|
||||
"The avatar for the profile, either as an object or directly the ID of an existing media"
|
||||
)
|
||||
|
||||
arg(:banner, :media_input,
|
||||
description:
|
||||
"The banner for the profile, either as an object or directly the ID of an existing media"
|
||||
)
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :all,
|
||||
scope: Mobilizon.Actors.Actor,
|
||||
args: %{}
|
||||
)
|
||||
|
||||
resolve(&Person.register_person/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :person_subscriptions do
|
||||
|
||||
Reference in New Issue
Block a user