Update user IDs when logged in kudos are changed

Description

Add callbacks to:

  • Save user IDs when new logged in kudos are created.

  • Remove user IDs from kudos when users are deleted (similar to pseud IDs).

We don't need to do anything when users change/remove their default pseuds because the user IDs would stay the same in that case.

There is a separate issue to fill in user IDs for existing logged in kudos: AO3-5851.

How to test: user IDs on kudos are not yet displayed on the site in any way, so admins will need to check on a Rails console that user IDs are saved correctly on:

  • New logged in kudos.

  • New logged in kudos after a default pseud change (same user ID).

  • Logged in kudos after users are removed.

And that user IDs are not saved on guest kudos.

Activity

Show:
Sarken
January 29, 2020, 6:54 AM
  • Created account sarkenkudos, user_id: 60, default_pseud_id: 76

  • Left kudos on work, name displayed normally (“sarkenkudos”), database correctly showed #<Kudo id: 20, pseud_id: 76, commentable_id: 152, commentable_type: "Work", created_at: "2020-01-29 06:48:31", updated_at: "2020-01-29 06:48:31", ip_address: nil, user_id: 60>

  • Added the default pseud Sarken to that account, making default_pseud_id: 77

  • Left kudos on a different work, name displayed normally (“Sarken (sarkenkudos)”), database correctly showed #<Kudo id: 21, pseud_id: 77, commentable_id: 154, commentable_type: "Work", created_at: "2020-01-29 06:50:57", updated_at: "2020-01-29 06:50:57", ip_address: nil, user_id: 60>

  • Deleted account and both kudos had the user_id and pseud_id correctly set to nil:

All looks good to me! (The kudos section on the first work didn’t update, so my name is still there, but that happens sometimes and isn’t a new bug.)

james_
February 7, 2020, 6:35 AM

2.6.5 :017 > u=User.last
=> #<User id: 67, created_at: "2020-02-07 06:19:54", updated_at: "2020-02-07 06:30:19", email: "james_@catbus.co.uk", login: "james_temp", suspended: false, banned: false, invitation_id: nil, suspended_until: nil, out_of_invites: true, accepted_tos_version: 20180523>
2.6.5 :018 > Pseud.last
=> #<Pseud id: 89, user_id: 67, name: "james_temp", description: nil, is_default: true, created_at: "2020-02-07 06:19:54", updated_at: "2020-02-07 06:19:54", icon_file_name: nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: nil, icon_alt_text: "", delta: true, description_sanitizer_version: 0, icon_comment_text: "">
2.6.5 :019 >

 

Left kudos on work “james_temp left kudos on this work!”

2.6.5 :019 > Kudo.last
=> #<Kudo id: 24, pseud_id: 89, commentable_id: 158, commentable_type: "Work", created_at: "2020-02-07 06:32:06", updated_at: "2020-02-07 06:32:06", ip_address: nil, user_id: 67>

 

Created a new pseud.

2.6.5 :021 > Pseud.last
=> #<Pseud id: 90, user_id: 67, name: "james", description: "", is_default: false, created_at: "2020-02-07 06:34:09", updated_at: "2020-02-07 06:34:09", icon_file_name: nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: nil, icon_alt_text: "", delta: true, description_sanitizer_version: 1, icon_comment_text: "">
2.6.5 :022 >

james_
February 7, 2020, 6:47 AM

Managed to kudos a work with the new psued

2.6.5 :023 > Kudo.last
=> #<Kudo id: 27, pseud_id: 90, commentable_id: 157, commentable_type: "Work", created_at: "2020-02-07 06:39:36", updated_at: "2020-02-07 06:39:36", ip_address: nil, user_id: 67>

Displayed correctly “james (james_temp) left kudos on this work!”

After a quick google

Account deleted!

Your account has been deleted. Thank you for using the Archive, and we hope to see you again someday.

If you orphaned your works, thank you for your generosity.

 

2.6.5 :023 > Kudo.last
=> #<Kudo id: 27, pseud_id: 90, commentable_id: 157, commentable_type: "Work", created_at: "2020-02-07 06:39:36", updated_at: "2020-02-07 06:39:36", ip_address: nil, user_id: 67>
2.6.5 :024 > Kudo.find(27)
=> #<Kudo id: 27, pseud_id: nil, commentable_id: 157, commentable_type: "Work", created_at: "2020-02-07 06:39:36", updated_at: "2020-02-07 06:39:36", ip_address: nil, user_id: nil>
2.6.5 :025 > Kudo.find(26)
=> #<Kudo id: 26, pseud_id: nil, commentable_id: 149, commentable_type: "Work", created_at: "2020-02-07 06:36:59", updated_at: "2020-02-07 06:36:59", ip_address: nil, user_id: nil>
2.6.5 :026 > Kudo.find(25)
=> #<Kudo id: 25, pseud_id: nil, commentable_id: 154, commentable_type: "Work", created_at: "2020-02-07 06:36:19", updated_at: "2020-02-07 06:36:19", ip_address: nil, user_id: nil>
2.6.5 :027 > Kudo.find(24)
=> #<Kudo id: 24, pseud_id: nil, commentable_id: 158, commentable_type: "Work", created_at: "2020-02-07 06:32:06", updated_at: "2020-02-07 06:32:06", ip_address: nil, user_id: nil>

 

Flushed memcached and kudos turned up on works

 

Looks good to me

DeployedToBeta

Assignee

redsummernight

Reporter

redsummernight

Roadmap

Misc

Priority

Medium

Affects versions

Fix versions

Components

BackEnd

Difficulty

Medium

Milestone

Internal 0.9
Configure