Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-05-23 23:40:07 +0300
committerToon Claes <toon@gitlab.com>2017-05-30 23:45:59 +0300
commit8e72ad70bd2479ae5a465eac1df74f99f03ea731 (patch)
treec282901f94ffddc335496481eb278e70749f93bc /app
parent07fc79e7c53a4fa7c4dd33835b905dfa8a609ff8 (diff)
Add starred_by scope to Project
Add a scope to search for the projects that are starred by a certain user.
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb3
-rw-r--r--app/models/user.rb2
2 files changed, 3 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index a59095cb25c..963fd594d46 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -242,6 +242,7 @@ class Project < ActiveRecord::Base
scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) }
scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) }
+ scope :starred_by, ->(user) { joins(:users_star_projects).where('users_star_projects.user_id': user.id) }
scope :visible_to_user, ->(user) { where(id: user.authorized_projects.select(:id).reorder(nil)) }
scope :non_archived, -> { where(archived: false) }
scope :for_milestones, ->(ids) { joins(:milestones).where('milestones.id' => ids).distinct }
@@ -350,7 +351,7 @@ class Project < ActiveRecord::Base
where("projects.id IN (#{union.to_sql})")
end
- def search_by_visibility(level)
+ def search_by_visibility(level) # DEPRECATED: remove with API V3
where(visibility_level: Gitlab::VisibilityLevel.string_options[level])
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 3f816a250c2..20894ce269a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -557,7 +557,7 @@ class User < ActiveRecord::Base
authorized_projects(Gitlab::Access::REPORTER).where(id: projects)
end
- def viewable_starred_projects
+ def viewable_starred_projects # DEPRECATED: Use ProjectFinder instead. Remove together with API V3
starred_projects.where("projects.visibility_level IN (?) OR projects.id IN (?)",
[Project::PUBLIC, Project::INTERNAL],
authorized_projects.select(:project_id))