diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2019-02-21 14:12:11 +0100 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2019-02-21 14:12:11 +0100 |
commit | 56a54c62fba093ae53c8fef309454f38d3778b0f (patch) | |
tree | b322cf001890414daca65528ff1c12ec1a735f4d | |
parent | 73e3a1cd02c5d2bdaf03d5998ae12bc86de2fa75 (diff) | |
download | gitlab-ce-56a54c62fba093ae53c8fef309454f38d3778b0f.tar.gz |
Add confidential_only scop to issue model
-rw-r--r-- | app/finders/issues_finder.rb | 12 | ||||
-rw-r--r-- | app/models/issue.rb | 1 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 9 |
3 files changed, 13 insertions, 9 deletions
diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index d0a094ea4a6..a34cdf29c80 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -73,17 +73,11 @@ class IssuesFinder < IssuableFinder by_confidential(issues) end - # rubocop: disable CodeReuse/ActiveRecord def by_confidential(items) - if params[:confidential] == 'yes' - items.where('issues.confidential = TRUE') - elsif params[:confidential] == 'no' - items.where.not('issues.confidential = TRUE') - else - items - end + return items unless params[:confidential].present? + + params[:confidential] == 'yes' ? items.confidential_only : items.public_only end - # rubocop: enable CodeReuse/ActiveRecord def by_due_date(items) if due_date? diff --git a/app/models/issue.rb b/app/models/issue.rb index 182c5d3d4b0..0b46e949052 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -66,6 +66,7 @@ class Issue < ActiveRecord::Base scope :preload_associations, -> { preload(:labels, project: :namespace) } scope :public_only, -> { where(confidential: false) } + scope :confidential_only, -> { where(confidential: true) } after_save :expire_etag_cache after_save :ensure_metrics, unless: :imported? diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 5d18e085a6f..6101df2e099 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -765,6 +765,15 @@ describe Issue do end end + describe '.confidential_only' do + it 'only returns confidential_only issues' do + create(:issue) + confidential_issue = create(:issue, confidential: true) + + expect(described_class.confidential_only).to eq([confidential_issue]) + end + end + it_behaves_like 'throttled touch' do subject { create(:issue, updated_at: 1.hour.ago) } end |