-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Logic for deletion * Test for removing a publisher * Test against versions * Allow admins to delete * Allow admin to delete users. Closes #751 * Performance and readability improvements * Performance improvements and bugfix for publisher test * Change the way we save deleted ip addresses * Add deleted state back in
- Loading branch information
1 parent
b8ed4ef
commit 9002ded
Showing
8 changed files
with
106 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class PublisherRemovalJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(publisher_id:) | ||
publisher = Publisher.find_by(id: publisher_id) | ||
return if publisher.suspended? | ||
publisher.status_updates.create(status: PublisherStatusUpdate::DELETED) | ||
ActiveRecord::Base.transaction do | ||
publisher.update(email: nil) | ||
publisher.update(pending_email: nil) | ||
publisher.update(name: PublisherStatusUpdate::DELETED) | ||
publisher.update(phone: nil) | ||
publisher.update(phone_normalized: nil) | ||
# If they're signed in, they should not longer be signed in | ||
publisher.user_authentication_token.update(authentication_token_expires_at: Time.now) if publisher.user_authentication_token.present? | ||
publisher.update(current_sign_in_ip: nil) | ||
publisher.update(last_sign_in_ip: nil) | ||
end | ||
publisher.channels.pluck(:id).each do |channel_id| | ||
DeletePublisherChannelJob.perform_now(channel_id: channel_id) | ||
end | ||
|
||
# Paper trail retains all records: we destroy all historical PII and non-PII | ||
publisher.versions.destroy_all | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'test_helper' | ||
|
||
class PublisherRemovalJobTest < ActiveJob::TestCase | ||
|
||
test "deletes a publisher and his or her channels" do | ||
publisher = publishers(:google_verified) | ||
assert_not_equal 0, publisher.channels.count | ||
PublisherRemovalJob.perform_now(publisher_id: publisher.id) | ||
publisher.reload | ||
assert_nil publisher.email | ||
assert_nil publisher.pending_email | ||
assert_equal PublisherStatusUpdate::DELETED, publisher.name | ||
assert_nil publisher.last_sign_in_ip | ||
assert_nil publisher.current_sign_in_ip | ||
assert_equal 0, publisher.channels.count | ||
assert_equal 0, publisher.versions.count | ||
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
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