Commit 9606dbbb authored by Yorick Peterse's avatar Yorick Peterse

Whitelist existing destroy_all offenses

This whitelists all existing places where we use "destroy_all".
parent 96ce2da7
...@@ -11,7 +11,7 @@ class Projects::PagesController < Projects::ApplicationController ...@@ -11,7 +11,7 @@ class Projects::PagesController < Projects::ApplicationController
def destroy def destroy
project.remove_pages project.remove_pages
project.pages_domains.destroy_all project.pages_domains.destroy_all # rubocop: disable DestroyAll
respond_to do |format| respond_to do |format|
format.html do format.html do
......
...@@ -101,7 +101,7 @@ module Awardable ...@@ -101,7 +101,7 @@ module Awardable
end end
def remove_award_emoji(name, current_user) def remove_award_emoji(name, current_user)
award_emoji.where(name: name, user: current_user).destroy_all award_emoji.where(name: name, user: current_user).destroy_all # rubocop: disable DestroyAll
end end
def toggle_award_emoji(emoji_name, current_user) def toggle_award_emoji(emoji_name, current_user)
......
...@@ -34,7 +34,7 @@ module FastDestroyAll ...@@ -34,7 +34,7 @@ module FastDestroyAll
included do included do
before_destroy do before_destroy do
raise ForbiddenActionError, '`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`' raise ForbiddenActionError, '`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`'
end end
end end
......
...@@ -29,11 +29,13 @@ class LfsObject < ActiveRecord::Base ...@@ -29,11 +29,13 @@ class LfsObject < ActiveRecord::Base
[nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store) [nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store)
end end
# rubocop: disable DestroyAll
def self.destroy_unreferenced def self.destroy_unreferenced
joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
.where(lfs_objects_projects: { id: nil }) .where(lfs_objects_projects: { id: nil })
.destroy_all .destroy_all
end end
# rubocop: enable DestroyAll
def self.calculate_oid(path) def self.calculate_oid(path)
Digest::SHA256.file(path).hexdigest Digest::SHA256.file(path).hexdigest
......
...@@ -516,7 +516,7 @@ class User < ActiveRecord::Base ...@@ -516,7 +516,7 @@ class User < ActiveRecord::Base
otp_grace_period_started_at: nil, otp_grace_period_started_at: nil,
otp_backup_codes: nil otp_backup_codes: nil
) )
self.u2f_registrations.destroy_all self.u2f_registrations.destroy_all # rubocop: disable DestroyAll
end end
end end
......
...@@ -65,7 +65,7 @@ module Labels ...@@ -65,7 +65,7 @@ module Labels
end end
def update_project_labels(label_ids) def update_project_labels(label_ids)
Label.where(id: label_ids).destroy_all Label.where(id: label_ids).destroy_all # rubocop: disable DestroyAll
end end
def clone_label_to_group_label(label) def clone_label_to_group_label(label)
......
...@@ -73,7 +73,7 @@ module Milestones ...@@ -73,7 +73,7 @@ module Milestones
end end
def destroy_old_milestones(milestone) def destroy_old_milestones(milestone)
Milestone.where(id: milestone_ids_for_merge(milestone)).destroy_all Milestone.where(id: milestone_ids_for_merge(milestone)).destroy_all # rubocop: disable DestroyAll
end end
def group_project_ids def group_project_ids
......
...@@ -27,7 +27,7 @@ module Projects ...@@ -27,7 +27,7 @@ module Projects
end end
def remove_remaining_deploy_keys_projects def remove_remaining_deploy_keys_projects
source_project.deploy_keys_projects.destroy_all source_project.deploy_keys_projects.destroy_all # rubocop: disable DestroyAll
end end
end end
end end
...@@ -21,7 +21,7 @@ module Projects ...@@ -21,7 +21,7 @@ module Projects
end end
def remove_remaining_lfs_objects_project def remove_remaining_lfs_objects_project
source_project.lfs_objects_projects.destroy_all source_project.lfs_objects_projects.destroy_all # rubocop: disable DestroyAll
end end
def non_existent_lfs_objects_projects def non_existent_lfs_objects_projects
......
...@@ -22,7 +22,7 @@ module Projects ...@@ -22,7 +22,7 @@ module Projects
# Remove remaining notification settings from source_project # Remove remaining notification settings from source_project
def remove_remaining_notification_settings def remove_remaining_notification_settings
source_project.notification_settings.destroy_all source_project.notification_settings.destroy_all # rubocop: disable DestroyAll
end end
# Get users of current notification_settings # Get users of current notification_settings
......
...@@ -26,7 +26,7 @@ module Projects ...@@ -26,7 +26,7 @@ module Projects
# Remove remaining project group links from source_project # Remove remaining project group links from source_project
def remove_remaining_project_group_links def remove_remaining_project_group_links
source_project.reload.project_group_links.destroy_all source_project.reload.project_group_links.destroy_all # rubocop: disable DestroyAll
end end
def group_links_in_target_project def group_links_in_target_project
......
...@@ -25,7 +25,7 @@ module Projects ...@@ -25,7 +25,7 @@ module Projects
def remove_remaining_members def remove_remaining_members
# Remove remaining members and authorizations from source_project # Remove remaining members and authorizations from source_project
source_project.project_members.destroy_all source_project.project_members.destroy_all # rubocop: disable DestroyAll
end end
def project_members_in_target_project def project_members_in_target_project
......
...@@ -38,11 +38,11 @@ module ProtectedBranches ...@@ -38,11 +38,11 @@ module ProtectedBranches
def delete_redundant_access_levels def delete_redundant_access_levels
unless @developers_can_merge.nil? unless @developers_can_merge.nil?
@protected_branch.merge_access_levels.destroy_all @protected_branch.merge_access_levels.destroy_all # rubocop: disable DestroyAll
end end
unless @developers_can_push.nil? unless @developers_can_push.nil?
@protected_branch.push_access_levels.destroy_all @protected_branch.push_access_levels.destroy_all # rubocop: disable DestroyAll
end end
end end
end end
......
...@@ -5,6 +5,6 @@ class RemoveExpiredGroupLinksWorker ...@@ -5,6 +5,6 @@ class RemoveExpiredGroupLinksWorker
include CronjobQueue include CronjobQueue
def perform def perform
ProjectGroupLink.expired.destroy_all ProjectGroupLink.expired.destroy_all # rubocop: disable DestroyAll
end end
end end
...@@ -6,7 +6,9 @@ class RemoveOldWebHookLogsWorker ...@@ -6,7 +6,9 @@ class RemoveOldWebHookLogsWorker
WEB_HOOK_LOG_LIFETIME = 2.days WEB_HOOK_LOG_LIFETIME = 2.days
# rubocop: disable DestroyAll
def perform def perform
WebHookLog.destroy_all(['created_at < ?', Time.now - WEB_HOOK_LOG_LIFETIME]) WebHookLog.destroy_all(['created_at < ?', Time.now - WEB_HOOK_LOG_LIFETIME])
end end
# rubocop: enable DestroyAll
end end
...@@ -16,6 +16,6 @@ class RemoveAwardEmojisWithNoUser < ActiveRecord::Migration ...@@ -16,6 +16,6 @@ class RemoveAwardEmojisWithNoUser < ActiveRecord::Migration
# disable_ddl_transaction! # disable_ddl_transaction!
def up def up
AwardEmoji.joins('LEFT JOIN users ON users.id = user_id').where('users.id IS NULL').destroy_all AwardEmoji.joins('LEFT JOIN users ON users.id = user_id').where('users.id IS NULL').destroy_all # rubocop: disable DestroyAll
end end
end end
...@@ -45,7 +45,7 @@ module Gitlab ...@@ -45,7 +45,7 @@ module Gitlab
end end
def ensure_default_member! def ensure_default_member!
@project.project_members.destroy_all @project.project_members.destroy_all # rubocop: disable DestroyAll
ProjectMember.create!(user: @user, access_level: ProjectMember::MAINTAINER, source_id: @project.id, importing: true) ProjectMember.create!(user: @user, access_level: ProjectMember::MAINTAINER, source_id: @project.id, importing: true)
end end
......
...@@ -95,7 +95,7 @@ describe OmniauthCallbacksController, type: :controller do ...@@ -95,7 +95,7 @@ describe OmniauthCallbacksController, type: :controller do
end end
it 'allows linking the disabled provider' do it 'allows linking the disabled provider' do
user.identities.destroy_all user.identities.destroy_all # rubocop: disable DestroyAll
sign_in(user) sign_in(user)
expect { post provider }.to change { user.reload.identities.count }.by(1) expect { post provider }.to change { user.reload.identities.count }.by(1)
......
...@@ -14,7 +14,7 @@ describe Projects::ReleasesController do ...@@ -14,7 +14,7 @@ describe Projects::ReleasesController do
describe 'GET #edit' do describe 'GET #edit' do
it 'initializes a new release' do it 'initializes a new release' do
tag_id = release.tag tag_id = release.tag
project.releases.destroy_all project.releases.destroy_all # rubocop: disable DestroyAll
get :edit, namespace_id: project.namespace, project_id: project, tag_id: tag_id get :edit, namespace_id: project.namespace, project_id: project, tag_id: tag_id
......
...@@ -5,7 +5,7 @@ describe Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys, :migration ...@@ -5,7 +5,7 @@ describe Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys, :migration
let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) } let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) }
before do before do
GpgKeySubkey.destroy_all GpgKeySubkey.destroy_all # rubocop: disable DestroyAll
end end
it 'generate the subkeys' do it 'generate the subkeys' do
......
...@@ -6,7 +6,7 @@ describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do ...@@ -6,7 +6,7 @@ describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do
create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs
create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs
# Delete all subkeys so they can be recreated # Delete all subkeys so they can be recreated
GpgKeySubkey.destroy_all GpgKeySubkey.destroy_all # rubocop: disable DestroyAll
end end
it 'correctly schedules background migrations' do it 'correctly schedules background migrations' do
......
...@@ -11,7 +11,7 @@ describe ForkNetworkMember do ...@@ -11,7 +11,7 @@ describe ForkNetworkMember do
let(:fork_network) { fork_network_member.fork_network } let(:fork_network) { fork_network_member.fork_network }
it 'removes the fork network if it was the last member' do it 'removes the fork network if it was the last member' do
fork_network.fork_network_members.destroy_all fork_network.fork_network_members.destroy_all # rubocop: disable DestroyAll
expect(ForkNetwork.count).to eq(0) expect(ForkNetwork.count).to eq(0)
end end
......
...@@ -73,7 +73,7 @@ describe SystemHook do ...@@ -73,7 +73,7 @@ describe SystemHook do
it "project_destroy hook" do it "project_destroy hook" do
project.add_maintainer(user) project.add_maintainer(user)
project.project_members.destroy_all project.project_members.destroy_all # rubocop: disable DestroyAll
expect(WebMock).to have_requested(:post, system_hook.url).with( expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_remove_from_team/, body: /user_remove_from_team/,
...@@ -110,7 +110,7 @@ describe SystemHook do ...@@ -110,7 +110,7 @@ describe SystemHook do
it 'group member destroy hook' do it 'group member destroy hook' do
group.add_maintainer(user) group.add_maintainer(user)
group.group_members.destroy_all group.group_members.destroy_all # rubocop: disable DestroyAll
expect(WebMock).to have_requested(:post, system_hook.url).with( expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_remove_from_group/, body: /user_remove_from_group/,
......
...@@ -1764,7 +1764,7 @@ describe MergeRequest do ...@@ -1764,7 +1764,7 @@ describe MergeRequest do
context 'with no discussions' do context 'with no discussions' do
before do before do
merge_request.notes.destroy_all merge_request.notes.destroy_all # rubocop: disable DestroyAll
end end
it 'returns true' do it 'returns true' do
......
...@@ -41,7 +41,7 @@ describe ProjectGroupLink do ...@@ -41,7 +41,7 @@ describe ProjectGroupLink do
project.project_group_links.create(group: group) project.project_group_links.create(group: group)
group_users.each { |user| expect(user.authorized_projects).to include(project) } group_users.each { |user| expect(user.authorized_projects).to include(project) }
project.project_group_links.destroy_all project.project_group_links.destroy_all # rubocop: disable DestroyAll
group_users.each { |user| expect(user.authorized_projects).not_to include(project) } group_users.each { |user| expect(user.authorized_projects).not_to include(project) }
end end
end end
......
...@@ -205,7 +205,7 @@ describe GroupPolicy do ...@@ -205,7 +205,7 @@ describe GroupPolicy do
nested_group.add_guest(developer) nested_group.add_guest(developer)
nested_group.add_guest(maintainer) nested_group.add_guest(maintainer)
group.owners.destroy_all group.owners.destroy_all # rubocop: disable DestroyAll
group.add_guest(owner) group.add_guest(owner)
nested_group.add_owner(owner) nested_group.add_owner(owner)
......
...@@ -9,13 +9,13 @@ describe RuboCop::Cop::DestroyAll do ...@@ -9,13 +9,13 @@ describe RuboCop::Cop::DestroyAll do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
it 'flags the use of destroy_all with a send receiver' do it 'flags the use of destroy_all with a send receiver' do
inspect_source('foo.destroy_all') inspect_source('foo.destroy_all # rubocop: disable DestroyAll')
expect(cop.offenses.size).to eq(1) expect(cop.offenses.size).to eq(1)
end end
it 'flags the use of destroy_all with a constant receiver' do it 'flags the use of destroy_all with a constant receiver' do
inspect_source('User.destroy_all') inspect_source('User.destroy_all # rubocop: disable DestroyAll')
expect(cop.offenses.size).to eq(1) expect(cop.offenses.size).to eq(1)
end end
...@@ -29,7 +29,7 @@ describe RuboCop::Cop::DestroyAll do ...@@ -29,7 +29,7 @@ describe RuboCop::Cop::DestroyAll do
it 'flags the use of destroy_all with a local variable receiver' do it 'flags the use of destroy_all with a local variable receiver' do
inspect_source(<<~RUBY) inspect_source(<<~RUBY)
users = User.all users = User.all
users.destroy_all users.destroy_all # rubocop: disable DestroyAll
RUBY RUBY
expect(cop.offenses.size).to eq(1) expect(cop.offenses.size).to eq(1)
......
...@@ -134,9 +134,11 @@ describe MergeRequests::CreateService do ...@@ -134,9 +134,11 @@ describe MergeRequests::CreateService do
let!(:pipeline_3) { create(:ci_pipeline, project: project, ref: "other_branch", project_id: project.id) } let!(:pipeline_3) { create(:ci_pipeline, project: project, ref: "other_branch", project_id: project.id) }
before do before do
# rubocop: disable DestroyAll
project.merge_requests project.merge_requests
.where(source_branch: opts[:source_branch], target_branch: opts[:target_branch]) .where(source_branch: opts[:source_branch], target_branch: opts[:target_branch])
.destroy_all .destroy_all
# rubocop: enable DestroyAll
end end
it 'sets head pipeline' do it 'sets head pipeline' do
......
...@@ -46,10 +46,12 @@ describe MergeRequests::DeleteNonLatestDiffsService, :clean_gitlab_redis_shared_ ...@@ -46,10 +46,12 @@ describe MergeRequests::DeleteNonLatestDiffsService, :clean_gitlab_redis_shared_
end end
it 'schedules no removal if there is no non-latest diffs' do it 'schedules no removal if there is no non-latest diffs' do
# rubocop: disable DestroyAll
merge_request merge_request
.merge_request_diffs .merge_request_diffs
.where.not(id: merge_request.latest_merge_request_diff_id) .where.not(id: merge_request.latest_merge_request_diff_id)
.destroy_all .destroy_all
# rubocop: enable DestroyAll
expect(DeleteDiffFilesWorker).not_to receive(:bulk_perform_in) expect(DeleteDiffFilesWorker).not_to receive(:bulk_perform_in)
......
...@@ -280,7 +280,7 @@ describe TodoService do ...@@ -280,7 +280,7 @@ describe TodoService do
end end
it 'does not create a todo if unassigned' do it 'does not create a todo if unassigned' do
issue.assignees.destroy_all issue.assignees.destroy_all # rubocop: disable DestroyAll
should_not_create_any_todo { service.reassigned_issue(issue, author) } should_not_create_any_todo { service.reassigned_issue(issue, author) }
end end
......
...@@ -4,8 +4,8 @@ shared_examples_for 'fast destroyable' do ...@@ -4,8 +4,8 @@ shared_examples_for 'fast destroyable' do
expect(external_data_counter).to be > 0 expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0 expect(subjects.count).to be > 0
expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`') expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`')
expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`') expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') # rubocop: disable DestroyAll
expect(subjects.count).to be > 0 expect(subjects.count).to be > 0
expect(external_data_counter).to be > 0 expect(external_data_counter).to be > 0
......
...@@ -6,7 +6,7 @@ describe RepositoryCheck::SingleRepositoryWorker do ...@@ -6,7 +6,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
it 'skips when the project has no push events' do it 'skips when the project has no push events' do
project = create(:project, :repository, :wiki_disabled) project = create(:project, :repository, :wiki_disabled)
project.events.destroy_all project.events.destroy_all # rubocop: disable DestroyAll
break_project(project) break_project(project)
expect(worker).not_to receive(:git_fsck) expect(worker).not_to receive(:git_fsck)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment