Use model constants more consistently for view expiration collections (#38589)

This commit is contained in:
Matt Jankowski 2026-04-17 09:57:18 -04:00 committed by GitHub
parent 9afaa23e78
commit 1d3ca80bf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 15 deletions

View File

@ -1,11 +0,0 @@
# frozen_string_literal: true
module InvitesHelper
def invites_max_uses_options
[1, 5, 10, 25, 50, 100]
end
def invites_expires_options
[30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week]
end
end

View File

@ -21,7 +21,9 @@ class Invite < ApplicationRecord
COMMENT_SIZE_LIMIT = 420
ELIGIBLE_CODE_CHARACTERS = [*('a'..'z'), *('A'..'Z'), *('0'..'9')].freeze
EXPIRATION_DURATIONS = [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week].freeze
HOMOGLYPHS = %w(0 1 I l O).freeze
MAX_USES_COUNTS = [1, 5, 10, 25, 50, 100].freeze
VALID_CODE_CHARACTERS = (ELIGIBLE_CODE_CHARACTERS - HOMOGLYPHS).freeze
belongs_to :user, inverse_of: :invites

View File

@ -20,6 +20,8 @@ class IpBlock < ApplicationRecord
include InetContainer
include Paginable
EXPIRATION_DURATIONS = [1.day, 2.weeks, 1.month, 6.months, 1.year, 3.years].freeze
enum :severity, {
sign_up_requires_approval: 5000,
sign_up_block: 5500,

View File

@ -12,7 +12,7 @@
.fields-group
= f.input :expires_in,
collection: [1.day, 2.weeks, 1.month, 6.months, 1.year, 3.years].map(&:to_i),
collection: IpBlock::EXPIRATION_DURATIONS.map(&:to_i),
label_method: ->(i) { I18n.t("admin.ip_blocks.expires_in.#{i}") },
prompt: I18n.t('invites.expires_in_prompt'),
wrapper: :with_block_label

View File

@ -2,12 +2,21 @@
.fields-row
.fields-row__column.fields-row__column-6.fields-group
= form.input :max_uses, wrapper: :with_label, collection: invites_max_uses_options, label_method: ->(num) { I18n.t('invites.max_uses', count: num) }, prompt: I18n.t('invites.max_uses_prompt')
= form.input :max_uses,
collection: Invite::MAX_USES_COUNTS,
label_method: ->(count) { I18n.t('invites.max_uses', count:) },
prompt: I18n.t('invites.max_uses_prompt'),
wrapper: :with_label
.fields-row__column.fields-row__column-6.fields-group
= form.input :expires_in, wrapper: :with_label, collection: invites_expires_options.map(&:to_i), label_method: ->(i) { I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt')
= form.input :expires_in,
collection: Invite::EXPIRATION_DURATIONS.map(&:to_i),
label_method: ->(duration) { I18n.t("invites.expires_in.#{duration}") },
prompt: I18n.t('invites.expires_in_prompt'),
wrapper: :with_label
.fields-group
= form.input :autofollow, wrapper: :with_label
= form.input :autofollow,
wrapper: :with_label
.actions
= form.button :button, t('invites.generate'), type: :submit