From 0859de43f9d31642e7ec1bad804fadd678858e0c Mon Sep 17 00:00:00 2001 From: Adrien Poly Date: Wed, 19 Feb 2025 23:17:05 +0100 Subject: [PATCH] downcase github handle (#639) --- app/models/connected_account.rb | 2 ++ app/models/speaker.rb | 4 +++- app/models/user.rb | 2 +- .../20250218073648_normalize_github_handle.rb | 18 ++++++++++++++++++ db/schema.rb | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20250218073648_normalize_github_handle.rb diff --git a/app/models/connected_account.rb b/app/models/connected_account.rb index a93130180..91e3b00a2 100644 --- a/app/models/connected_account.rb +++ b/app/models/connected_account.rb @@ -28,4 +28,6 @@ class ConnectedAccount < ApplicationRecord belongs_to :user encrypts :access_token + + normalizes :username, with: ->(value) { value.strip.downcase } end diff --git a/app/models/speaker.rb b/app/models/speaker.rb index d6e39d891..2d28271eb 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -76,7 +76,9 @@ class Speaker < ApplicationRecord scope :not_canonical, -> { where.not(canonical_id: nil) } # normalizes - normalizes :github, with: ->(value) { value.gsub(/^(?:https?:\/\/)?(?:www\.)?github\.com\//, "").gsub(/^@/, "") } + normalizes :github, with: ->(value) { + value.gsub(/^(?:https?:\/\/)?(?:www\.)?github\.com\//, "").gsub(/^@/, "").downcase + } normalizes :twitter, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:x\.com|twitter\.com)/}, "").gsub(/@/, "") } normalizes :bsky, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:x\.com|bsky\.app/profile)/}, "").gsub(/@/, "") diff --git a/app/models/user.rb b/app/models/user.rb index 44bf917e0..79e39dc8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,7 +53,7 @@ def self.normalize_github_handle(value) value .gsub(GITHUB_URL_PATTERN, "") .delete("@") - .strip + .strip.downcase end after_update if: :password_digest_previously_changed? do diff --git a/db/migrate/20250218073648_normalize_github_handle.rb b/db/migrate/20250218073648_normalize_github_handle.rb new file mode 100644 index 000000000..a1c5d9300 --- /dev/null +++ b/db/migrate/20250218073648_normalize_github_handle.rb @@ -0,0 +1,18 @@ +class NormalizeGitHubHandle < ActiveRecord::Migration[8.0] + def change + User.all.each do |u| + next if u.github_handle.blank? + u.update_column(:github_handle, u.github_handle.strip.downcase) + end + + ConnectedAccount.all.each do |ca| + next if ca.username.blank? + + ca.update_column(:username, ca.username.strip.downcase) + end + + Speaker.where.not(github: [nil, ""]).each do |s| + s.update_column(:github, s.github.strip.downcase) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 933d17c1d..c11a545fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_28_085252) do +ActiveRecord::Schema[8.0].define(version: 2025_02_18_073648) do create_table "ahoy_events", force: :cascade do |t| t.integer "visit_id" t.integer "user_id"