diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-11 23:09:41 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-11 23:09:41 +0200 |
commit | c69ca9912ed06876d96e0bb1aa7d511473867dc2 (patch) | |
tree | 35544f45f283f408d3eb1e3fd5f8fcbd235df223 /app/models | |
parent | 8f142c4aaeac73743196b1648677eb712f70c87b (diff) | |
parent | b0de6e9ae27a6364819f47d13d827a8aa253c83e (diff) | |
download | gitlab-ce-c69ca9912ed06876d96e0bb1aa7d511473867dc2.tar.gz |
Merge pull request #9371 from zenati/patch-2
An `in_namespace` scope is already present
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 3c9f0dad28b..b161cbe86b9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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_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 :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 :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) } diff --git a/app/models/user.rb b/app/models/user.rb index 596dc7ea33a..8be0b622704 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -352,9 +352,11 @@ class User < ActiveRecord::Base end def owned_projects - @owned_projects ||= begin - Project.where(namespace_id: owned_groups.pluck(:id).push(namespace.id)).joins(:namespace) - end + @owned_projects ||= + begin + namespace_ids = owned_groups.pluck(:id).push(namespace.id) + Project.in_namespace(namespace_ids).joins(:namespace) + end end # Team membership in authorized projects |