-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AO3-5486 Script for getting user data #3393
Conversation
script/get_user_data.rb
Outdated
puts " #{change}" | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingBlankLines: 1 trailing blank lines detected.
script/get_user_data.rb
Outdated
puts | ||
puts "User Agents:" | ||
user_agents.uniq.map do |user_agent| | ||
puts " #{user_agent}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
script/get_user_data.rb
Outdated
|
||
# List of user agents | ||
user_agents = [] | ||
u.comments.pluck(:user_agent)&.map { |ua| user_agents << ua if !ua.blank? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
script/get_user_data.rb
Outdated
# Don't include IPs from the audits table because some IPs may be admins' | ||
ips = [] | ||
u.comments.pluck(:ip_address)&.map { |ip| ips << ip if !ip.blank? } | ||
u.works.pluck(:ip_address)&.map { |ip| ips << ip if !ip.blank? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
script/get_user_data.rb
Outdated
# List of IP addresses | ||
# Don't include IPs from the audits table because some IPs may be admins' | ||
ips = [] | ||
u.comments.pluck(:ip_address)&.map { |ip| ips << ip if !ip.blank? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/NegatedIf: Favor unless over if for negative conditions.
script/get_user_data.rb
Outdated
|
||
# Names of people listing user as their FNOK | ||
next_of_kin_for = [] | ||
FannishNextOfKin.where(kin_id: u.id)&.pluck(:user_id).map do |id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
script/get_user_data.rb
Outdated
|
||
# URLs of all nominations made in tag sets | ||
tag_set_nomination_urls = [] | ||
TagSetNomination.where(pseud_id: u.pseuds.pluck(:id))&.pluck(:id, :owned_tag_set_id).map do |id, tag_set_id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
script/get_user_data.rb
Outdated
# URLs of all works user has kudosed | ||
# Kudos can only be on works now, but there is a pull request for admin posts | ||
kudosed_item_urls = [] | ||
u.kudos&.pluck(:commentable_type, :commentable_id).map do |type, id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
script/get_user_data.rb
Outdated
|
||
# URLs of all comments | ||
comment_urls = [] | ||
u.comments&.pluck(:id).map do |id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/SafeNavigationChain: Do not chain ordinary method call after safe navigation operator.
@@ -0,0 +1,172 @@ | |||
#!script/rails runner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/ScriptPermission: Script file get_user_data.rb doesn't have execute permission.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it locally and it looks good! Minor comments not blocking merge.
script/get_user_data.rb
Outdated
# URLs of all comments | ||
comment_urls = [] | ||
u.comments.pluck(:id)&.map do |id| | ||
comment_urls << "#{comments_url}/#{id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"#{comments_url}/#{id}"
can be comment_url(id)
.
script/get_user_data.rb
Outdated
# URLs of all nominations made in tag sets | ||
tag_set_nomination_urls = [] | ||
TagSetNomination.where(pseud_id: u.pseuds.pluck(:id)).pluck(:id, :owned_tag_set_id)&.map do |id, tag_set_id| | ||
tag_set_nomination_urls << "#{tag_sets_url}/#{tag_set_id}/nominations/#{id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be tag_set_nomination_url(tag_set_id: tag_set_id, id: id)
.
…add giant warning about deleting file
script/get_user_data.rb
Outdated
unless collection_roles.empty? | ||
f.puts "Collection Roles: " | ||
collection_roles.map do |role| | ||
f.puts " #{role}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
script/get_user_data.rb
Outdated
f.puts "Collections: #{user_collections_url(u)}" | ||
unless collection_roles.empty? | ||
f.puts "Collection Roles: " | ||
collection_roles.map do |role| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentationConsistency: Inconsistent indentation detected.
script/get_user_data.rb
Outdated
f.puts | ||
f.puts "Collections: #{user_collections_url(u)}" | ||
unless collection_roles.empty? | ||
f.puts "Collection Roles: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
script/get_user_data.rb
Outdated
|
||
filename_and_path = "/tmp/user_data_for_#{u.login}_#{todays_date}.txt" | ||
|
||
open(filename_and_path, "w") { |f| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/BlockLength: Block has too many lines. [81/25]
Security/Open: The use of Kernel#open is a serious security risk.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
|
||
# URLs of all nominations made in tag sets | ||
tag_set_nomination_urls = [] | ||
TagSetNomination.where(pseud_id: u.pseuds.pluck(:id)).pluck(:id, :owned_tag_set_id)&.map do |id, tag_set_id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnusedBlockArgument: Unused block argument - id. You can omit all the arguments if you don't care about them.
Lint/UnusedBlockArgument: Unused block argument - tag_set_id. You can omit all the arguments if you don't care about them.
script/get_user_data.rb
Outdated
# URLs of all comments | ||
comment_urls = [] | ||
u.comments.pluck(:id)&.map do |id| | ||
comment_urls << "#{comment_url(id)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
|
||
filename_and_path = "/tmp/user_data_for_#{u.login}_#{todays_date}.txt" | ||
|
||
open(filename_and_path, "w") do |f| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/BlockLength: Block has too many lines. [81/25]
Security/Open: The use of Kernel#open is a serious security risk.
"an unknown IP address" | ||
end | ||
if action == "create" | ||
account_changes << "Created account #{changes["login"]} from #{ip} on #{date}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
# admins' personal data | ||
account_changes = [] | ||
audits = u.audits.pluck(:action, :audited_changes, :created_at, :remote_address) | ||
audits.map do |audit| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/BlockLength: Block has too many lines. [26/25]
script/get_user_data.rb
Outdated
when "login" | ||
account_changes << "Changed username from #{v[0]} to #{v[1]} from #{ip} on #{date}" | ||
when "recently_reset" | ||
account_changes << "Requested password reset from from #{ip} on #{date}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra "from".
Issue
https://otwarchive.atlassian.net/browse/AO3-5486
Purpose
Adds a script that will let database admins give Policy & Abuse a pretty dump of user data when they have GDPR requests for such things.
Testing
Run the script for a viclunteer. Instructions and example output are in the issue.