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

Fix current feature related specs

parent 8e8eb978
......@@ -78,11 +78,14 @@ def project?
end
def project
return nil if @project&.pending_delete?
return @project if defined?(@project)
if project?
@project = Project.find(params[:project_id])
@project = nil if @project.pending_delete?
unless Ability.allowed?(current_user, :read_project, @project)
@project = nil
end
......@@ -95,7 +98,7 @@ def project
def projects(items)
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
def type?
......
......@@ -19,7 +19,7 @@ class NotificationSetting < ActiveRecord::Base
# pending delete).
#
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
EMAIL_EVENTS = [
......
......@@ -1456,7 +1456,7 @@ def check_pending_delete
def pending_delete_twin
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
##
......
......@@ -54,9 +54,9 @@ def execute
def builds_for_shared_runner
new_builds.
# don't run projects which have not enabled shared runners and builds
joins(:project).where(projects: { shared_runners_enabled: true })
.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').
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').
where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
# Implement fair scheduling
# this returns builds that are ordered by number of running builds
......@@ -66,7 +66,7 @@ def builds_for_shared_runner
end
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
def running_builds_for_shared_runners
......
......@@ -10,7 +10,7 @@ def async_execute
def execute
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.
# Skip repository removal because we remove directory with namespace
# that contain all these repositories
......
......@@ -35,7 +35,7 @@ def execute(user, options = {})
Groups::DestroyService.new(group, current_user).execute
end
user.personal_projects.with_deleted.each do |project|
user.personal_projects.each do |project|
# Skip repository removal because we remove directory with namespace
# that contain all this repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
......
......@@ -45,7 +45,7 @@ def drop_stuck(status, timeout)
def search(status, timeout)
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)
end
end
......
---
title: Removes deleted_at and pending_delete occurrences in Project related queries
merge_request: 12091
author:
......@@ -46,7 +46,8 @@ def validate_job!(job)
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?
end
......
......@@ -28,7 +28,8 @@ def validate_build!(build)
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?
end
......
......@@ -284,15 +284,6 @@
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
it 'sets an random token if none provided' do
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