From e02e88bff4ad5f5acd017fa340f745b87f430a46 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 27 Sep 2024 04:21:27 -0400 Subject: [PATCH] Use previously extracted model constants in form `maxlength` attributes (#32113) --- app/models/form/admin_settings.rb | 4 +++- app/views/admin/settings/branding/show.html.haml | 2 +- app/views/auth/registrations/new.html.haml | 2 +- app/views/disputes/strikes/show.html.haml | 2 +- app/views/settings/profiles/show.html.haml | 8 ++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 85b913cf80..515909d5cf 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -73,6 +73,8 @@ class Form::AdminSettings authorized_fetch: :authorized_fetch_mode?, }.freeze + DESCRIPTION_LIMIT = 200 + attr_accessor(*KEYS) validates :registrations_mode, inclusion: { in: %w(open approved none) }, if: -> { defined?(@registrations_mode) } @@ -82,7 +84,7 @@ class Form::AdminSettings validates :show_domain_blocks, inclusion: { in: %w(disabled users all) }, if: -> { defined?(@show_domain_blocks) } validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) }, if: -> { defined?(@show_domain_blocks_rationale) } validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }, allow_blank: true, if: -> { defined?(@media_cache_retention_period) || defined?(@content_cache_retention_period) || defined?(@backups_retention_period) } - validates :site_short_description, length: { maximum: 200 }, if: -> { defined?(@site_short_description) } + validates :site_short_description, length: { maximum: DESCRIPTION_LIMIT }, if: -> { defined?(@site_short_description) } validates :status_page_url, url: true, allow_blank: true validate :validate_site_uploads diff --git a/app/views/admin/settings/branding/show.html.haml b/app/views/admin/settings/branding/show.html.haml index e03c16a25a..62e9c72459 100644 --- a/app/views/admin/settings/branding/show.html.haml +++ b/app/views/admin/settings/branding/show.html.haml @@ -25,7 +25,7 @@ .fields-group = f.input :site_short_description, as: :text, - input_html: { rows: 2, maxlength: 200 }, + input_html: { rows: 2, maxlength: Form::AdminSettings::DESCRIPTION_LIMIT }, wrapper: :with_block_label .fields-row diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml index 1e5aac2976..d58f1ccf4d 100644 --- a/app/views/auth/registrations/new.html.haml +++ b/app/views/auth/registrations/new.html.haml @@ -21,7 +21,7 @@ = f.simple_fields_for :account do |ff| = ff.input :username, append: "@#{site_hostname}", - input_html: { 'aria-label': t('simple_form.labels.defaults.username'), autocomplete: 'off', placeholder: t('simple_form.labels.defaults.username'), pattern: '[a-zA-Z0-9_]+', maxlength: 30 }, + input_html: { 'aria-label': t('simple_form.labels.defaults.username'), autocomplete: 'off', placeholder: t('simple_form.labels.defaults.username'), pattern: '[a-zA-Z0-9_]+', maxlength: Account::USERNAME_LENGTH_LIMIT }, label: false, required: true, wrapper: :with_label diff --git a/app/views/disputes/strikes/show.html.haml b/app/views/disputes/strikes/show.html.haml index 2bfecebbff..150dc06759 100644 --- a/app/views/disputes/strikes/show.html.haml +++ b/app/views/disputes/strikes/show.html.haml @@ -76,7 +76,7 @@ = simple_form_for(@appeal, url: disputes_strike_appeal_path(@strike)) do |f| .fields-group - = f.input :text, wrapper: :with_label, input_html: { maxlength: 500 } + = f.input :text, wrapper: :with_label, input_html: { maxlength: Appeal::TEXT_LENGTH_LIMIT } .actions = f.button :button, t('disputes.strikes.appeals.submit'), type: :submit diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml index 9790df7d05..8fb2132519 100644 --- a/app/views/settings/profiles/show.html.haml +++ b/app/views/settings/profiles/show.html.haml @@ -15,10 +15,10 @@ .fields-row .fields-row__column.fields-row__column-6 .fields-group - = f.input :display_name, wrapper: :with_block_label, input_html: { maxlength: 30, data: { default: @account.username } } + = f.input :display_name, wrapper: :with_block_label, input_html: { maxlength: Account::DISPLAY_NAME_LENGTH_LIMIT, data: { default: @account.username } } .fields-group - = f.input :note, wrapper: :with_block_label, input_html: { maxlength: 500 } + = f.input :note, wrapper: :with_block_label, input_html: { maxlength: Account::NOTE_LENGTH_LIMIT } .fields-row__column.fields-group.fields-row__column-6 .input.with_block_label @@ -27,8 +27,8 @@ = f.simple_fields_for :fields do |fields_f| .row - = fields_f.input :name, placeholder: t('simple_form.labels.account.fields.name'), input_html: { maxlength: 255 } - = fields_f.input :value, placeholder: t('simple_form.labels.account.fields.value'), input_html: { maxlength: 255 } + = fields_f.input :name, placeholder: t('simple_form.labels.account.fields.name'), input_html: { maxlength: Account::Field::MAX_CHARACTERS_LOCAL } + = fields_f.input :value, placeholder: t('simple_form.labels.account.fields.value'), input_html: { maxlength: Account::Field::MAX_CHARACTERS_LOCAL } .fields-row .fields-row__column.fields-row__column-6