From 4cf031ee13b8bda88fdf2ae23a7d6632deeac90c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 6 Jan 2025 13:23:05 -0500 Subject: [PATCH] Extricate `Invite` constants for code generation (#33472) --- app/models/invite.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/invite.rb b/app/models/invite.rb index ea095a3ac1..d1981f16ad 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -20,6 +20,9 @@ class Invite < ApplicationRecord include Expireable COMMENT_SIZE_LIMIT = 420 + ELIGIBLE_CODE_CHARACTERS = [*('a'..'z'), *('A'..'Z'), *('0'..'9')].freeze + HOMOGLYPHS = %w(0 1 I l O).freeze + VALID_CODE_CHARACTERS = ELIGIBLE_CODE_CHARACTERS - HOMOGLYPHS belongs_to :user, inverse_of: :invites has_many :users, inverse_of: :invite, dependent: nil @@ -38,7 +41,7 @@ class Invite < ApplicationRecord def set_code loop do - self.code = ([*('a'..'z'), *('A'..'Z'), *('0'..'9')] - %w(0 1 I l O)).sample(8).join + self.code = VALID_CODE_CHARACTERS.sample(8).join break if Invite.find_by(code: code).nil? end end