From c8cb063416f11bcb1b27640eadfaa64e7bdd3f03 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 12 Feb 2025 21:38:43 -0800 Subject: [PATCH 1/5] AO3-4250 Made gift recipients update on blurbs on pseud / username changes --- app/models/pseud.rb | 14 +++- app/models/user.rb | 4 + features/other_a/pseud_delete.feature | 31 +++++++ features/other_a/pseuds.feature | 24 ++++++ features/step_definitions/pseud_steps.rb | 2 +- features/users/user_delete.feature | 23 ++++++ features/users/user_rename.feature | 101 +++++++++++++++++++---- 7 files changed, 179 insertions(+), 20 deletions(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 6dca5d7641b..267005d49d1 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -76,6 +76,7 @@ class Pseud < ApplicationRecord after_update :check_default_pseud after_update :expire_caches after_commit :reindex_creations, :touch_comments + after_destroy :expire_caches scope :alphabetical, -> { order(:name) } scope :default_alphabetical, -> { order(is_default: :desc).alphabetical } @@ -390,9 +391,16 @@ def check_default_pseud end def expire_caches - if saved_change_to_name? - works.touch_all - series.each(&:expire_byline_cache) + return unless saved_change_to_name? || (destroyed? && user != nil && user.default_pseud != nil) + pseud = if destroyed? then user.default_pseud else self end + pseud.series.each(&:expire_byline_cache) + pseud.works.each do |work| + work.touch + work.expire_caches + end + pseud.gift_works.each do |work| + work.touch + work.expire_caches end end diff --git a/app/models/user.rb b/app/models/user.rb index 47c6c6b3d04..d967a757bc6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -166,6 +166,10 @@ def expire_caches work.touch work.expire_caches end + self.gift_works.each do |work| + work.touch + work.expire_caches + end end def remove_user_from_kudos diff --git a/features/other_a/pseud_delete.feature b/features/other_a/pseud_delete.feature index 14e3ffafca2..e69f8a63468 100644 --- a/features/other_a/pseud_delete.feature +++ b/features/other_a/pseud_delete.feature @@ -202,3 +202,34 @@ Feature: Delete pseud. Then I should see "My Collection Thing" And I should not see "other_pseud (myself)" within "#main" And I should see "myself" within "#main" + + Scenario: Deleting a pseud updates series blurbs + + Given I am logged in as "Myself" + And I add the work "Great Work" to series "Best Series" as "Me2" + When I go to the dashboard page for user "Myself" with pseud "Me2" + And I follow "Series" + Then I should see "Best Series by Me2 (Myself)" + + When I delete the pseud "Me2" + And I follow "Series" + Then I should see "Best Series by Myself" + + Scenario: Deleting a pseud updates gift blurbs + Given I have no users + And the following activated users exist + | login | password | email | id | + | gifter | something | gifter@example.com | 1 | + | giftee1 | something | giftee1@example.com | 2 | + And a pseud exists with name: "Me2", user_id: 2 + And the user "giftee1" allows gifts + And I am logged in as "gifter" with password "something" + And I set up the draft "GiftStory1" + And I give the work to "Me2 (giftee1)" + And I press "Post" + And I am logged in as "giftee1" with password "something" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for Me2 (giftee1)" + When I delete the pseud "Me2" + And I go to my gifts page + Then I should see "GiftStory1 by gifter for giftee1" diff --git a/features/other_a/pseuds.feature b/features/other_a/pseuds.feature index 37826b9d433..c1fcf21e475 100644 --- a/features/other_a/pseuds.feature +++ b/features/other_a/pseuds.feature @@ -253,6 +253,30 @@ Scenario: Edit pseud updates series blurbs When I follow "Series" Then I should see "Best Series by Me3 (Myself)" +Scenario: Edit pseud updates gift blurbs + Given I have no users + And the following activated users exist + | login | password | email | id | + | gifter | something | gifter@example.com | 1 | + | giftee1 | something | giftee1@example.com | 2 | + And a pseud exists with name: "Me2", user_id: 2 + And the user "giftee1" allows gifts + And I am logged in as "gifter" with password "something" + And I set up the draft "GiftStory1" + And I give the work to "Me2 (giftee1)" + And I press "Post" + And I am logged in as "giftee1" with password "something" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for Me2 (giftee1)" + When I go to my profile page + And I follow "Manage My Pseuds" + And I follow "Edit Me2" + And I fill in "Name" with "Me3" + And I press "Update" + Then I should see "Pseud was successfully updated." + When I go to my gifts page + Then I should see "GiftStory1 by gifter for Me3 (giftee1)" + Scenario: Change details as an admin Given "someone" has the pseud "alt" diff --git a/features/step_definitions/pseud_steps.rb b/features/step_definitions/pseud_steps.rb index 4448d1c81b1..db6e8f8dd5b 100644 --- a/features/step_definitions/pseud_steps.rb +++ b/features/step_definitions/pseud_steps.rb @@ -29,7 +29,7 @@ When(/^I delete the pseud "([^\"]*)"$/) do |pseud| visit user_pseuds_path(User.current_user) - click_link("delete_#{pseud}") + click_link("delete_#{pseud.downcase}") end When /^"([^\"]*)" creates the default pseud "([^"]*)"$/ do |username, newpseud| diff --git a/features/users/user_delete.feature b/features/users/user_delete.feature index e47f9a1af54..2f970a8c214 100644 --- a/features/users/user_delete.feature +++ b/features/users/user_delete.feature @@ -117,3 +117,26 @@ Scenario: Delete a user who has coauthored a work And a user account should not exist for "testuser" When I go to orphan_account's series page Then I should see "Epic" + + Scenario: Deleting a user updates gift blurbs + Given I have no users + And I have no works or comments + And the following activated users exist + | login | password | email | id | + | gifter | something | gifter@example.com | 1 | + | giftee1 | something | giftee1@example.com | 2 | + And the user "giftee1" allows gifts + And I am logged in as "gifter" with password "something" + And I set up the draft "GiftStory1" + And I give the work to "giftee1" + And I press "Post" + And I am logged in as "giftee1" with password "something" + When I am on gifter's works page + Then I should see "GiftStory1 by gifter for giftee1" + When I try to delete my account as giftee1 + Then I should see "You have successfully deleted your account." + And a user account should not exist for "giftee1" + And I should be logged out + When I am on gifter's works page + Then I should see "GiftStory1 by gifter" + And I should not see "GiftStory1 by gifter for giftee1" diff --git a/features/users/user_rename.feature b/features/users/user_rename.feature index 98c9ee4c587..13d6440935b 100644 --- a/features/users/user_rename.feature +++ b/features/users/user_rename.feature @@ -182,35 +182,104 @@ Feature: And I should see "after" within "#main" And I should not see "before" within "#main" - Scenario: Changing username updates series blurbs + Scenario: Changing only username updates series blurbs Given I have no users - And I am logged in as "oldusername" with password "password" + And the following activated user exists + | login | password | id | + | oldusername | secret | 1 | + And a pseud exists with name: "newusername", user_id: 1 + And I am logged in as "oldusername" with password "secret" And I add the work "Great Work" to series "Best Series" When I go to the dashboard page for user "oldusername" with pseud "oldusername" And I follow "Series" Then I should see "Best Series by oldusername" When I visit the change username page for oldusername And I fill in "New user name" with "newusername" - And I fill in "Password" with "password" + And I fill in "Password" with "secret" + And I press "Change User Name" + Then I should get confirmation that I changed my username + And I should see "Hi, newusername" + When I follow "Series" + Then I should see "Best Series by oldusername (newusername)" + + Scenario: Changing username and pseud updates series blurbs + Given I have no users + And I am logged in as "oldusername" with password "secret" + And I add the work "Great Work" to series "Best Series" + When I go to the dashboard page for user "oldusername" with pseud "oldusername" + And I follow "Series" + Then I should see "Best Series by oldusername" + When I visit the change username page for oldusername + And I fill in "New user name" with "newusername" + And I fill in "Password" with "secret" And I press "Change User Name" Then I should get confirmation that I changed my username And I should see "Hi, newusername" When I follow "Series" Then I should see "Best Series by newusername" + And I should not see "Best Series by oldusername" + + Scenario: Changing only username updates gift blurbs + Given I have no users + And the following activated users exist + | login | password | email | id | + | gifter | something | gifter@example.com | 1 | + | giftee1 | something | giftee1@example.com | 2 | + And a pseud exists with name: "newusername", user_id: 2 + And the user "giftee1" allows gifts + And I am logged in as "gifter" with password "something" + And I set up the draft "GiftStory1" + And I give the work to "giftee1" + And I press "Post" + And I am logged in as "giftee1" with password "something" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for giftee1" + When I visit the change username page for giftee1 + And I fill in "New user name" with "newusername" + And I fill in "Password" with "something" + And I press "Change User Name" + Then I should get confirmation that I changed my username + And I should see "Hi, newusername" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for giftee1 (newusername)" - Scenario: Changing the username from a forbidden name to non-forbidden - Given I have no users - And the following activated user exists - | login | password | - | forbidden | secret | - And the user name "forbidden" is on the forbidden list - When I am logged in as "forbidden" with password "secret" - And I visit the change username page for forbidden - And I fill in "New user name" with "notforbidden" - And I fill in "Password" with "secret" - And I press "Change User Name" - Then I should get confirmation that I changed my username - And I should see "Hi, notforbidden" + Scenario: Changing username and pseud updates gift blurbs + Given I have no users + And the following activated users exist + | login | password | email | id | + | gifter | something | gifter@example.com | 1 | + | giftee1 | something | giftee1@example.com | 2 | + And the user "giftee1" allows gifts + And I am logged in as "gifter" with password "something" + And I set up the draft "GiftStory1" + And I give the work to "giftee1" + And I press "Post" + And I am logged in as "giftee1" with password "something" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for giftee1" + When I visit the change username page for giftee1 + And I fill in "New user name" with "newusername" + And I fill in "Password" with "something" + And I press "Change User Name" + Then I should get confirmation that I changed my username + And I should see "Hi, newusername" + When I go to my gifts page + Then I should see "GiftStory1 by gifter for newusername" + And I should not see "GiftStory1 by gifter for giftee1" + + Scenario: Changing the username from a forbidden name to non-forbidden + Given I have no users + And the following activated user exists + | login | password | + | forbidden | secret | + And the user name "forbidden" is on the forbidden list + When I am logged in as "forbidden" with password "secret" + And I visit the change username page for forbidden + And I fill in "New user name" with "notforbidden" + And I fill in "Password" with "secret" + And I press "Change User Name" + Then I should get confirmation that I changed my username + And I should see "Hi, notforbidden" Scenario: Tag wrangling supervisors are emailed about tag wrangler username changes Given the user "before" exists and is activated From 5829463969138b602fc98bb434eb252d85997416 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 12 Feb 2025 21:54:10 -0800 Subject: [PATCH 2/5] AO3-4250 feed the rubodog --- app/models/pseud.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 267005d49d1..82e53152f5c 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -75,8 +75,8 @@ class Pseud < ApplicationRecord after_update :check_default_pseud after_update :expire_caches - after_commit :reindex_creations, :touch_comments after_destroy :expire_caches + after_commit :reindex_creations, :touch_comments scope :alphabetical, -> { order(:name) } scope :default_alphabetical, -> { order(is_default: :desc).alphabetical } @@ -391,8 +391,8 @@ def check_default_pseud end def expire_caches - return unless saved_change_to_name? || (destroyed? && user != nil && user.default_pseud != nil) - pseud = if destroyed? then user.default_pseud else self end + return unless saved_change_to_name? || (destroyed? && !user.nil? && !user.default_pseud.nil?) + pseud = destroyed? ? user.default_pseud : self pseud.series.each(&:expire_byline_cache) pseud.works.each do |work| work.touch From 3b331488c411ae0961dd20b909c7c497efb049af Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 12 Feb 2025 22:18:26 -0800 Subject: [PATCH 3/5] AO3-4250 feed the rubodog a bit more --- app/models/pseud.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 82e53152f5c..255bad73ced 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -392,6 +392,7 @@ def check_default_pseud def expire_caches return unless saved_change_to_name? || (destroyed? && !user.nil? && !user.default_pseud.nil?) + pseud = destroyed? ? user.default_pseud : self pseud.series.each(&:expire_byline_cache) pseud.works.each do |work| From 5b3cd90533eb633cb95468e731c2d5c51c1a4e5a Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 12 Feb 2025 22:22:33 -0800 Subject: [PATCH 4/5] AO3-4250 protect better against nils --- app/models/pseud.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 255bad73ced..b7c83f97bca 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -391,9 +391,11 @@ def check_default_pseud end def expire_caches - return unless saved_change_to_name? || (destroyed? && !user.nil? && !user.default_pseud.nil?) + return unless saved_change_to_name? || (destroyed? && !user.nil?) pseud = destroyed? ? user.default_pseud : self + return unless !pseud.nil? + pseud.series.each(&:expire_byline_cache) pseud.works.each do |work| work.touch From 087929ab7f8711bb3da478a9fcca1df02c17748c Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Thu, 13 Feb 2025 06:50:54 -0800 Subject: [PATCH 5/5] Feed rubodog --- app/models/pseud.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index b7c83f97bca..f389f9e918e 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -394,7 +394,7 @@ def expire_caches return unless saved_change_to_name? || (destroyed? && !user.nil?) pseud = destroyed? ? user.default_pseud : self - return unless !pseud.nil? + return if pseud.nil? pseud.series.each(&:expire_byline_cache) pseud.works.each do |work|