Commit b0de6e9a authored by zenati's avatar zenati

An `in_namespace` scope is already present

parent 9562f028
...@@ -5,7 +5,7 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -5,7 +5,7 @@ class Admin::ProjectsController < Admin::ApplicationController
def index def index
@projects = Project.all @projects = Project.all
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present? @projects = @projects.in_namespace(params[:namespace_id]) if params[:namespace_id].present?
@projects = @projects.where("visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present? @projects = @projects.where("visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present?
@projects = @projects.with_push if params[:with_push].present? @projects = @projects.with_push if params[:with_push].present?
@projects = @projects.abandoned if params[:abandoned].present? @projects = @projects.abandoned if params[:abandoned].present?
......
...@@ -158,7 +158,7 @@ class Project < ActiveRecord::Base ...@@ -158,7 +158,7 @@ class Project < ActiveRecord::Base
scope :without_user, ->(user) { where('projects.id NOT IN (:ids)', ids: user.authorized_projects.map(&:id) ) } scope :without_user, ->(user) { where('projects.id NOT IN (:ids)', ids: user.authorized_projects.map(&:id) ) }
scope :without_team, ->(team) { team.projects.present? ? where('projects.id NOT IN (:ids)', ids: team.projects.map(&:id)) : scoped } scope :without_team, ->(team) { team.projects.present? ? where('projects.id NOT IN (:ids)', ids: team.projects.map(&:id)) : scoped }
scope :not_in_group, ->(group) { where('projects.id NOT IN (:ids)', ids: group.project_ids ) } scope :not_in_group, ->(group) { where('projects.id NOT IN (:ids)', ids: group.project_ids ) }
scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) }
scope :in_group_namespace, -> { joins(:group) } scope :in_group_namespace, -> { joins(:group) }
scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) } scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) }
......
...@@ -352,8 +352,10 @@ class User < ActiveRecord::Base ...@@ -352,8 +352,10 @@ class User < ActiveRecord::Base
end end
def owned_projects def owned_projects
@owned_projects ||= begin @owned_projects ||=
Project.where(namespace_id: owned_groups.pluck(:id).push(namespace.id)).joins(:namespace) begin
namespace_ids = owned_groups.pluck(:id).push(namespace.id)
Project.in_namespace(namespace_ids).joins(:namespace)
end end
end end
......
...@@ -9,7 +9,7 @@ module Search ...@@ -9,7 +9,7 @@ module Search
def execute def execute
group = Group.find_by(id: params[:group_id]) if params[:group_id].present? group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
projects = ProjectsFinder.new.execute(current_user) projects = ProjectsFinder.new.execute(current_user)
projects = projects.where(namespace_id: group.id) if group projects = projects.in_namespace(group.id) if group
project_ids = projects.pluck(:id) project_ids = projects.pluck(:id)
Gitlab::SearchResults.new(project_ids, params[:search]) Gitlab::SearchResults.new(project_ids, params[:search])
......
...@@ -51,7 +51,7 @@ namespace :gitlab do ...@@ -51,7 +51,7 @@ namespace :gitlab do
git_base_path = Gitlab.config.gitlab_shell.repos_path git_base_path = Gitlab.config.gitlab_shell.repos_path
all_dirs = Dir.glob(git_base_path + '/*') all_dirs = Dir.glob(git_base_path + '/*')
global_projects = Project.where(namespace_id: nil).pluck(:path) global_projects = Project.in_namespace(nil).pluck(:path)
puts git_base_path.yellow puts git_base_path.yellow
puts "Looking for global repos to remove... " puts "Looking for global repos to remove... "
......
...@@ -51,11 +51,11 @@ namespace :gitlab do ...@@ -51,11 +51,11 @@ namespace :gitlab do
if namespace_path.blank? if namespace_path.blank?
Project Project
elsif namespace_path == '/' elsif namespace_path == '/'
Project.where(namespace_id: nil) Project.in_namespace(nil)
else else
namespace = Namespace.where(path: namespace_path).first namespace = Namespace.where(path: namespace_path).first
if namespace if namespace
Project.where(namespace_id: namespace.id) Project.in_namespace(namespace.id)
else else
puts "Namespace not found: #{namespace_path}".red puts "Namespace not found: #{namespace_path}".red
exit 2 exit 2
......
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