Commit 34f57b46 authored by Tiago Botelho's avatar Tiago Botelho

Fix current feature related specs

parent 8e8eb978
...@@ -78,11 +78,14 @@ class TodosFinder ...@@ -78,11 +78,14 @@ class TodosFinder
end end
def project def project
return nil if @project&.pending_delete?
return @project if defined?(@project) return @project if defined?(@project)
if project? if project?
@project = Project.find(params[:project_id]) @project = Project.find(params[:project_id])
@project = nil if @project.pending_delete?
unless Ability.allowed?(current_user, :read_project, @project) unless Ability.allowed?(current_user, :read_project, @project)
@project = nil @project = nil
end end
...@@ -95,7 +98,7 @@ class TodosFinder ...@@ -95,7 +98,7 @@ class TodosFinder
def projects(items) def projects(items)
item_project_ids = items.reorder(nil).select(:project_id) item_project_ids = items.reorder(nil).select(:project_id)
ProjectsFinder.new(current_user: current_user, project_ids_relation: item_project_ids).execute ProjectsFinder.new(current_user: current_user, project_ids_relation: item_project_ids).execute.without_deleted
end end
def type? def type?
......
...@@ -19,7 +19,7 @@ class NotificationSetting < ActiveRecord::Base ...@@ -19,7 +19,7 @@ class NotificationSetting < ActiveRecord::Base
# pending delete). # pending delete).
# #
scope :for_projects, -> do scope :for_projects, -> do
includes(:project).references(:projects).where(source_type: 'Project').where.not(projects: { id: nil }) includes(:project).references(:projects).where(source_type: 'Project').where.not(projects: { id: nil, pending_delete: true })
end end
EMAIL_EVENTS = [ EMAIL_EVENTS = [
......
...@@ -1456,7 +1456,7 @@ class Project < ActiveRecord::Base ...@@ -1456,7 +1456,7 @@ class Project < ActiveRecord::Base
def pending_delete_twin def pending_delete_twin
return false unless path return false unless path
Project.unscoped.where(pending_delete: true).find_by_full_path(path_with_namespace) Project.with_deleted.find_by_full_path(path_with_namespace)
end end
## ##
......
...@@ -54,9 +54,9 @@ module Ci ...@@ -54,9 +54,9 @@ module Ci
def builds_for_shared_runner def builds_for_shared_runner
new_builds. new_builds.
# don't run projects which have not enabled shared runners and builds # don't run projects which have not enabled shared runners and builds
joins(:project).where(projects: { shared_runners_enabled: true }) joins(:project).where(projects: { shared_runners_enabled: true, pending_delete: false }).
.joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id') joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id').
.where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0'). where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
# Implement fair scheduling # Implement fair scheduling
# this returns builds that are ordered by number of running builds # this returns builds that are ordered by number of running builds
...@@ -66,7 +66,7 @@ module Ci ...@@ -66,7 +66,7 @@ module Ci
end end
def builds_for_specific_runner def builds_for_specific_runner
new_builds.where(project: runner.projects.with_builds_enabled).order('created_at ASC') new_builds.where(project: runner.projects.without_deleted.with_builds_enabled).order('created_at ASC')
end end
def running_builds_for_shared_runners def running_builds_for_shared_runners
......
...@@ -10,7 +10,7 @@ module Groups ...@@ -10,7 +10,7 @@ module Groups
def execute def execute
group.prepare_for_destroy group.prepare_for_destroy
group.projects.with_deleted.each do |project| group.projects.each do |project|
# Execute the destruction of the models immediately to ensure atomic cleanup. # Execute the destruction of the models immediately to ensure atomic cleanup.
# Skip repository removal because we remove directory with namespace # Skip repository removal because we remove directory with namespace
# that contain all these repositories # that contain all these repositories
......
...@@ -35,7 +35,7 @@ module Users ...@@ -35,7 +35,7 @@ module Users
Groups::DestroyService.new(group, current_user).execute Groups::DestroyService.new(group, current_user).execute
end end
user.personal_projects.with_deleted.each do |project| user.personal_projects.each do |project|
# Skip repository removal because we remove directory with namespace # Skip repository removal because we remove directory with namespace
# that contain all this repositories # that contain all this repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
......
...@@ -45,7 +45,7 @@ class StuckCiJobsWorker ...@@ -45,7 +45,7 @@ class StuckCiJobsWorker
def search(status, timeout) def search(status, timeout)
builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago) builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago)
builds.joins(:project).includes(:tags, :runner, project: :namespace).find_each(batch_size: 50).each do |build| builds.joins(:project).merge(Project.without_deleted).includes(:tags, :runner, project: :namespace).find_each(batch_size: 50).each do |build|
yield(build) yield(build)
end end
end end
......
---
title: Removes deleted_at and pending_delete occurrences in Project related queries
merge_request: 12091
author:
...@@ -46,7 +46,8 @@ module API ...@@ -46,7 +46,8 @@ module API
yield if block_given? yield if block_given?
forbidden!('Project has been deleted!') unless job.project project = job.project
forbidden!('Project has been deleted!') if project.nil? || project.pending_delete?
forbidden!('Job has been erased!') if job.erased? forbidden!('Job has been erased!') if job.erased?
end end
......
...@@ -28,7 +28,8 @@ module Ci ...@@ -28,7 +28,8 @@ module Ci
yield if block_given? yield if block_given?
forbidden!('Project has been deleted!') unless build.project project = build.project
forbidden!('Project has been deleted!') if project.nil? || project.pending_delete?
forbidden!('Build has been erased!') if build.erased? forbidden!('Build has been erased!') if build.erased?
end end
......
...@@ -284,15 +284,6 @@ describe Project, models: true do ...@@ -284,15 +284,6 @@ describe Project, models: true do
end end
end end
describe 'default_scope' do
it 'excludes projects pending deletion from the results' do
project = create(:empty_project)
create(:empty_project, pending_delete: true)
expect(Project.all).to eq [project]
end
end
describe 'project token' do describe 'project token' do
it 'sets an random token if none provided' do it 'sets an random token if none provided' do
project = FactoryGirl.create :empty_project, runners_token: '' project = FactoryGirl.create :empty_project, runners_token: ''
......
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