-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AO3-6467 Record Fannish Next of Kin changes in user history (#4582)
* Adding https://otwarchive.atlassian.net/browse/AO3-6467 * Remove * Replace many ifelse with case * Display logs on admin page * Forgot to log admin identity * Also show logs on the FNOK side * Test for display Keeping it simple by not checking id for now * Add Alterity * Forgot to commit previously * Hound * Hound (bis) * Hound (ter) * Add i18n keys to exceptions * Remove Alterity actually Superseded by #4528 * Add pt-online-schema-change syntax for prod * Remove explicit foreign key Similar migrations don't appear to set one * Implicit NULL default value * Test id too * Add user destroy controller test Apparently didn't exist before? * Log automatic removal of fnok on deletion * Hound * Use classical I18n syntax * Simplify fnok name action * Clean other I18n keys * Hound * reviewdog * Normalize i18n * Syntax more compliant with i18n-tasks * Wordings * Explicit over succinct
- Loading branch information
Showing
15 changed files
with
244 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
db/migrate/20230717161221_add_fnok_user_id_to_log_items.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class AddFnokUserIdToLogItems < ActiveRecord::Migration[6.1] | ||
def up | ||
if Rails.env.staging? || Rails.env.production? | ||
database = LogItem.connection.current_database | ||
|
||
puts <<~PTOSC | ||
Schema Change Command: | ||
pt-online-schema-change D=#{database},t=log_items \\ | ||
--alter "ADD `fnok_user_id` int, | ||
ADD INDEX `index_log_items_on_fnok_user_id` (`fnok_user_id`)" \\ | ||
--no-drop-old-table \\ | ||
-uroot --ask-pass --chunk-size=5k --max-flow-ctl 0 --pause-file /tmp/pauseme \\ | ||
--max-load Threads_running=15 --critical-load Threads_running=100 \\ | ||
--set-vars innodb_lock_wait_timeout=2 --alter-foreign-keys-method=auto \\ | ||
--execute | ||
Table Deletion Command: | ||
DROP TABLE IF EXISTS `#{database}`.`_log_items_old`; | ||
PTOSC | ||
else | ||
add_column :log_items, :fnok_user_id, :integer, nullable: true | ||
add_index :log_items, :fnok_user_id | ||
end | ||
end | ||
|
||
def down | ||
if Rails.env.staging? || Rails.env.production? | ||
database = LogItem.connection.current_database | ||
|
||
puts <<~PTOSC | ||
Schema Change Command: | ||
pt-online-schema-change D=#{database},t=log_items \\ | ||
--alter "DROP COLUMN `fnok_user_id`"\\ | ||
--no-drop-old-table \\ | ||
-uroot --ask-pass --chunk-size=5k --max-flow-ctl 0 --pause-file /tmp/pauseme \\ | ||
--max-load Threads_running=15 --critical-load Threads_running=100 \\ | ||
--set-vars innodb_lock_wait_timeout=2 --alter-foreign-keys-method=auto \\ | ||
--execute | ||
Table Deletion Command: | ||
DROP TABLE IF EXISTS `#{database}`.`_log_items_old`; | ||
PTOSC | ||
else | ||
remove_column :log_items, :fnok_user_id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "faker" | ||
|
||
FactoryBot.define do | ||
factory :fannish_next_of_kin do | ||
user { create(:user) } | ||
kin { create(:user) } | ||
kin_email { |u| u.kin.email } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Feature: Admin Fannish Next Of Kind actions | |
And I fill in "Fannish next of kin's email" with "[email protected]" | ||
And I press "Update Fannish Next of Kin" | ||
Then I should see "Fannish next of kin was updated." | ||
And the history table should show that "libby" was added as next of kin | ||
|
||
When I go to the manage users page | ||
And I fill in "Name" with "harrykim" | ||
|
@@ -24,6 +25,9 @@ Feature: Admin Fannish Next Of Kind actions | |
When I follow "libby" | ||
Then I should be on libby's user page | ||
|
||
When I go to the user administration page for "libby" | ||
Then the history table should show they were added as next of kin of "harrykim" | ||
|
||
Scenario: An invalid Fannish Next of Kin username is added | ||
Given the fannish next of kin "libby" for the user "harrykim" | ||
And I am logged in as a "support" admin | ||
|
@@ -66,6 +70,9 @@ Feature: Admin Fannish Next Of Kind actions | |
And I fill in "Fannish next of kin's email" with "" | ||
And I press "Update Fannish Next of Kin" | ||
Then I should see "Fannish next of kin was removed." | ||
And the history table should show that "libby" was removed as next of kin | ||
When I go to the user administration page for "libby" | ||
Then the history table should show they were removed as next of kin of "harrykim" | ||
|
||
Scenario: A Fannish Next of Kin updates when the next of kin user changes their username | ||
Given the fannish next of kin "libby" for the user "harrykim" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.