Add configurable registration_reason limit
This commit is contained in:
parent
6747bf2e16
commit
6f44a0ee84
|
@ -238,6 +238,7 @@
|
|||
max_remote_account_fields: 20,
|
||||
account_field_name_length: 512,
|
||||
account_field_value_length: 2048,
|
||||
registration_reason_length: 500,
|
||||
external_user_synchronization: true,
|
||||
extended_nickname_format: true,
|
||||
cleanup_attachments: false,
|
||||
|
|
|
@ -641,6 +641,7 @@ def force_password_reset(user), do: update_password_reset_pending(user, true)
|
|||
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
||||
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)
|
||||
|
||||
need_confirmation? =
|
||||
|
@ -681,6 +682,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
|
|||
|> validate_format(:email, @email_regex)
|
||||
|> validate_length(:bio, max: bio_limit)
|
||||
|> validate_length(:name, min: 1, max: name_limit)
|
||||
|> validate_length(:registration_reason, max: reason_limit)
|
||||
|> maybe_validate_required_email(opts[:external])
|
||||
|> put_password_hash
|
||||
|> put_ap_id()
|
||||
|
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddApprovalFieldsToUsers do
|
|||
def change do
|
||||
alter table(:users) do
|
||||
add(:approval_pending, :boolean)
|
||||
add(:registration_reason, :string)
|
||||
add(:registration_reason, :text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -550,7 +550,8 @@ test "it creates confirmed user if :confirmed option is given" do
|
|||
nickname: "nick",
|
||||
password: "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)
|
||||
|
||||
|
@ -561,6 +562,21 @@ test "it creates unapproved user" do
|
|||
{:ok, user} = Repo.insert(changeset)
|
||||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue