From 34456bebec393e677aea11c361b403d34ddf9536 Mon Sep 17 00:00:00 2001 From: Dobe-Time Date: Mon, 29 Dec 2025 19:28:15 -0800 Subject: [PATCH 1/6] AO3-6359 Possible to delete the pseud that corresponds with your username if the capitalization or diacritics differ --- app/models/user.rb | 23 +++++++++++------------ spec/models/user_spec.rb | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index e822a5d4eb..0488d8c41e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -536,25 +536,24 @@ def self.fetch_orphan_account def update_pseud_name return unless saved_change_to_login? && login_before_last_save.present? - - old_pseud = pseuds.where(name: login_before_last_save).first - if login.downcase == login_before_last_save.downcase - old_pseud.name = login - old_pseud.save! - else + + pseud_to_update = pseuds.where(name: login_before_last_save).first + #If the new login is (case insensitive) different from the old login + if login != login_before_last_save.downcase new_pseud = pseuds.where(name: login).first - # do nothing if they already have the matching pseud + #If the user does not have an existing pseud for the new login if new_pseud.blank? - if old_pseud.present? - # change the old pseud to match - old_pseud.name = login - old_pseud.save!(validate: false) - else + #If the pseud for the old login doesn't exist + if !pseud_to_update.present? # shouldn't be able to get here, but just in case Pseud.create!(name: login, user_id: id) end + else + pseud_to_update = new_pseud end end + pseud_to_update.name = login + pseud_to_update.save!(validate:justification_enabled?) end def reindex_user_creations_after_rename diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d55c1bf1f3..8bf82d54da 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -359,6 +359,23 @@ expect(log_item.note).to eq("Change made by #{admin.login}") end end + + context "username was changed to match an existing pseud's name except with alternate capitalization and diacritics" do + let(:new_pseud) { build(:pseud, name: "New_Usernamé") } + + before do + existing_user.pseuds << new_pseud + existing_user.update!(login: "new_username") + existing_user.reload + end + + it "pseud's capitalization and diacritics were changed to match the new username's" do + expect(existing_user.pseuds.size).to eq(2) + expect(existing_user.pseuds.second.name).to eq(existing_user.login) + expect(existing_user.pseuds.second.name).to eq("new_username") + expect(existing_user.login).to eq("new_username") + end + end end describe ".search_multiple_by_email" do @@ -408,3 +425,5 @@ end end end + + From 1bfcfbe9b503cb122d644986290eb8ed6ff1d82a Mon Sep 17 00:00:00 2001 From: Dobe-Time Date: Sat, 3 Jan 2026 13:39:57 -0800 Subject: [PATCH 2/6] AO3-6359 fixing extra new lines in user_spec.rb --- spec/models/user_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8bf82d54da..2affbb55c5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -425,5 +425,3 @@ end end end - - From 1a7c62de8f4a562d6611f80be0a511aeb62289dd Mon Sep 17 00:00:00 2001 From: Dobe-Time Date: Sat, 3 Jan 2026 14:43:21 -0800 Subject: [PATCH 3/6] AO3-6359 Fixing style issue for Rubocop --- app/models/user.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0488d8c41e..85db58e405 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -538,13 +538,13 @@ def update_pseud_name return unless saved_change_to_login? && login_before_last_save.present? pseud_to_update = pseuds.where(name: login_before_last_save).first - #If the new login is (case insensitive) different from the old login + # If the new login is (case insensitive) different from the old login if login != login_before_last_save.downcase new_pseud = pseuds.where(name: login).first - #If the user does not have an existing pseud for the new login + # If the user does not have an existing pseud for the new login if new_pseud.blank? - #If the pseud for the old login doesn't exist - if !pseud_to_update.present? + # If the pseud for the old login doesn't exist + unless pseud_to_update.present? # shouldn't be able to get here, but just in case Pseud.create!(name: login, user_id: id) end @@ -553,7 +553,7 @@ def update_pseud_name end end pseud_to_update.name = login - pseud_to_update.save!(validate:justification_enabled?) + pseud_to_update.save!(validate: justification_enabled?) end def reindex_user_creations_after_rename From 1d044cc8fdd190e4fdf75d8233eaaf39eb62d895 Mon Sep 17 00:00:00 2001 From: Dobe-Time Date: Sat, 3 Jan 2026 14:45:21 -0800 Subject: [PATCH 4/6] AO3-6359 Fixing conditional statement style issue for Rubocop --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 85db58e405..647d9c8940 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -544,7 +544,7 @@ def update_pseud_name # If the user does not have an existing pseud for the new login if new_pseud.blank? # If the pseud for the old login doesn't exist - unless pseud_to_update.present? + if pseud_to_update.blank? # shouldn't be able to get here, but just in case Pseud.create!(name: login, user_id: id) end From cad132df5b1b8acddfded71b3b854903fffd766a Mon Sep 17 00:00:00 2001 From: Eagersheepy Date: Mon, 2 Feb 2026 18:08:57 -0800 Subject: [PATCH 5/6] AO3-6359: Additional pseud testing and user.rb fixes --- app/models/user.rb | 19 +++++++++---------- spec/models/user_spec.rb | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 2893d10f65..bc8034b2ca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -551,17 +551,16 @@ def update_pseud_name pseud_to_update = pseuds.where(name: login_before_last_save).first # If the new login is (case insensitive) different from the old login - if login != login_before_last_save.downcase + if login.downcase != login_before_last_save.downcase new_pseud = pseuds.where(name: login).first - # If the user does not have an existing pseud for the new login - if new_pseud.blank? - # If the pseud for the old login doesn't exist - if pseud_to_update.blank? - # shouldn't be able to get here, but just in case - Pseud.create!(name: login, user_id: id) - end - else - pseud_to_update = new_pseud + # If the user does have an existing pseud for the new login + if new_pseud.present? + pseud_to_update = new_pseud + # If the pseud for the old login doesn't exist + elsif pseud_to_update.blank? + # shouldn't be able to get here, but just in case + Pseud.create!(name: login, user_id: id) + return end end pseud_to_update.name = login diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e33c452118..d5f8e25968 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -395,7 +395,7 @@ end end - context "username was changed to match an existing pseud's name except with alternate capitalization and diacritics" do + context "username was changed to match an existing pseud's name except downcased" do let(:new_pseud) { build(:pseud, name: "New_Usernamé") } before do @@ -411,6 +411,41 @@ expect(existing_user.login).to eq("new_username") end end + + context "username was changed to match an existing pseud's name with mixed capitalization and diacritics" do + let(:new_pseud) { build(:pseud, name: "New_Usernamé") } + + before do + existing_user.pseuds << new_pseud + existing_user.update!(login: "new_UsernaMe") + existing_user.reload + end + + it "pseud's capitalization and diacritics were changed to match the new username's" do + expect(existing_user.pseuds.size).to eq(2) + expect(existing_user.pseuds.second.name).to eq(existing_user.login) + expect(existing_user.pseuds.second.name).to eq("new_UsernaMe") + expect(existing_user.login).to eq("new_UsernaMe") + end + end + + context "username was changed to not match an existing pseud's name, and the users has no psueds" do + let(:new_pseud) { build(:pseud, name: "New_Usernamé") } + + before do + existing_user.pseuds = Array.new + + existing_user.update!(login: "new_UsernaMe") + existing_user.reload + end + + it "creates a new pseud for the users new login" do + expect(existing_user.pseuds.size).to eq(1) + expect(existing_user.pseuds.first.name).to eq(existing_user.login) + expect(existing_user.pseuds.first.name).to eq("new_UsernaMe") + expect(existing_user.login).to eq("new_UsernaMe") + end + end end describe ".search_multiple_by_email" do From 1d6da0572883498f35983272def369c05810f246 Mon Sep 17 00:00:00 2001 From: Eagersheepy Date: Mon, 2 Feb 2026 18:54:05 -0800 Subject: [PATCH 6/6] AO3-6359: RuboCop fixes for extra space and array creation. --- app/models/user.rb | 2 +- spec/models/user_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index bc8034b2ca..19610a7c3c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -555,7 +555,7 @@ def update_pseud_name new_pseud = pseuds.where(name: login).first # If the user does have an existing pseud for the new login if new_pseud.present? - pseud_to_update = new_pseud + pseud_to_update = new_pseud # If the pseud for the old login doesn't exist elsif pseud_to_update.blank? # shouldn't be able to get here, but just in case diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d5f8e25968..7b15795cd6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -433,7 +433,7 @@ let(:new_pseud) { build(:pseud, name: "New_Usernamé") } before do - existing_user.pseuds = Array.new + existing_user.pseuds = [] existing_user.update!(login: "new_UsernaMe") existing_user.reload