Add moderation text in user - #877
This commit is contained in:
@@ -153,13 +153,13 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
- send a validation email to the user
|
||||
"""
|
||||
@spec create_user(any, %{email: String.t()}, any) :: {:ok, User.t()} | {:error, String.t()}
|
||||
def create_user(_parent, %{email: email} = args, %{context: context}) do
|
||||
def create_user(_parent, %{email: email, moderation: moderation} = args, %{context: context}) do
|
||||
current_ip = Map.get(context, :ip)
|
||||
user_agent = Map.get(context, :user_agent, "")
|
||||
now = DateTime.utc_now()
|
||||
|
||||
with {:ok, email} <- lowercase_domain(email),
|
||||
:registration_ok <- check_registration_config(email),
|
||||
:registration_ok <- check_registration_config(email, moderation),
|
||||
:not_deny_listed <- check_registration_denylist(email),
|
||||
{:spam, :ham} <-
|
||||
{:spam, AntiSpam.service().check_user(email, current_ip, user_agent)},
|
||||
@@ -176,6 +176,9 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
:registration_closed ->
|
||||
{:error, dgettext("errors", "Registrations are not open")}
|
||||
|
||||
:moderation_empty ->
|
||||
{:error, dgettext("errors", "Moderation text must not be empty")}
|
||||
|
||||
:not_allowlisted ->
|
||||
{:error, dgettext("errors", "Your email is not on the allowlist")}
|
||||
|
||||
@@ -198,12 +201,12 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
end
|
||||
end
|
||||
|
||||
@spec check_registration_config(String.t()) ::
|
||||
:registration_ok | :registration_closed | :not_allowlisted
|
||||
defp check_registration_config(email) do
|
||||
@spec check_registration_config(String.t(), String.t()) ::
|
||||
:registration_ok | :registration_closed | :not_allowlisted | :moderation_empty
|
||||
defp check_registration_config(email, moderation) do
|
||||
cond do
|
||||
Config.instance_registrations_open?() ->
|
||||
:registration_ok
|
||||
check_moderation(moderation)
|
||||
|
||||
Config.instance_registrations_allowlist?() ->
|
||||
check_allow_listed_email(email)
|
||||
@@ -223,6 +226,19 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
else: :not_deny_listed
|
||||
end
|
||||
|
||||
@spec check_moderation(String.t()) :: :registration_ok | :moderation_empty
|
||||
defp check_moderation(moderation) do
|
||||
if Config.instance_registrations_moderation?() do
|
||||
if moderation |> String.trim() == "" do
|
||||
:moderation_empty
|
||||
else
|
||||
:registration_ok
|
||||
end
|
||||
else
|
||||
:registration_ok
|
||||
end
|
||||
end
|
||||
|
||||
@spec check_allow_listed_email(String.t()) :: :registration_ok | :not_allowlisted
|
||||
defp check_allow_listed_email(email) do
|
||||
if email_in_list?(email, Config.instance_registrations_allowlist()),
|
||||
|
||||
@@ -25,6 +25,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
interfaces([:action_log_object])
|
||||
field(:id, :id, description: "The user's ID")
|
||||
field(:email, non_null(:string), description: "The user's email")
|
||||
field(:moderation, :string, description: "The user's moderation text")
|
||||
|
||||
field(:actors, non_null(list_of(:person)),
|
||||
description: "The user's list of profiles (identities)"
|
||||
@@ -345,6 +346,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
field :create_user, type: :user do
|
||||
arg(:email, non_null(:string), description: "The new user's email")
|
||||
arg(:password, non_null(:string), description: "The new user's password")
|
||||
arg(:moderation, :string, description: "The new user's moderation text")
|
||||
arg(:locale, :string, description: "The new user's locale")
|
||||
middleware(Rajska.QueryAuthorization, permit: :all)
|
||||
middleware(Rajska.RateLimiter, limit: user_ip_limiter(@env))
|
||||
|
||||
@@ -16,6 +16,7 @@ defmodule Mobilizon.Users.User do
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
email: String.t(),
|
||||
moderation: String.t(),
|
||||
password_hash: String.t(),
|
||||
password: String.t(),
|
||||
role: atom(),
|
||||
@@ -40,6 +41,7 @@ defmodule Mobilizon.Users.User do
|
||||
|
||||
@required_attrs [:email]
|
||||
@optional_attrs [
|
||||
:moderation,
|
||||
:role,
|
||||
:password,
|
||||
:password_hash,
|
||||
@@ -61,7 +63,6 @@ defmodule Mobilizon.Users.User do
|
||||
@attrs @required_attrs ++ @optional_attrs
|
||||
|
||||
@registration_required_attrs @required_attrs ++ [:password]
|
||||
|
||||
@auth_provider_required_attrs @required_attrs ++ [:provider]
|
||||
|
||||
@password_change_required_attrs [:password]
|
||||
@@ -72,6 +73,7 @@ defmodule Mobilizon.Users.User do
|
||||
|
||||
schema "users" do
|
||||
field(:email, :string)
|
||||
field(:moderation, :string)
|
||||
field(:password_hash, :string)
|
||||
field(:password, :string, virtual: true)
|
||||
field(:role, UserRole, default: :user)
|
||||
|
||||
Reference in New Issue
Block a user