Skip to content
Snippets Groups Projects
Commit aef8be3b authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg
Browse files

Use explicit scope to exclude projects pending deletion

parent 624dc104
No related branches found
No related tags found
No related merge requests found
Showing
with 22 additions and 23 deletions
Loading
Loading
@@ -46,6 +46,7 @@ v 8.8.0 (unreleased)
 
v 8.7.5
- Fix relative links in wiki pages. !4050
- Excluding projects pending deletion is now down using explicit scoping
 
v 8.7.4
- Links for Redmine issue references are generated correctly again !4048 (Benedikt Huss)
Loading
Loading
class Admin::DashboardController < Admin::ApplicationController
def index
@projects = Project.limit(10)
@projects = Project.without_pending_delete.limit(10)
@users = User.limit(10)
@groups = Group.limit(10)
end
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@ class Admin::ProjectsController < Admin::ApplicationController
before_action :group, only: [:show, :transfer]
 
def index
@projects = Project.all
@projects = Project.without_pending_delete
@projects = @projects.in_namespace(params[:namespace_id]) if params[:namespace_id].present?
@projects = @projects.where("projects.visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present?
@projects = @projects.with_push if params[:with_push].present?
Loading
Loading
Loading
Loading
@@ -12,9 +12,9 @@ class Admin::RunnersController < Admin::ApplicationController
@builds = @runner.builds.order('id DESC').first(30)
@projects =
if params[:search].present?
::Project.search(params[:search])
::Project.without_pending_delete.search(params[:search])
else
Project.all
Project.without_pending_delete
end
@projects = @projects.where.not(id: @runner.projects.select(:id)) if @runner.projects.any?
@projects = @projects.page(params[:page]).per(30)
Loading
Loading
Loading
Loading
@@ -4,6 +4,6 @@ class Dashboard::ApplicationController < ApplicationController
private
 
def projects
@projects ||= current_user.authorized_projects.sorted_by_activity.non_archived
@projects ||= ProjectsFinder.new.execute(current_user).sorted_by_activity.non_archived
end
end
Loading
Loading
@@ -4,7 +4,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
before_action :event_filter
 
def index
@projects = current_user.authorized_projects.sorted_by_activity
@projects = current_user.authorized_projects.without_pending_delete.sorted_by_activity
@projects = filter_projects(@projects)
@projects = @projects.includes(:namespace)
@projects = @projects.sort(@sort = params[:sort])
Loading
Loading
@@ -28,7 +28,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
 
def starred
@projects = current_user.viewable_starred_projects.sorted_by_activity
@projects = current_user.viewable_starred_projects.without_pending_delete.sorted_by_activity
@projects = filter_projects(@projects)
@projects = @projects.includes(:namespace, :forked_from_project, :tags)
@projects = @projects.sort(@sort = params[:sort])
Loading
Loading
Loading
Loading
@@ -21,8 +21,8 @@ class PersonalProjectsFinder < UnionFinder
def all_projects(current_user)
projects = []
 
projects << @user.personal_projects.visible_to_user(current_user) if current_user
projects << @user.personal_projects.public_to_user(current_user)
projects << @user.personal_projects.without_pending_delete.visible_to_user(current_user) if current_user
projects << @user.personal_projects.without_pending_delete.public_to_user(current_user)
 
projects
end
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ class ProjectsFinder < UnionFinder
projects = []
 
projects << current_user.authorized_projects if current_user
projects << Project.unscoped.public_to_user(current_user)
projects << Project.without_pending_delete.public_to_user(current_user)
 
projects
end
Loading
Loading
Loading
Loading
@@ -163,9 +163,6 @@ class Project < ActiveRecord::Base
 
mount_uploader :avatar, AvatarUploader
 
# Scopes
default_scope { where(pending_delete: false) }
scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) }
scope :sorted_by_stars, -> { reorder('projects.star_count DESC') }
scope :sorted_by_names, -> { joins(:namespace).reorder('namespaces.name ASC, projects.name ASC') }
Loading
Loading
@@ -179,6 +176,7 @@ class Project < ActiveRecord::Base
scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) }
scope :non_archived, -> { where(archived: false) }
scope :for_milestones, ->(ids) { joins(:milestones).where('milestones.id' => ids).distinct }
scope :without_pending_delete, -> { where(pending_delete: false) }
 
state_machine :import_status, initial: :none do
event :import_start do
Loading
Loading
Loading
Loading
@@ -91,7 +91,7 @@ class SystemHooksService
end
 
def project_member_data(model)
project = model.project || Project.unscoped.find(model.source_id)
project = model.project || Project.find(model.source_id)
 
{
project_name: project.name,
Loading
Loading
Loading
Loading
@@ -104,7 +104,7 @@
%h4 Projects
.data
= link_to admin_namespaces_projects_path do
%h1= number_with_delimiter(Project.count)
%h1= number_with_delimiter(Project.without_pending_delete.count)
%hr
= link_to('New Project', new_project_path, class: "btn btn-new")
.col-sm-4
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ class ProjectDestroyWorker
 
def perform(project_id, user_id, params)
begin
project = Project.unscoped.find(project_id)
project = Project.find(project_id)
rescue ActiveRecord::RecordNotFound
return
end
Loading
Loading
Loading
Loading
@@ -56,7 +56,7 @@ module API
# GET /projects/all
get '/all' do
authenticated_as_admin!
@projects = Project.all
@projects = Project.without_pending_delete
@projects = filter_projects(@projects)
@projects = paginate @projects
present @projects, with: Entities::ProjectWithAccess, user: current_user
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@ module Gitlab
 
def initialize(current_user, limit_projects, query)
@current_user = current_user
@limit_projects = limit_projects || Project.all
@limit_projects = limit_projects || Project.without_pending_delete
@query = Shellwords.shellescape(query) if query.present?
end
 
Loading
Loading
Loading
Loading
@@ -64,12 +64,12 @@ describe Project, models: true do
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)
describe 'without_pending_delete scope' do
it 'excludes projects pending deletion' do
create(:project)
create(:project, pending_delete: true)
 
expect(Project.all).to eq [project]
expect(Project.without_pending_delete.count).to be 1
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment