Remove diaspora_handle from AccountDeletions and add unique index
This commit is contained in:
parent
fa0b78f5a2
commit
245ad9e04d
8 changed files with 38 additions and 31 deletions
|
|
@ -5,23 +5,15 @@
|
||||||
class AccountDeletion < ApplicationRecord
|
class AccountDeletion < ApplicationRecord
|
||||||
include Diaspora::Federated::Base
|
include Diaspora::Federated::Base
|
||||||
|
|
||||||
scope :uncompleted, -> { where('completed_at is null') }
|
scope :uncompleted, -> { where("completed_at is null") }
|
||||||
|
|
||||||
belongs_to :person
|
belongs_to :person
|
||||||
after_commit :queue_delete_account, :on => :create
|
after_commit :queue_delete_account, on: :create
|
||||||
|
|
||||||
def person=(person)
|
delegate :diaspora_handle, to: :person
|
||||||
self[:diaspora_handle] = person.diaspora_handle
|
|
||||||
self[:person_id] = person.id
|
|
||||||
end
|
|
||||||
|
|
||||||
def diaspora_handle=(diaspora_handle)
|
|
||||||
self[:diaspora_handle] = diaspora_handle
|
|
||||||
self[:person_id] ||= Person.find_by_diaspora_handle(diaspora_handle).id
|
|
||||||
end
|
|
||||||
|
|
||||||
def queue_delete_account
|
def queue_delete_account
|
||||||
Workers::DeleteAccount.perform_async(self.id)
|
Workers::DeleteAccount.perform_async(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform!
|
def perform!
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,7 @@ class User < ApplicationRecord
|
||||||
def close_account!
|
def close_account!
|
||||||
self.person.lock_access!
|
self.person.lock_access!
|
||||||
self.lock_access!
|
self.lock_access!
|
||||||
AccountDeletion.create(:person => self.person)
|
AccountDeletion.create(person: person)
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed_account?
|
def closed_account?
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
class CleanupAccountDeletionsAndAddUniqueIndex < ActiveRecord::Migration[5.1]
|
||||||
|
def up
|
||||||
|
remove_column :account_deletions, :diaspora_handle
|
||||||
|
|
||||||
|
duplicate_query = "WHERE a1.person_id = a2.person_id AND a1.id > a2.id"
|
||||||
|
if AppConfig.postgres?
|
||||||
|
execute("DELETE FROM account_deletions AS a1 USING account_deletions AS a2 #{duplicate_query}")
|
||||||
|
else
|
||||||
|
execute("DELETE a1 FROM account_deletions a1, account_deletions a2 #{duplicate_query}")
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :account_deletions, :person_id, name: :index_account_deletions_on_person_id, unique: true
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :account_deletions, name: :index_account_deletions_on_person_id
|
||||||
|
add_column :account_deletions, :diaspora_handle, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -106,6 +106,6 @@ class AccountDeleter
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_account_deletion_complete
|
def mark_account_deletion_complete
|
||||||
AccountDeletion.where(:diaspora_handle => self.person.diaspora_handle).where(:person_id => self.person.id).update_all(["completed_at = ?", Time.now])
|
AccountDeletion.find_by(person: person)&.update_attributes(completed_at: Time.now.utc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.account_deletion(entity)
|
def self.account_deletion(entity)
|
||||||
AccountDeletion.create!(person: author_of(entity), diaspora_handle: entity.author)
|
AccountDeletion.create!(person: author_of(entity))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.comment(entity)
|
def self.comment(entity)
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,6 @@ FactoryGirl.define do
|
||||||
|
|
||||||
factory :account_deletion do
|
factory :account_deletion do
|
||||||
association :person
|
association :person
|
||||||
after(:build) do |delete|
|
|
||||||
delete.diaspora_handle = delete.person.diaspora_handle
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :like do
|
factory :like do
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,19 @@ describe "Receive federation messages feature" do
|
||||||
context "with public receive" do
|
context "with public receive" do
|
||||||
let(:recipient) { nil }
|
let(:recipient) { nil }
|
||||||
|
|
||||||
|
context "account deletion" do
|
||||||
it "receives account deletion correctly" do
|
it "receives account deletion correctly" do
|
||||||
post_message(generate_payload(DiasporaFederation::Entities::AccountDeletion.new(diaspora_id: sender_id), sender))
|
post_message(generate_payload(DiasporaFederation::Entities::AccountDeletion.new(author: sender_id), sender))
|
||||||
|
|
||||||
expect(AccountDeletion.exists?(diaspora_handle: sender_id)).to be_truthy
|
expect(AccountDeletion.exists?(person: sender.person)).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it "rejects account deletion with wrong diaspora_id" do
|
it "rejects account deletion with wrong author" do
|
||||||
delete_id = Fabricate.sequence(:diaspora_id)
|
delete_id = Fabricate.sequence(:diaspora_id)
|
||||||
post_message(generate_payload(DiasporaFederation::Entities::AccountDeletion.new(diaspora_id: delete_id), sender))
|
expect {
|
||||||
|
post_message(generate_payload(DiasporaFederation::Entities::AccountDeletion.new(author: delete_id), sender))
|
||||||
expect(AccountDeletion.exists?(diaspora_handle: delete_id)).to be_falsey
|
}.not_to change(AccountDeletion, :count)
|
||||||
expect(AccountDeletion.exists?(diaspora_handle: sender_id)).to be_falsey
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "reshare" do
|
context "reshare" do
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ describe Diaspora::Federation::Receive do
|
||||||
it "saves the account deletion" do
|
it "saves the account deletion" do
|
||||||
Diaspora::Federation::Receive.account_deletion(account_deletion_entity)
|
Diaspora::Federation::Receive.account_deletion(account_deletion_entity)
|
||||||
|
|
||||||
account_deletion = AccountDeletion.find_by!(diaspora_handle: sender.diaspora_handle)
|
expect(AccountDeletion.exists?(person: sender)).to be_truthy
|
||||||
|
|
||||||
expect(account_deletion.person).to eq(sender)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue