mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Add configurable registration_reason limit
This commit is contained in:
parent
6747bf2e16
commit
6f44a0ee84
4 changed files with 21 additions and 2 deletions
|
@ -238,6 +238,7 @@ config :pleroma, :instance,
|
||||||
max_remote_account_fields: 20,
|
max_remote_account_fields: 20,
|
||||||
account_field_name_length: 512,
|
account_field_name_length: 512,
|
||||||
account_field_value_length: 2048,
|
account_field_value_length: 2048,
|
||||||
|
registration_reason_length: 500,
|
||||||
external_user_synchronization: true,
|
external_user_synchronization: true,
|
||||||
extended_nickname_format: true,
|
extended_nickname_format: true,
|
||||||
cleanup_attachments: false,
|
cleanup_attachments: false,
|
||||||
|
|
|
@ -641,6 +641,7 @@ defmodule Pleroma.User do
|
||||||
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||||
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
||||||
name_limit = Config.get([:instance, :user_name_length], 100)
|
name_limit = Config.get([:instance, :user_name_length], 100)
|
||||||
|
reason_limit = Config.get([:instance, :registration_reason_length], 500)
|
||||||
params = Map.put_new(params, :accepts_chat_messages, true)
|
params = Map.put_new(params, :accepts_chat_messages, true)
|
||||||
|
|
||||||
need_confirmation? =
|
need_confirmation? =
|
||||||
|
@ -681,6 +682,7 @@ defmodule Pleroma.User do
|
||||||
|> validate_format(:email, @email_regex)
|
|> validate_format(:email, @email_regex)
|
||||||
|> validate_length(:bio, max: bio_limit)
|
|> validate_length(:bio, max: bio_limit)
|
||||||
|> validate_length(:name, min: 1, max: name_limit)
|
|> validate_length(:name, min: 1, max: name_limit)
|
||||||
|
|> validate_length(:registration_reason, max: reason_limit)
|
||||||
|> maybe_validate_required_email(opts[:external])
|
|> maybe_validate_required_email(opts[:external])
|
||||||
|> put_password_hash
|
|> put_password_hash
|
||||||
|> put_ap_id()
|
|> put_ap_id()
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddApprovalFieldsToUsers do
|
||||||
def change do
|
def change do
|
||||||
alter table(:users) do
|
alter table(:users) do
|
||||||
add(:approval_pending, :boolean)
|
add(:approval_pending, :boolean)
|
||||||
add(:registration_reason, :string)
|
add(:registration_reason, :text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -550,7 +550,8 @@ defmodule Pleroma.UserTest do
|
||||||
nickname: "nick",
|
nickname: "nick",
|
||||||
password: "test",
|
password: "test",
|
||||||
password_confirmation: "test",
|
password_confirmation: "test",
|
||||||
email: "email@example.com"
|
email: "email@example.com",
|
||||||
|
registration_reason: "I'm a cool guy :)"
|
||||||
}
|
}
|
||||||
setup do: clear_config([:instance, :account_approval_required], true)
|
setup do: clear_config([:instance, :account_approval_required], true)
|
||||||
|
|
||||||
|
@ -561,6 +562,21 @@ defmodule Pleroma.UserTest do
|
||||||
{:ok, user} = Repo.insert(changeset)
|
{:ok, user} = Repo.insert(changeset)
|
||||||
|
|
||||||
assert user.approval_pending
|
assert user.approval_pending
|
||||||
|
assert user.registration_reason == "I'm a cool guy :)"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it restricts length of registration reason" do
|
||||||
|
reason_limit = Pleroma.Config.get([:instance, :registration_reason_length])
|
||||||
|
|
||||||
|
assert is_integer(reason_limit)
|
||||||
|
|
||||||
|
params =
|
||||||
|
@full_user_data
|
||||||
|
|> Map.put(:registration_reason, "Quia et nesciunt dolores numquam ipsam nisi sapiente soluta. Ullam repudiandae nisi quam porro officiis officiis ad. Consequatur animi velit ex quia. Odit voluptatem perferendis quia ut nisi. Dignissimos sit soluta atque aliquid dolorem ut dolorum ut. Labore voluptates iste iusto amet voluptatum earum. Ad fugit illum nam eos ut nemo. Pariatur ea fuga non aspernatur. Dignissimos debitis officia corporis est nisi ab et. Atque itaque alias eius voluptas minus. Accusamus numquam tempore occaecati in.")
|
||||||
|
|
||||||
|
changeset = User.register_changeset(%User{}, params)
|
||||||
|
|
||||||
|
refute changeset.valid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue