diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2019-06-03 14:56:33 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-06-03 14:56:33 +0200 |
commit | 6cb750a2bb7e1720413a7c42ec4afebaa3f2f4d2 (patch) | |
tree | 2f94f96a1fcb0c692f8e94e924a733d4bad9a59b /app/models/project.rb | |
parent | 51a66a581f4d0662d04c432aa4b014dd4b634fc9 (diff) | |
parent | 3dcf3cfde35d1506c7196634080849d002251a41 (diff) | |
download | gitlab-ce-6cb750a2bb7e1720413a7c42ec4afebaa3f2f4d2.tar.gz |
Merge dev.gitlab.org master into GitLab.com master
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 20895923d3b..78d54571d94 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -407,6 +407,7 @@ class Project < ApplicationRecord scope :with_builds_enabled, -> { with_feature_enabled(:builds) } scope :with_issues_enabled, -> { with_feature_enabled(:issues) } scope :with_issues_available_for_user, ->(current_user) { with_feature_available_for_user(:issues, current_user) } + scope :with_merge_requests_available_for_user, ->(current_user) { with_feature_available_for_user(:merge_requests, current_user) } scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) } scope :with_remote_mirrors, -> { joins(:remote_mirrors).where(remote_mirrors: { enabled: true }).distinct } @@ -597,6 +598,17 @@ class Project < ApplicationRecord def group_ids joins(:namespace).where(namespaces: { type: 'Group' }).select(:namespace_id) end + + # Returns ids of projects with milestones available for given user + # + # Used on queries to find milestones which user can see + # For example: Milestone.where(project_id: ids_with_milestone_available_for(user)) + def ids_with_milestone_available_for(user) + with_issues_enabled = with_issues_available_for_user(user).select(:id) + with_merge_requests_enabled = with_merge_requests_available_for_user(user).select(:id) + + from_union([with_issues_enabled, with_merge_requests_enabled]).select(:id) + end end def all_pipelines |