diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 742ac8feafa157..c962a3e95454df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,6 +110,8 @@ RSpec/MultipleExpectations: # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 21 + Exclude: + - 'spec/services/delete_account_service_spec.rb' # Configuration parameters: AllowedGroups. RSpec/NestedGroups: diff --git a/app/models/concerns/account_associations.rb b/app/models/concerns/account_associations.rb index 94301abeb12e1b..6d85e88064f723 100644 --- a/app/models/concerns/account_associations.rb +++ b/app/models/concerns/account_associations.rb @@ -42,7 +42,6 @@ module AccountAssociations has_many :report_notes, dependent: :destroy has_many :custom_filters, inverse_of: :account, dependent: :destroy - has_many :antennas, inverse_of: :account, dependent: :destroy has_many :antenna_accounts, inverse_of: :account, dependent: :destroy # Moderation notes diff --git a/app/services/delete_account_service.rb b/app/services/delete_account_service.rb index 8f525383895ccc..59dd176ca83b9c 100644 --- a/app/services/delete_account_service.rb +++ b/app/services/delete_account_service.rb @@ -11,6 +11,8 @@ class DeleteAccountService < BaseService antennas block_relationships blocked_by_relationships + bookmark_categories + circles conversation_mutes conversations custom_filters @@ -39,6 +41,8 @@ class DeleteAccountService < BaseService account_notes account_pins aliases + antenna_accounts + circle_accounts conversation_mutes conversations custom_filters @@ -225,6 +229,7 @@ def purge_feeds! FeedManager.instance.clean_feeds!(:home, [@account.id]) FeedManager.instance.clean_feeds!(:list, @account.owned_lists.pluck(:id)) + FeedManager.instance.clean_feeds!(:antenna, @account.antennas.pluck(:id)) end def purge_profile! diff --git a/spec/fabricators/bookmark_category_fabricator.rb b/spec/fabricators/bookmark_category_fabricator.rb new file mode 100644 index 00000000000000..484d6f0692ed12 --- /dev/null +++ b/spec/fabricators/bookmark_category_fabricator.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +Fabricator(:bookmark_category) do + account { Fabricate.build(:account) } + title 'MyString' +end diff --git a/spec/fabricators/bookmark_category_status_fabricator.rb b/spec/fabricators/bookmark_category_status_fabricator.rb new file mode 100644 index 00000000000000..5f19f31da3ec5d --- /dev/null +++ b/spec/fabricators/bookmark_category_status_fabricator.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +Fabricator(:bookmark_category_status) do + bookmark_category + status + before_create do |_bookmark_category_status, _| + Bookmark.create!(status: status, account: bookmark_category.account) unless bookmark_category.account.bookmarked?(status) + end +end diff --git a/spec/services/delete_account_service_spec.rb b/spec/services/delete_account_service_spec.rb index 68ab491e4eae7c..7948bf308020f8 100644 --- a/spec/services/delete_account_service_spec.rb +++ b/spec/services/delete_account_service_spec.rb @@ -6,12 +6,19 @@ shared_examples 'common behavior' do subject { described_class.new.call(account) } + before do + account.follow!(list_target_account) + circle_target_account.follow!(account) + end + let!(:status) { Fabricate(:status, account: account) } let!(:mention) { Fabricate(:mention, account: local_follower) } let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) } let!(:media_attachment) { Fabricate(:media_attachment, account: account) } let!(:notification) { Fabricate(:notification, account: account) } let!(:favourite) { Fabricate(:favourite, account: account, status: Fabricate(:status, account: local_follower)) } + let!(:emoji_reaction) { Fabricate(:emoji_reaction, account: account, status: Fabricate(:status, account: local_follower)) } + let!(:bookmark) { Fabricate(:bookmark, account: account) } let!(:poll) { Fabricate(:poll, account: account) } let!(:poll_vote) { Fabricate(:poll_vote, account: local_follower, poll: poll) } @@ -23,8 +30,21 @@ let!(:status_notification) { Fabricate(:notification, account: local_follower, activity: status, type: :status) } let!(:poll_notification) { Fabricate(:notification, account: local_follower, activity: poll, type: :poll) } let!(:favourite_notification) { Fabricate(:notification, account: local_follower, activity: favourite, type: :favourite) } + let!(:emoji_reaction_notification) { Fabricate(:notification, account: local_follower, activity: emoji_reaction, type: :emoji_reaction) } let!(:follow_notification) { Fabricate(:notification, account: local_follower, activity: active_relationship, type: :follow) } + let!(:list) { Fabricate(:list, account: account) } + let!(:list_account) { Fabricate(:list_account, list: list, account: list_target_account) } + let!(:list_target_account) { Fabricate(:account) } + let!(:antenna) { Fabricate(:antenna, account: account) } + let!(:antenna_account) { Fabricate(:antenna_account, antenna: antenna, account: list_target_account) } + let!(:circle) { Fabricate(:circle, account: account) } + let!(:circle_account) { Fabricate(:circle_account, circle: circle, account: circle_target_account) } + let!(:circle_target_account) { Fabricate(:account) } + let!(:circle_status) { Fabricate(:circle_status, circle: circle, status: Fabricate(:status, account: account, visibility: :limited)) } + let!(:bookmark_category) { Fabricate(:bookmark_category, account: account) } + let!(:bookmark_category_status) { Fabricate(:bookmark_category_status, bookmark_category: bookmark_category, status: bookmark.status) } + let!(:account_note) { Fabricate(:account_note, account: account) } it 'deletes associated owned records' do @@ -34,12 +54,32 @@ account.media_attachments, account.notifications, account.favourites, + account.emoji_reactions, + account.bookmarks, account.active_relationships, account.passive_relationships, account.polls, account.account_notes, ].map(&:count) - }.from([2, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0]) + }.from([3, 1, 1, 1, 1, 1, 2, 2, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + end + + it 'deletes associated owned record groups' do + expect { subject }.to change { + [ + account.owned_lists, + account.antennas, + account.circles, + account.bookmark_categories, + ].map(&:count) + }.from([1, 1, 1, 1]).to([0, 0, 0, 0]) + expect { bookmark_category_status.status.reload }.to_not raise_error + expect { antenna_account.account.reload }.to_not raise_error + expect { circle_account.account.reload }.to_not raise_error + expect { antenna_account.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect { circle_account.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect { circle_status.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect { bookmark_category_status.reload }.to raise_error(ActiveRecord::RecordNotFound) end it 'deletes associated target records' do @@ -53,9 +93,9 @@ it 'deletes associated target notifications' do expect { subject }.to change { %w( - poll favourite status mention follow + poll favourite emoji_reaction status mention follow ).map { |type| Notification.where(type: type).count } - }.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0]) + }.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0]) end end