Skip to content
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

Merged
merged 7 commits into from
Jul 26, 2018
Merged

Conversation

sarken
Copy link
Member

@sarken sarken commented Jul 16, 2018

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.

puts " #{change}"
end
end

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.

puts
puts "User Agents:"
user_agents.uniq.map do |user_agent|
puts " #{user_agent}"

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.


# List of user agents
user_agents = []
u.comments.pluck(:user_agent)&.map { |ua| user_agents << ua if !ua.blank? }

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.

# 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? }

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.

# 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? }

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.


# Names of people listing user as their FNOK
next_of_kin_for = []
FannishNextOfKin.where(kin_id: u.id)&.pluck(:user_id).map do |id|

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.


# 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|

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.

# 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|

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.


# URLs of all comments
comment_urls = []
u.comments&.pluck(:id).map do |id|

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

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.

Copy link
Member

@redsummernight redsummernight left a 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.

# URLs of all comments
comment_urls = []
u.comments.pluck(:id)&.map do |id|
comment_urls << "#{comments_url}/#{id}"
Copy link
Member

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).

# 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}"
Copy link
Member

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).

unless collection_roles.empty?
f.puts "Collection Roles: "
collection_roles.map do |role|
f.puts " #{role}"

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.

f.puts "Collections: #{user_collections_url(u)}"
unless collection_roles.empty?
f.puts "Collection Roles: "
collection_roles.map do |role|

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.

f.puts
f.puts "Collections: #{user_collections_url(u)}"
unless collection_roles.empty?
f.puts "Collection Roles: "

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.


filename_and_path = "/tmp/user_data_for_#{u.login}_#{todays_date}.txt"

open(filename_and_path, "w") { |f|

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|

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.

# URLs of all comments
comment_urls = []
u.comments.pluck(:id)&.map do |id|
comment_urls << "#{comment_url(id)}"

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|

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}"

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|

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]

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}"
Copy link
Member

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants